Skip to main content
Skip table of contents

How to Install LAMP (Linux,Apache,MySQL,PHP) Stack on Ubuntu 16.04 Instance

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

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.php index.xhtml index.htm

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

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

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

$ sudo systemctl restart apache2

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

$ sudo vim /var/www/html/info.php

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:


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


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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.