Bootstrap FreeKB - Apache (Web Server) - Configure Apache to use PHP
Apache (Web Server) - Configure Apache to use PHP

Updated:   |  Apache (Web Server) articles

Apache (or HTTPD) typically used a PHP module so that Apache can produce PHP pages. In laymen terms, this typically means configuring Apache with the PHP module file such as libphp.so.

Check out my article Compile PHP as an Apache module for steps on how to create the libphp.so file. And then place the libphp.so file in the modules directory of your Apache web server.

/path/to/modules/libphp.so

 

In the directory that contains your Apache conf file, update your httpd.conf file to contain something like this and restart your Apache server for this change to take effect.

LoadModule php_module modules/libphp.so

 

The httpd command with the -M flag can be used to display the modules that are currently loaded.

<web_server_root>/bin/httpd -M

 

Likewise, the apachectl command can be used.

<web_server_root>/bin/apachectl -M

 

If you have multiple web server configuration files (e.g. httpd.conf), the -f option can be used to point to a specific httpd.conf file.

<web_server_root>/bin/httpd -f <web_server_root>/conf/httpd.conf -M

 

Which should return output that contains the PHP module.

Loaded Modules:
 php_module (static)

 

Create the phpinfo.php file in the document root of your web server.

touch /var/www/html/phpinfo.php

 

Add the following to the phpinfo.php file.

<?php
   phpinfo();
?>

 

Make the following changes to the /etc/php.ini file. The reason open_basedir is set to /var/www instead of /var/www/html is because if HTTPD will be producing two or more websites using virtual hosts, setting open_basedir to /var/www ensure that every site at and below /var/www can use PHP.

expose_php = Off
open_basedir = /var/www

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable httpd.

systemctl restart httpd
systemctl status httpd

 

If your system is using init, use the chkconfig and service commands to start and enable httpd.

service httpd restart
service httpd status

 

Navigate to www.example.com/phpinfo.php, and the PHP info page should be displayed.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e1add1 in the box below so that we can be sure you are a human.