How to install a LAMP stack on an Ubuntu server

This article describes how to install a complete LAMP stack on Ubuntu. A LAMP stack is an open-source software bundle that contains the following components:

  • The Linux operating system. (This is already installed on your server.)
  • The Apache web server.
  • The MySQL database management system.
  • The PHP programming language.

With a LAMP stack, you can install and create many popular types of web applications. WordPress, for example, often runs on a LAMP stack.

This article only applies to unmanaged hosting packages. You must have root access to the server to install the Ubuntu operating system template and a LAMP stack.

Installing a LAMP stack on Ubuntu

The following procedure assumes that you have installed the Ubuntu operating system template on your server. If you have not already done this, please see this article for information about how to install an operating system template.

To install a LAMP stack on Ubuntu, follow these steps:

  1. Log in to your server using SSH.
  2. As the root user, type the following commands to update the system:
    apt update
    apt upgrade
    
  3. As the root user, type the following commands to install the tasksel package and then run it:

    apt install tasksel
    tasksel
    
  4. The tasksel interface lists predefined software collections that are available for installation:

    • Under Choose software to install, use the arrow keys to highlight LAMP server.
    • Press the spacebar to select LAMP server, and then press Enter. The installation process starts.
    • When you are prompted to specify a password for the MySQL root user, type the password and then press Enter.
  5. When the installation process finishes, you have a functioning LAMP stack on your server. To test and configure the installation further, follow these steps:

    • Test the web server: To ensure the Apache web server is running normally, use your web browser to visit the domain name (or IP address) of the server. You should see the default Apache page.
    • Test PHP: To ensure PHP is running on the server correctly, type the following command at the command prompt:
      php --version
      Additionally, to verify PHP is integrated with Apache, you can create a web page that contains the phpinfo() function. When you load the page in your web browser, you should see PHP configuration information for your server. For more information about how to use the phpinfo() function to view PHP settings, please see this article.
    • Secure MySQL: During installation you set a root password for MySQL. To help secure the MySQL installation further, type the following command at the command prompt:

      mysql_secure_installation

      The mysql_secure_installation program enables you to configure additional security settings for MySQL.

More Information

Get Ubuntu Server Hosting

Article Details

  • Operating System: Linux Hosting
  • Product: All unmanaged hosting accounts
  • Level: Intermediate

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.