PHP is a popular programming language that is widely used in web development, CMS and blogs. It is most commonly used with Apache web server. However, you need to enable PHP in Apache, in order to be able to execute PHP code on it. In this article, we will learn how to enable PHP in Apache web server.
How to Enable PHP in Apache
Here are the steps to enable PHP in Apache. If you have not installed PHP on your system, open terminal and run the following command to install it.
$ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
In Ubuntu/Debian systems, you can easily enable PHP in Apache using the a2enmod command, and restarting Apache server, as shown below.
$ sudo a2enmod php5 $ sudo service apache2 restart
If you are running Redhat/CentOS/Fedora systems, open Apache config file in a text editor. It is located at any of the following locations.
Run the following command to open the configuration file of Apache server.
$ sudo vi /etc/apache2/httpd.conf
Uncomment the following line by removing # at is beginning
#LoadModule php5_module /path/to/mods-available/libphp5.so
LoadModule php5_module /path/to/mods-available/libphp5.so
Save and close the file. Restart Apache server.
$ sudo service apache2 restart
That’s it. In this article, we have learnt how to enable PHP in Apache.