Installing LAMP (PHP 5.6, Apache 2.4, MySQL 5.6) on Elementary OS

LAMP on elementary OS Freya

I’m a web and mobile application developer by profession and developing on LAMP (Linux, Apache, MySQL and PHP) stack for last couple of years. Now it’s time to get development environment ready on my newly installed elementary OS “Freya”. I will install everything separately instead of using the tasksel command.

At the time of writing this article, I’m installing the latest stable version of all the things I am going to need.

  • PHP 5.6
  • Apache 2.4
  • MySQL 5.6

Installing Apache 2.4

We will add the repository of the latest Apache version to our system by using the following command:

Then run the following two commands to install Apache 2.4:

Installing PHP 5.6

First, we will add the repository of the latest PHP version to our system by using the following command:

Then run the following two commands to install PHP 5.6:

This will install PHP on our system.

Installing MySQL 5.6

We will add the repository of the latest MySQL version to our system by using the following command:

Then run the following two commands to install MySQL 5.6:

This will install MySQL on our system.

You will be asked to set password for the “root” user for the MySQL server during the process.

Voila! Our development environment is ready now 🙂

If you visit http://localhost now, you will see the Apache2 Ubuntu Default Page.

Apache2 Ubuntu Default Page

Now let’s write some PHP code to check if everything is working properly. Let’s create a PHP file named info.php on the default document root folder of Apache web server which is /var/www/html and add the following code to the file:

Save the file. Then visit the file on your browser: http://localhost/info.php

You should get an output like this:

LAMP on elementary OS Freya


You may need to install some other PHP extensions and libraries according to your need manually. I will cover this in future. Feel free to comment if you have any queries.

Author: Muhammad Sumon Molla Selim

Homo sapiens by Born. Coder by Heart. Entrepreneur by Passion. Founder of Kodeeo & Lets Learn Coding. Software Engineer at GG, Bashundhara Group.

21 thoughts on “Installing LAMP (PHP 5.6, Apache 2.4, MySQL 5.6) on Elementary OS”

      1. Hi how about phpmyadmin i currently install php5.6 and once i install phpmyadmin it says mbstring is missing got any solution to that? thanks

  1. good guide! I guess, since the user wants to use mysql with php, you should add howto add php mysql extension which doesn’t come with the basic php5 package

  2. Hi, thanks for the info, if I’m already installing to ‘official’ repo which I get are PHP 5.5.9 and MySQL 5.5, can I just follow your instructions or I have to remove them one by one?


  3. Hello I might have a question about changint DocumentRoot, i found in documentation I have to install suEXEC to be able to change it (they say i cannot change apache2.conf , while i tried i had an perrmision error occured even with set up permission at 777 -R on folder i wanted to be my DocumentRoot). Buut i wasnt able to proceed with suEXEC and setup succesfully new DocumentRoot folder (I want it to be a Dropbox folder so i can edit codes from another devices ).

    Sorry for my quite not good english, hope you understand my problem and im looking foward to your answer

      1. Yeah i tried that already, came out with error:

        You don’t have permission to access / on this server.
        Apache/2.4.16 (Ubuntu) Server at localhost Port 80

        Folders permission is set to 666, tried 777 and still doesnt work. I had no problems with other devices (windows 7, Ubuntu). The folder im trying to reach is in Dropbox folder, may this have some effect? I tried to reinstall apache2 (purge apache2 and install it with your guide) and still the same error.

  4. Hello Friend, i just have a problem, when i installing mysql-server

    The following packages have unmet dependencies:
    mysql-server : Depends: mysql-server-5.6 but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.
    I just after tried [sudo apt-get autoclean && sudo apt-get autoremove] sudo apt-get install -f sudo apt-get dist-upgrade && sudo apt-get update

    And try again sudo apt-get install mysql-server
    but not change anything, can yoou help me ?

    1. Can we please try with these?

      sudo apt-get purge mysql-client-core-5.6
      sudo apt-get autoremove
      sudo apt-get autoclean
      sudo apt-get install mysql-client-core-5.5
      sudo apt-get install mysql-server

Leave a Reply