Linux Apps Tutorials - Herong's Tutorial Examples - v1.02, by Herong Yang
Publish PHP Scripts on Apache Web Server
This section provides a tutorial example on how to publish PHP scripts on Apache Web Server on CentOS Linux systems.
Since PHP is commonly used as the Web server side scripting language, you probably need to learn how to enable the Apache Web server, httpd, to support PHP script pages. Here is what I did on my CentOS 8 computer.
1. Verify that PHP FPM (FastCGI Process Manager), php-fpm, is up and running. If not, install "php-fpm" package and start "php-fpm" service. PHP FPM provides the interface between the Apache Web server and the PHP engine.
herong$ systemctl status php-fpm php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; Active: active (running) since Thu 2020-03-26 23:00:41 EDT; Main PID: 21507 (php-fpm) ...: ...
2. Verify that Apache Web server, httpd, is up and running. If not, install "httpd" package and start "httpd" service. You need to restart httpd, if you have just installed php and php-fpm.
herong$ sudo systemctl restart httpd herong$ systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; Drop-In: /usr/lib/systemd/system/httpd.service.d |-php-fpm.conf Active: active (running) since Thu 2020-03-26 22:06:40 EDT; Main PID: 19007 (httpd) ...: ...
3. Publish a PHP script in in the HTML document directory on the Apache Web server.
herong$ cd /var/www/html herong$ sudo mkdir test herong$ ls -l drwxr-xr-x. 2 root root 6 Mar 28 22:25 test herong$ sudo chown herong test herong$ ls -l drwxr-xr-x. 2 herong root 6 Mar 28 22:25 test herong$ cd /var/www/html/test herong$ ls -l -rw-r--r--. 1 herong herong 73 Mar 28 22:28 test.php herong$ cat test.php <html> <body> <p> <?php print("Hello world!\n"); ?> </p> </body> </html>
4. Verify that the PHP script page is working.
herong$ curl http://localhost/test/test.php <html> <body> <p> Hello world! </p> </body> </html>
Table of Contents