How to Enable PHP In Apache

In this tutorial, you'll learn how to enable PHP on your Apache web server.

 

Check Your PHP Version

From the command line, check your version of PHP using the following command:

 

php -v
PHP 7.2.34-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 6 2020 12:01:28) ( NTS )

 

Install PHP

If the above command wasn't recognised, you'll need to install PHP on your system using the following commands:

 

Update Linux:

 

sudo apt update

 

Now install PHP with MySQL and mcrypt plugin:

 

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

 

Enable PHP for Apache

Now enable PHP for Apache using the following command, replacing the version number with the one you have:

 

sudo a2enmod php7.2

 

Restart Apache

To apply the changes, restart Apache with the following command:

 

sudo service apache2 restart
apache

Related Tutorials

 thumbnail

How to Change PHP Version

December 07, 2020
 thumbnail

How to Check PHP Version

July 11, 2020