In this post, I will show you how to install LAMP on Ubuntu 18.04 Server. LAMP stands for Linux, Apache Web Server, MySQL, and PHP.
A good portion of web applications deployed today are deployed on a LAMP stack.
In this post, I will walk you through the process.
Make sure you have a fresh copy of Ubuntu Server 18.04 installed and fully updated.
To begin, we will need to install the Apache 2 Web Server.
After it is installed, you can browse to the server's IP address or DNS name and see the default web page that comes with Apache.
All of your web content by default is located in /var/www/html.
In addition, everything in the /var/www/html directory needs to be owned by the www-data user and www-data group for the Apache Web Server to be able to read the files.
Next, we will install the MySQL Database.
MySQL is an open-source relational database that is very robust.
Run the following command to install MySQL.
After it is completed installing, we need to secure it. Run this command to secure MySQL.
This script will ask you several questions.
The first question will ask you to install the Validate Password Plugin.
I typically answer "N" to this question because I know my password is secure. You can answer "Y" if you would like.
Next, the script will ask you to set a new password for the root MySQL user.
The script will now ask you to remove anonymous users. Answer "Y."
Next, it will ask you if you want to disallow root login remotely. We should always answer "Y" to this.
It will ask you to remove the test database and access to it. Answer "Y."
Next, it will ask you to reload the privilege tables. Answer "Y."
Finally, the script completes.
MySQL is now installed.
The last step to install LAMP on Ubuntu 18.04 is to install the PHP preprocessor.
PHP adds server-side web page processing that enables dynamic web pages.
Run the following command to install PHP.
Next, we need to tell Apache to serve PHP pages first.
Open /etc/apache2/mods-enabled/dir.conf file and change it to have index.php listed first.
Finally, we need to restart the Apache Web Server.
We should make sure that PHP is working correctly.
Create a new file in /var/www/html called info.php with the following contents:
Save and exit the file.
Now browse to this URL:
And you should see the PHP Information page.
Remove the file after you have verified that PHP is working.
Installing PHP Modules
Most likely, when you install a PHP based application, it will have PHP module dependencies.
A common PHP module is the php-curl module.
We can use apt to install these. Just prepend a "php-" in front of the module that you need to install.
If you are having trouble finding the module you need, simply type in "apt install php" (first letter of module), then hit the TAB key.
Ubuntu will list all the matching packages for you.
In this post, we learned how to install LAMP on Ubuntu 18.04.
I hope you have enjoyed this post and that it was helpful. If it was, then please share it and comment below.