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:
- Log in to your server using SSH.
- As the root user, type the following commands to update the system:
As the root user, type the following commands to install the tasksel package and then run it:
apt install tasksel
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.
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:
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:
The mysql_secure_installation program enables you to configure additional security settings for MySQL.