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:
Â
https://<your_server_IP_address>
Â
You can find your server’s public IP with the following:
Â
sudo apt-get install curl
curl https://icanhazip.com
Â
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.
mysql_secure_installation
Â
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.
https://<your_server_IP_address>/info.php
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!
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
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: https://askubuntu.com/questions/1031921/php-mcrypt-package-missing-in-ubuntu-server-18-04-lts).