Install LAMP on Ubuntu 18.04
Introduction LAMP stands for Linux, Apache, MySQL and PHP. With this combination you can host your own websites like Wordpress.
Step 1 - Install webserver In this guide we will be using Apache. Apache is the most popular webserver around.
Start by updating your Ubuntu
sudo apt update
Wait until the updates are downloaded & installed.
Install Apache2
sudo apt install apache2
Your webserver is now available and should be started.
Test your webserver by navigating to your IP address in your browser, you should see a Apache2 default page.
Step 2 - Install database Next step is to install the database.
Install MySQL
sudo apt install mysql-server
It is possible you see a purple screen with some questions about restarting services.
Please select < Yes >
When the installation of MySQL is completed we have to run a small script to set up the password of the database user.
sudo mysql_secure_installation
Answer the questions and set up a password for the database.
When the script has ran, the installation of your database has been completed.
Step 3 - install PHP Now we are going to install PHP.
Install the packages that enables PHP to communicate with the database
sudo apt install php libapache2-mod-php php-mysql
Normally the webserver (Apache2) is looking for an index.html as default page to load. We are going to use PHP so let's set up index.php as our default page to load.
Open the dir.conf text file with the following command
sudo nano /etc/apache2/mods-enabled/dir.conf
You should see the following text in the dir.conf file
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
Edit the file so it looks like this
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Save the file with CTRL
+ O
, press ENTER
.
Exit the file with CTRL
+ X
, press ENTER
.
After editing the file, let's restart our webserver (Apache2) so it will start using the new settings
sudo systemctl restart apache2
Step 4 - Test PHP on your webserver Now that we have the webserver, database and PHP installed, we should be able to run a small PHP test.
Create a new index.php
file.
sudo nano /var/www/html/index.php
Paste the following code into the file:
<?php
phpinfo();
?>
Save the file with CTRL
+ O
, press ENTER
.
Exit the file with CTRL
+ X
, press ENTER
.
Open your webbrowser and navigate to the IP address of your VPS. You should now see a PHP page with information. If you see this page, your PHP modules are functioning.
Have any questions? Please let me know in the comments below!
Related Tutorials
Install LAMP (Linux Apache, Mysql Server and Php) on an Ubuntu 14.04 64bit VPS ServerInstalling Drupal on Ubuntu 16 VPS Server
Installing LAMP (Linux Apache MySQL and PHP) Stack on CentOS 7 64bit
Installing and Configuring Wordpress on an Ubuntu 14.04 64bit Server
Installing LAMP (Linux, Apache, MySql & Php) Stack on Debian 8 Server
comments (2)
Carlos
- 3 years agoI always had a lot of difficulty with linux, your tutorial helped me a lot, thank you for sharing your knowledge
graciously
Pinkman
- 3 years agoI am glad that my tutorial was helpful!