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.
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
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
Next we’re going to install the MySQL server portion of the LAMP stack.
sudo apt-get install mysql-server
After the installation you can set the root password for the MySQL installation with this command.
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
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.