Install Lamp Server on Ubuntu

Install LAMP server ubuntu

Install LAMP Server – Ubuntu: The command we’re all after….

Install LAMP Server on Ubuntu?

A few complex packages but all (bar linux!) can be installed with one command and then following the on-screen instructions:

(NOTE: All the commands here need to be typed into a terminal, open one by pressing Ctrl+Alt+T.)

It’s important to remember the caret (^) at the end of the command.

Thought I’d get that out the way for all the hit and runners looking for the command!


The use of ^ in the package name suggests that this is a ‘meta-package’. Meaning a number of programs that are usually installed together.

If you try to remove this ‘meta-package’ you could remove a lot of programs you are not expecting to… SSH being one of them!

So please do install your lamp server using these instructions, but do not remove it using lamp-server^

Let’s proceed……

What is LAMP Server

LAMP Server is a collection of open source software used to create a web server. The collection consists of:

  • Linux – the operating system
  • Apache server – the server
  • MySQL – the database system
  • PHP – the programming language

Clearly named after the initials of its components, these four applications are all lengthy subjects in their own right. So I won’t go much further on them, but if you have any questions post a comment and I’ll always try help.

Installing Lamp Server components individually

Installing Linux

Installing Linux unfortunately isn’t as simple as one command. But installing Ubuntu is as simple as installing any other operating system. The latest installation .iso can be downloaded here. Ubuntu isn’t the only version of Linux, a list of major distributions can be found at distrowatch.

Installing Apache Server

Apache Server can be installed in one line:

You can test the installation by visiting http://localhost/ in a browser, you should see a massage saying “It works!“.

Installing MySQL Server

Installing MySQL is as simple as another one line in the terminal:

This installs:

  • MySQL Server – to store/serve your database
  • MySQL Client – a client to access your MySQL server

Be sure to pay attention during the install. You will be asked to create a password for the MySQL root user. You can then access the server in the terminal by typing/copying:

Obviously replace ‘password‘ with the password you just created (leave the ‘-u‘ and ‘-p‘ before your username and password). You should now be logged in and be displaying ‘mysql>‘ on your command line ready for your SQL queries!

Installing PHP

PHP requires 3 packages to be installed, again its only one line:

You must restart your Apache server now for the changes to take effect:

To test this, open gedit and type/copy:

Save the file as info.php. Now navigate to this file in your web browser by visiting http://localhost/info.php, you should see a page displaying your PHP version and the rest of your PHP installation information.


