Red Hat Training
A Red Hat training course is available for RHEL 8
42.2.2. nginx Web サーバーでの PHP の使用
本セクションでは、nginx
Web サーバーで PHP コードを実行する方法を説明します。
前提条件
PHP スクリプト言語がシステムにインストールされている。
PHP スクリプト言語のインストール を参照してください。
手順
nginx
モジュールストリームをインストールします。# yum module install nginx:stream
stream は、インストールする
nginx
のバージョンに置き換えます。たとえば、
nginx
バージョン 1.18 をインストールするには、以下を実行します。# yum module install nginx:1.18
nginx
サーバーを起動します。# systemctl start nginx
または、使用中のシステムで
nginx
サーバーを実行している場合は、PHP のインストール後にnginx
サービスを再起動します。# systemctl restart nginx
php-fpm
サービスを起動します。# systemctl start php-fpm
必要に応じて、両方のサービスが起動時に開始できるようにします。
# systemctl enable php-fpm nginx
PHP の設定に関する情報を取得するには、以下の内容を含む
index.php
ファイルを/usr/share/nginx/html/
ディレクトリーに作成します。echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php
index.php
ファイルを実行するには、ブラウザーで以下を指定します。http://<hostname>/
オプション: 特定の要件がある場合は、設定を調整します。
-
/etc/nginx/nginx.conf
-nginx
main configuration -
/etc/nginx/conf.d/php-fpm.conf
-nginx
の FPM 設定 -
/etc/php-fpm.conf
- FPM の主要設定 -
/etc/php-fpm.d/www.conf
- デフォルトのwww
プール設定
-
例42.2 Hello, World の実行 nginx サーバーを使用した PHP スクリプト
プロジェクトの
hello
ディレクトリーを/usr/share/nginx/html/
ディレクトリーに作成します。# mkdir hello
以下の内容で
/usr/share/nginx/html/hello/
ディレクトリーにhello.php
ファイルを作成します。# <!DOCTYPE html> <html> <head> <title>Hello, World! Page</title> </head> <body> <?php echo 'Hello, World!'; ?> </body> </html>
nginx
サーバーを起動します。# systemctl start nginx
hello.php
ファイルを実行するには、ブラウザーに以下を指定します。http://<hostname>/hello/hello.php
これにより、Hello, World! テキストの Web ページが表示されます。
関連情報