Publish PHP Scripts on Apache Web Server

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.

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

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Files and Directories

 Users and Groups

 File Systems

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Software Package Manager on CentOS - DNF and YUM

 Running Apache Web Server (httpd) 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 Web 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

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 GCC - C/C++ Compiler

 Conda - Environment and Package Manager

 Tools and Utilities

 References

 Full Version in PDF/EPUB