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.
This completes the LAMP stack installation for Ubuntu.