enable php in apache

How to Enable PHP in Apache

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.

  • /etc/apache2/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf

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

to

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.

Also read:

How to Install Rspamd in Ubuntu
How to Connect to Wifi Using nmcli
How to Set JAVA_HOME in Ubuntu
How to Create Large File in Ubuntu
How to Find JDK Path in Ubuntu

Leave a Reply

Your email address will not be published.