Enable PHP Apache2

To enable PHP for Apache2 on Ubuntu, follow these steps:

  1. First, make sure that you have installed the Apache2 and PHP packages. You can do this by running the following command:
sudo apt-get install apache2 php
  1. Once the installation is complete, you need to enable the PHP module for Apache2. You can do this by running the following command:
sudo a2enmod php
  1. After enabling the PHP module, you need to restart Apache2 for the changes to take effect. You can do this by running the following command:
sudo service apache2 restart
  1. Finally, you can test whether PHP is working correctly by creating a file called "info.php" in the root directory of your Apache2 server (usually located at /var/www/html). Inside this file, put the following code:
<?php
phpinfo();
?>

Watch a course Learn object oriented PHP

Then, open a web browser and go to "http://localhost/info.php". If PHP is working correctly, you should see a page with information about your PHP installation.