12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【XServerVPS】LAMP環境のセットアップ手順

Posted at

1. 環境

項目 バージョン
OS Windows 11
ターミナル TeraTerm 5.5.0
サーバOS CentOS 9
Apache 2.4.62
MySQL 8.0.43
PHP 8.2
Laravel 12.32.5

2. クライアント側の準備

■ XServer VPS を作成

  • CentOS 9 を選択

  • パケットフィルターで以下を許可

    • SSH(22)
    • HTTP / HTTPS(80 / 443)

■ TeraTerm をインストール

  • SSH 接続用ツールとして使用

■ GitHub からプロジェクトを準備

  • デプロイ対象の Laravel プロジェクトを GitHub に置いておく

3. サーバ側の設定(TeraTerm から SSH 接続して実施)

■ Apache のインストール

sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd

ファイアウォール設定:

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload

■ PHP 8.2 のインストール

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
sudo dnf install dnf-plugins-core -y
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y
sudo dnf install php php-cli php-mbstring php-xml php-pdo php-mysqlnd php-bcmath php-tokenizer php-curl php-json php-zip -y

■ Laravel プロジェクトをクローン

cd /var/www
sudo git clone https://github.com/ユーザー名/リポジトリ名.git
sudo chown -R apache:apache /var/www/リポジトリ名

■ Composer のセットアップ

composer install
cp .env.example .env
php artisan key:generate

.env の DB 設定を修正

■ 権限設定

sudo chown -R apache:apache /var/www/リポジトリ名
sudo chmod -R 775 /var/www/リポジトリ名/storage /var/www/リポジトリ名/bootstrap/cache

■ Apache VirtualHost 設定

sudo vi /etc/httpd/conf.d/laravel.conf

設定例:

<VirtualHost *:80>
    DocumentRoot /var/www/リポジトリ名/public
    <Directory /var/www/リポジトリ名/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

反映:

sudo systemctl restart httpd

■ MySQL のセットアップ

mysql -u root -p
CREATE DATABASE データベース名 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Laravel マイグレーション:

php artisan migrate

4. 動作確認

ブラウザで以下を開く

http://サーバのIP/

Laravel のトップページが表示されれば成功。


参考リンク

12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?