4.2. Using the PHP scripting language with a web server
4.2.1. Using PHP with the Apache HTTP Server 링크 복사링크가 클립보드에 복사되었습니다!
In Red Hat Enterprise Linux 10, the Apache HTTP Server allows you to run PHP as a FastCGI process server. FastCGI Process Manager (FPM) is an alternative PHP FastCGI daemon that allows a website to manage high loads. PHP uses FastCGI Process Manager by default in RHEL 10.
Prerequisites
- The PHP scripting language is installed on your system.
Procedure
Configure the
Apache HTTP Serverandphp-fpmto run PHP scripts.Install the
httpdpackage:# dnf install httpdStart the
Apache HTTP Server:# systemctl start httpdOr, if the
Apache HTTP Serveris already running on your system, restart thehttpdservice after installing PHP:# systemctl restart httpdStart the
php-fpmservice:# systemctl start php-fpmOptional: Enable both services to start at boot time:
# systemctl enable php-fpm httpdTo obtain information about your PHP settings, create the
index.phpfile with the following content in the/var/www/html/directory:# echo '<?php phpinfo(); ?>' > /var/www/html/index.phpTo run the
index.phpfile, point the browser to:http://<hostname>/Optional: Adjust configuration if you have specific requirements:
-
/etc/httpd/conf/httpd.conf- generichttpdconfiguration -
/etc/httpd/conf.d/php.conf- PHP-specific configuration forhttpd -
/usr/lib/systemd/system/httpd.service.d/php-fpm.conf- by default, thephp-fpmservice is started withhttpd -
/etc/php-fpm.conf- FPM main configuration -
/etc/php-fpm.d/www.conf- defaultwwwpool configuration
-
Run the "Hello, World!" PHP script using the Apache HTTP Server.
Create a
hellodirectory for your project in the/var/www/html/directory:# mkdir helloCreate a
hello.phpfile in the/var/www/html/hello/directory with the following content:# <!DOCTYPE html> <html> <head> <title>Hello, World! Page</title> </head> <body> <?php echo 'Hello, World!'; ?> </body> </html>Start the
Apache HTTP Server:# systemctl start httpdTo run the
hello.phpfile, point the browser to:http://<hostname>/hello/hello.phpAs a result, a web page with the "Hello, World!" text is displayed.
See
httpd(8),httpd.conf(5), andphp-fpm(8)man pages for more information.
4.2.2. Using PHP with the nginx web server 링크 복사링크가 클립보드에 복사되었습니다!
You can run PHP code through the nginx web server.
Prerequisites
- The PHP scripting language is installed on your system.
Procedure
Configure the
nginxweb server andphp-fpmto run PHP scripts.Install the
nginxpackage:# dnf install nginxStart the
nginxserver:# systemctl start nginxOr, if the
nginxserver is already running on your system, restart thenginxservice after installing PHP:# systemctl restart nginxStart the
php-fpmservice:# systemctl start php-fpmOptional: Enable both services to start at boot time:
# systemctl enable php-fpm nginxTo obtain information about your PHP settings, create the
index.phpfile with the following content in the/usr/share/nginx/html/directory:# echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.phpTo run the
index.phpfile, point the browser to:http://<hostname>/Optional: Adjust configuration if you have specific requirements:
-
/etc/nginx/nginx.conf-nginxmain configuration -
/etc/nginx/conf.d/php-fpm.conf- FPM configuration fornginx -
/etc/php-fpm.conf- FPM main configuration -
/etc/php-fpm.d/www.conf- defaultwwwpool configuration
-
Run the "Hello, World!" PHP script using the nginx server.
Create a
hellodirectory for your project in the/usr/share/nginx/html/directory:# mkdir helloCreate a
hello.phpfile in the/usr/share/nginx/html/hello/directory with the following content:# <!DOCTYPE html> <html> <head> <title>Hello, World! Page</title> </head> <body> <?php echo 'Hello, World!'; ?> </body> </html>Start the
nginxserver:# systemctl start nginxTo run the
hello.phpfile, point the browser to:http://<hostname>/hello/hello.phpAs a result, a web page with the "Hello, World!" text is displayed.
See
nginx(8)andphp-fpm(8)man pages for more information.