2台目のサーバー設定をする(webサーバー1)
2台目としてサーバー構成図のwebサーバー1の設定をします。
PHPアプリケーションを動かすwebサーバーで、
今回はapacheではなくNginx上でPHPが動くようにしたいと思います。
なので、Nginxのインストールまでは1台目と同じ手順です。
ちなみにwebサーバー1のユーザー名はweb1という名前で追加しました。
Nginxのインストールまで終われば、次にNginx上でPHPを動かすために必要なPHP-FPMをインストールします。
あればインストール
インストールできたか確認
php-fpm -v
PHP5.4が入ってました。
PHP-FPMの設定ファイルにはデフォルトがapacheの設定になっているのでuserとgroupの「apache」を「nginx」に書き換えます。
次に、nginxの設定ファイル中の、ドキュメントルートの設定とPHPを実行できるように書き換えます。
※デフォルトの設定ファイルはコピーして残します。
sudo cp default.conf default.conf.org
location / {
- root /usr/share/nginx/html;
+ root /var/www;
- index index.html index.htm;
+ index index.php;
}
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
+ location ~ \.php$ {
+ root /var/www;
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
+ include fastcgi_params;
+ }
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl status php-fpm
・Nginxも設定ファイルを修正したので再起動
sudo systemctl restart nginx.service
・設定したドキュメントルートにindex.phpを作る。
ブラウザから「http://webサーバー1のIPアドレス」にアクセスして、
この画像が表示されれば、PHP-FPMの設定は成功です。