You have now installed a LAMP server on Ubuntu! You are now ready to serve web-apps with server side scripting and MySQL database access. There are other features to configure that we may go into in later articles, but for now drop me a comment if you have any questions or need any help.

  • Guest

    I’m brand new to Ubuntu and this helped me a lot.
    Thank you!

  • I’m brand new to Ubuntu and this guide helped me a lot.
    Thank you!

  • Ezekia Matabaro

    when I try to creata the page info.php into var/www leads to the following error:
    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    What can i to change that port used by apache server of Ubuntu please:

  • when I try to creata the page info.php into var/www leads to the following error:
    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    What can i to change that port used by apache server of Ubuntu please:

    • What version of Ubuntu are you running?
      Can you try restarting your Apache server (sudo service apache2 restart) and post any errors.

  • Rhythm

    it’s not working, i have restarted, but no use, same error Apache/2.2.22 (Ubuntu) Server at localhost Port 80, My ubuntu version is 12.10.

    • Does visiting this page http://localhost/ give you the working message? or is it just the info.php part?

      • Francis Musyoki

        localhost and localhost/info.php/ gives me a message but localhost/phpmyadmin gives me the above error! please help asap…

        • sudojuice

          phpmyadmin is a separate package and will need installing. Have you checked it is actually installed? (sudo apt-get install phpmyadmin – should install it or tell you if its already installed and up to date)

  • Pityu

    Hello, I’m new in ubuntu and have a problem wen I install mysql-server. I recive this message: E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
    E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
    I have ubuntu 12.04

    • This could happen either because you are not typing “sudo” before the install command, or you are running updates, or possibly have Synaptic open. The latter 2 could lock aptitude from installing.

  • r00tusr

    Just a word of warning about removing the LAMP from your server using the same apt-get method.

    I have a ubuntu vps that I installed LAMP on using ” apt-get install lamp-server^ “. I then decided to remove LAMP packages from my server as it was not being used anymore. I did ” apt-get remove lamp-server^ “.

    I disconnected my ssh session to my vps and shutdown my machine for the day. The next time I went to ssh into my server I was not able to. It was almost as the sshd was not running anymore.

    I logged into my ubuntu vps via the serial console in my hosting provider control panel. When I checked for sshd, sure enough it was not installed.

    When checked the log for apt-get I saw that the openssh package was part of the LAMP installation.

    Entry in log.
    Commandline: apt-get remove lamp-server^

    Remove: bind9:i386 (9.8.1.dfsg.P1-4ubuntu0.5), apache2-utils:i386
    (2.2.22-1ubuntu1.2), sendmail-bin:i386 (8.14.4-2ubuntu2), libwrap0:i386
    (7.6.q-21), libsnmp15:i386 (5.4.3~dfsg-2.4ubuntu1.1),
    libnet-daemon-perl:i386 (0.48-1), sendmail:i386 (8.14.4-2ubuntu2),
    libclass-isa-perl:i386 (0.36-3), libaprutil1-dbd-sqlite3:i386
    (1.3.12+dfsg-3), libswitch-perl:i386 (2.16-2), perl:i386
    (5.14.2-6ubuntu2.2), sendmail-base:i386 (8.14.4-2ubuntu2), libcap2:i386
    (2.22-1ubuntu3), libhtml-template-perl:i386 (2.10-1), libdbi-perl:i386
    (1.616-1build2), apache2.2-bin:i386 (2.2.22-1ubuntu1.2),
    mysql-client-core-5.5:i386 (5.5.29-0ubuntu0.12.04.2),
    libdbd-mysql-perl:i386 (4.020-1build2), mysql-server-5.5:i386
    (5.5.29-0ubuntu0.12.04.2), libapr1:i386 (1.4.6-1),
    libfile-copy-recursive-perl:i386 (0.38-1), xinetd:i386
    (2.3.14-7ubuntu4), mysql-common:i386 (5.5.29-0ubuntu0.12.04.2),
    mysql-client-5.5:i386 (5.5.29-0ubuntu0.12.04.2), quota:i386
    (4.00-3ubuntu1), libaprutil1-ldap:i386 (1.3.12+dfsg-3),
    apache2-mpm-prefork:i386 (2.2.22-1ubuntu1.2), libplrpc-perl:i386
    (0.2020-2), tcpd:i386 (7.6.q-21), apache2:i386 (2.2.22-1ubuntu1.2),
    mysql-server-core-5.5:i386 (5.5.29-0ubuntu0.12.04.2), sensible-mda:i386
    (8.14.4-2ubuntu2), samba-common-bin:i386 (3.6.3-2ubuntu2.3), snmp:i386
    (5.4.3~dfsg-2.4ubuntu1.1), apache2.2-common:i386 (2.2.22-1ubuntu1.2),
    mysql-server:i386 (5.5.29-0ubuntu0.12.04.2), update-inetd:i386 (4.41),
    ssl-cert:i386 (1.0.28ubuntu0.1), samba:i386 (3.6.3-2ubuntu2.3),
    perl-modules:i386 (5.14.2-6ubuntu2.2), rpcbind:i386 (0.2.0-7ubuntu1.2),
    libmysqlclient18:i386 (5.5.29-0ubuntu0.12.04.2), bsd-mailx:i386
    (8.1.2-0.20111106cvs-1), php5-mysql:i386 (5.3.10-1ubuntu3.6),
    php5-cli:i386 (5.3.10-1ubuntu3.6), libapache2-mod-php5:i386
    (5.3.10-1ubuntu3.6), openssh-server:i386 (5.9p1-5ubuntu1),
    libaprutil1:i386 (1.3.12+dfsg-3), php5-common:i386 (5.3.10-1ubuntu3.6),
    rmail:i386 (8.14.4-2ubuntu2)

    sshd was installed with my initial ubuntu install. Openssh (sshd) is part of the LAMP packages. When I did ” apt-get remove lamp-server^ ” it removed openssh, and disabled my remote access to my server.

    Just wanted to make sure no one else makes that mistake!

    • Thanks for sharing, this is something pretty important!

  • Guest

    You can install lamp server using one command # apt-get install lamp-server^.

  • anonymous

    i installed it with sudo apt-get install lamp-server^ and everything works, but I cannot edit index.html or create files in that place

  • What is wrong with you people! so i INSTALLED LAMPSERVER, THEN HOW DO I RUN IT? done lamp-server, lamp, lampserver…. wtf! gimme the command to run it

  • Good installing. HOW DO YOU RUN???!!!

  • Malamadre

    Can you tell me, what means caret ^ at the string …lamp-server^?

  • Pingback: LAMP server - installing via tasksel or apt-get ?()

  • Thanks very much.

  • Varun Chakkera

    Hi, I’m new to this but i read all the comments to see through all the problems i and they are facing at a similarity the error “Apache/2.2.22 (Ubuntu) Server at localhost Port 80”. But when i type only “http://localhost/” then there’s a “It Works” message but i still cant launch the info.php through the ULR. can u please help me?

  • This is a straightforward step to install lampserver. It works.

  • omachol james

    I have installed the lamp server using

    sudo apt-get install lamp-server^ but still doesn’t show when I search it from my pc ,what can I do so as to use it

    • What do you see when visiting http://localhost what output do you get?
      What response do you get running “whereis apache2” in a terminal
      Also run “systemctl status apache2.service” in a terminal… hopefully you will see ‘active (running)’ about 5 lines down