Skip to content

Install a LAMP stack on Ubuntu 16.04

Note: In general, this guide should work on newer and older versions of Ubuntu. This was tested using Ubuntu 16.04 and 18.04. Concerning other Distributions, it should still work as long as the distro is Debian-based and/or uses apt to install and manage software packages.

What is ‘LAMP’?

A so called LAMP stack is a group of open-source software that allows you to host and run websites, web applications and databases. The name LAMP splits up as follows:

  • Linux, the OS/kernel which Ubuntu is based off
  • Apache, a web server
  • MySQL, a database management system (DBMS)
  • PHP, a scripting language primarily used in web applications.

Installing the LAMP stack

Apache

As a starting point, let’s assume you have a fresh Ubuntu installation up and running. You’ll need sudo rights to perform the operations in this guide.

If you use Ubuntu Desktop, fire up the terminal. The installation of the LAMP stack is done entirely on the command line.

First, update the software package list and install Apache:

sudo apt update
sudo apt install apache2 -y

We use the -y option to directly run the installation, without you needing to manually confirm it.

To test that Apache was installed correctly, use the following command to get your IP:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Note: Depending on where your installation is running and your network setup, you may get your internal IP (like 192.168.0.1) instead of the public one.

When you visit that URL in your browser, you should see a page with the title "Apache2 Ubuntu Default Page". That means Apache was correctly installed.

MySQL

Next, install the MySQL Server:

sudo apt install mysql-server -y

You’ll need to set up a password for the root account of MySQL. Make sure that you remember that password, you’ll need it to log in to the server over the CLI or applications like phpMyAdmin or MySQL Workbench using that password.

PHP

Last but not least, let us install PHP.

PHP is a programming language that runs many popular web applications, like WordPress.

To install it for Apache, run the following:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql -y

Then, restart your Apache server:

sudo systemctl restart apache2

To test it, create a new file called phpinfo.php with the following content:

<?php

echo phpinfo();

?>

Then, go to http://<YOUR SERVER IP>/phpinfo.php. If that page lists informations about PHP and it’s modules, you’re good.

Conclusion

If you followed all steps and had no errors or problems during setting everything up, Congratulations! You just set up your own LAMP stack and are ready to run web applications and databases on your server.

(source)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.