How to Install LAMP Stack on Ubuntu 18.04

r00t April 29, 2018

Install LAMP Stack on Ubuntu 18.04

In this tutorial we’ll learn how to install LAMP Stack on Ubuntu 18.04. We will also install and configure its prerequisites. LAMP is a simple software bundle made of 4 components, Linux, Apache, MySQL or MariaDB and PHP.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install LAMP Stack on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Apache.

Install Apache by running the following command:

apt-get install apache2 libapache2-mod-php7.2

Once installation is complete, you should enable Apache to start automatically upon system boot. You can do that with the following command:

systemctl start apache2
systemctl enable apache2

Step 3. Installing and configuring MySQL.

Now that we have a web server, we need to install MySQL, a database management system, to store and manage the data for our site. You can install this easily by running the following:

apt-get install mysql-server php7.2-mysql

Start MySQL service using the following command:

systemctl start mysql

MySQL needs some security modifications to help protect your databases from unauthorized access. Run the following command:

mysql_secure_installation

Follow the prompts as below:

  • Would you like to setup VALIDATE PASSWORD plugin? press Enter here for No
  • Please set the password for root here. New password: Type a secure password here then press Enter
  • Re-enter new password: Re-type the secure password here then press Enter
  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : press y and then Enter here
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : press y and then Enter here
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : press y and then Enter here
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : press y and then Enter here

Step 4. Installing and configuring PHP 7.

Next, we are going to install PHP on Ubuntu 18.04:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.2

You may also need to install some additional PHP module:

apt-get install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml

Once the package has finished installing, we can test PHP in the command line:

###php -version

PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.3-1ubuntu1, Copyright (c) 1999-2018, by Zend Technologies

Step 5. Configure Firewall.

The systems with iptables/ufw enabled, execute the following commands to open port 80 for public access of web server:

sudo ufw allow 80/tcp

Congratulation’s! You have successfully install and configure LAMP Server on your Ubuntu 18.04 Bionic Beaver server. Thanks for using this tutorial for installing LAMP Stack on Ubuntu system.

The Tags:

Leave a Comment

Comments are closed.