Though installing different versions of php using yum should enable php automatically on Apache 2.2, in case there is a problem and it is not enabled this tutorial shows how to enable it.
Make Sure php Is Installed
We are assuming php has already been installed. If yum
was used you can check this way:
[ahmed@amayem ~]$ yum list installed php
Should give us the following:
Installed Packages
php.x86_64 5.3.3-27.el6_5.1 @updates
If not installed using yum
then we should check the existence of a php.ini
file:
[ahmed@amayem ~]$ ls /etc | grep php
php.d
php.ini
Your php
files do not have to be necessarily in this directory, but it is where the default yum
repository places them.
Checking the php Apache Module
The most important thing we need to check is that there is a php
module:
[ahmed@amayem ~]$ ls /etc/httpd/modules/ | grep php
libphp5.so
Looks like it is there.
Modifying the httpd.conf File
We need to add the following line somewhere in the httpd.conf
file:
LoadModule php5_module modules/libphp5.so
Open the httpd.conf
file for editing:
[ahmed@amayem ~]$ sudo vi /etc/httpd/conf/httpd.conf
Notice that we have to use sudo
to edit the file. Check here to see how to give a linux user sudo powers.
Find the place in the document where all the LoadModule
commands are by entering /LoadModule
and pressing enter. Go wherever you want in the list (or anywhere in the document, in fact) and enter insert
mode by pressing i
. Make a new line (the line must not start with a #
, which would indicate a comment) and paste the following:
LoadModule php5_module modules/libphp5.so
For more on copying and pasting in vi
check here. Exit insert mode by pressing Esc
or Ctrl+c
then save and exit by entering :x
. Now that the config file has been modified we need to restart Apache
Restarting Apache
[ahmed@amayem ~]$ sudo apachectl restart
Testing php
Now that php
has been installed and enabled let’s test it by make a php info page that outputs some information about the installed php.