Skip to content →

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

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.

Published in Coding

21 Comments

      • achilles achilles

        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

        • Run the following command to install mbstring:

          sudo apt-get install php5.6-mbstring

  1. Davide Davide

    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

    • Thanks for your suggestion. I will write one.

  2. ankit jha ankit jha

    where to write the command ????????????

  3. Dee Dee

    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?

    Thanks

    • Yeah. You have to first remove them so that they don’t conflict with each other. And the system exactly know which version is to be used.

  4. Hi thanks for the info, I have a problem with my kernel 4.1.4 on freya but i don’t why. Something to do?

    • Can you please describe what problem you are facing?

  5. Tofa Tofa

    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

    • Can you let me know more about your OS and Apache version?

      • Tofa Tofa

        I m using elementary OS 0.3.1 Freya (64-bit) and Apache ver. 2.4.7 (Ubuntu – more or less your installation)

        • Have you tried editing the /etc/apache2/sites-available/default file?

          You should change the document root on this file and reload the Apache server.

      • Tofa Tofa

        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.

      • Tofa Tofa

        I tried to change documentroot folder outside of Dropbox folder and still the same error..

        • Can I know what is the user group that those folders are under? You can view by running ls -la command.

  6. 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 ?

    • 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.