A "LAMP" stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps.

Before you begin with this guide, you should install Apache Web Server by following this guide and you should install MySQL by following this guide. After that we will install PHP to complete our LAMP stack.

PHP will process code to display dynamic content and it can connect to our MySQL databases and it can run scripts. We should install some helper packages for PHP to talk to MySQL and run PHP code under the Apache server.

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

After installation is completed, we will edit /etc/apache2/mods-enabled/dir.conf file for telling to Apache prefer to PHP files.

It will look like this

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
CODE

We want to move the PHP index file to the first position :

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl  index.xhtml index.htm
</IfModule>
CODE

After that you should save the file and restart the apache service.

$ sudo systemctl restart apache2
CODE

For testing PHP , we will create info.php script located at /var/www/html/ directory.

$ sudo vim /var/www/html/info.php
<?php
phpinfo();
?>
CODE

After that save and close the file.

Now we can test our web server can correctly display content generated by a PHP script. For visiting this page, you should write your instance public ip to web browser search bar like this:

YOUR_INSTANCE_PUBLIC_IP_ADDRESS/info.php
CODE

After that, the page that you come to should look like this:

php.png

If you see the above page, this means your PHP is working as expected. This page gives you information about your server.

After testing PHP, you should remove info.php file because it give information about your instance to unauthorized users.