How to Install LAMP Stack for Ubuntu

Follow the steps below in order to learn how to install a LAMP stack on a Cloud VPS using Ubuntu. We will be showing you the installation of the individual components that can be used to install the LAMP stack. These steps apply to Ubuntu versions 10 and higher.

Note that all commands shown below require root access on your server using SSH.

How to Install a LAMP Stack in Ubuntu

We will first explain how to install the individual modules installed in a LAMP. This will also provide the opportunity to make tuning adjustments and set security options that you may not often immediately address in the one-liner option for the installation.

  1. So, first we’re going to make sure that everything is up-to-date, then we will install the Apache web server.


    sudo apt-get update

    sudo apt-get install apache2

  2. After the installation, we enable it and then start up the service with these commands:

    sudo systemctl enable apache2

    sudo systemctl start apache2


    You can then check the Apache browser:




    You can find your server’s public IP with the following:


    sudo apt-get install curl



  3. Next we’re going to install the MySQL server portion of the LAMP stack.


    sudo apt-get install mysql-server

  4. After the installation you can set the root password for the MySQL installation with this command.



  5. Finally, you need to install the “P” portion of the LAMP stack – PHP. Use the following instructions to install PHP.


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

    Restart Apache to get the PHP service started.

    sudo systemctl restart apache2

    After you restart the Apache web service, check the status of the web server to make sure that it’s running properly:

    sudo systemctl status apache2


  6. Next, you need to test PHP in order to make sure that it is up and running. The easiest way to do this is to setup a info.php file. Then when you run the info.php file you will see the PHP configuration information.


    sudo nano /var/www/html/info.php


    <?php phpinfo(); ?>


    Once you have entered the code into the text editor (nano), save the file and close Nano.

Next, you would enter the following line in order to see the PHP configuration page. You can verify the PHP installation with this page.


This completes the LAMP stack installation for Ubuntu.

Learn more from our Cloud Server Hosting Product Guide.

Experience full control over your server environment and deploy the best operating and management systems that fit your needs with our reliable Cloud VPS Hosting!
Arnel Custodio Content Writer I

As a writer for InMotion Hosting, Arnel has always aimed to share helpful information and provide knowledge that will help solve problems and aid in achieving goals. He's also been active with WordPress local community groups and events since 2004.

More Articles by Arnel

2 thoughts on “How to Install LAMP Stack for Ubuntu

  1. I get:

    apt-get install php libapache2-mod-php php-mcrypt php-mysql
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package php-mcrypt is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘php-mcrypt’ has no installation candidate

    1. Hello Andrew – Thanks for your comment concerning the availability of Mcrypt. As of version 7.2, Mcrypt has been deprecated, so you won’t be able to install it in that way. You can still install the mcrypt extension using pecl. (Ubuntu forums post:

Was this article helpful? Join the conversation!

Shop the Black Friday Sale
Hurry! These Deals Won't Last Long