Linux Apps Tutorials - Herong's Tutorial Examples - v1.03, by Herong Yang
Publish PHP Scripts on Apache HTTP Server
This section provides a tutorial example on how to publish PHP scripts on Apache HTTP 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 HTTP 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 HTTP 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 HTTP 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 HTTP 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
Running Apache HTTP Server (httpd) on Linux Systems
Running Apache Tomcat on Linux Systems
►Running PHP Scripts on Linux Systems
Install and Manage PHP Packages on CentOS
"php -i" - Dump PHP Environment Information
Install and Manage PHP Modules on CentOS
Files Used in PHP "include" Statements
►Publish PHP Scripts on Apache HTTP Server
Dump PHP/Apache Environment Information
Change PHP Configuration Settings
Apache PHP file_put_contents() Permission Denied
SELinux Security Context on /var/www/html
Migrate Old Scripts to New PHP Release
Running MySQL Database Server on Linux Systems
Running Python Scripts on Linux Systems
Conda - Environment and Package Manager