Home Linux How to Install LAMP on Ubuntu Linux

How to Install LAMP on Ubuntu Linux

Before learning of how to install LAMP on Ubuntu, I would like to share some basic information about it first. Before going to see this tutorial, you must know how to install MySQL and Apache web server in Ubuntu Linux because it will be required in the subsequent process of installing LAMP on Ubuntu. Ok, let’s start with LAMP. This software is a combination of few open source software. It is usually installed at a time for enabling a server to handle web apps as well as the dynamic website.

The combination of the LAMP is L-Linux operating system, A-Apache web server, M-MySQL database, P-PHP. In Apache web server installed in Linux operating system, MySQL database stores the site data, and PHP processes dynamic content. Here, I am going to show you how to install LAMP on Ubuntu.

Basic Requirements


Prior to going through the following steps, you need to have an individual a non-root user account having sudo privileges set up on the server to install LAMP on Ubuntu server.  

  • Installing Apache and Allowing in Firewall

In the world of web servers, Apache is the best and most used one. For excellent fastness, reliability, and security it became so dominant in this field, and it is used on 67% of all web servers. In the history of the web, Apache established itself as the best choice to the users. For more information about installing the Apache web server in Ubuntu, follow my tutorial to learn how to do that.

  • Installing MySQL

We have installed a web server, and it is now in running condition. Now, MySQL is to be installed. It is a database management system which will organize and allow access to the database. Here, site information can be stored. Please follow my tutorial on how to install MySQL in Ubuntu Linux.

  • Install PHP on Ubuntu

PHP is the setup component, and it will make code suitable to display the dynamic content. It is capable of performing multiple functions like running scripts, connecting to a MySQL database for collecting information, and delivering the processed content so that the web server can display it.  

For installing our components, we can again leverage the “apt” system. Some additional helper packages can be installed to aid PHP code to run in the Apache server and respond to the MySQL database.

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

This command will install PHP. During requesting a directory, we shall prefer the way that Apache serves files. Apache will search for a file called “index.html” when a user requests a directory. We want, our web server will give priority to PHP files. So, we will assign Apache to search an “index.php” file first.

To open “dir.conf” file, type the following in a text editor. While writing this keep it in mind to do with root privileges.

sudo nano /etc/apache2/mods-enabled/dir.conf

It will appear like this:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

We want to replace the index file (highlighted above) to the position, immediate after DirectoryIndex specification, like the following.

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Now, press “Ctrl-X,” save and close the file. By typing, “Y” you have to confirm the saving. Then press Enter to ensure the file save location.

Then, restarting of the Apache web server is needed to recognize the changes made. Use the following command to do this.  

sudo systemctl restart apache2

Using “systemctl,” the status of the “apache2″ service can be checked.

sudo systemctl status apache2
  • Install PHP Modules

For enhancing the functionality of PHP, some additional modules can be installed, and it is totally optional. To use the available options for PHP libraries and modules, the results of “apt-cache” search into “less” can be conducted.

apt-cache search php- | less

Arrow keys help scroll up and down. Pressing q, you may exit.

The results are optional installable components which will show a brief description of each.

libnet-libidn-perl - Perl bindings for GNU Libidn
php-all-dev - package depending on all supported PHP development packages
php-cgi - server-side, HTML-embedded scripting language (CGI binary) (default)
php-cli - command-line interpreter for the PHP scripting language (default)
php-common - Common files for PHP packages
php-curl - CURL module for PHP [default]
php-dev - Files for PHP module development (default)
php-gd - GD module for PHP [default]
php-gmp - GMP module for PHP [default]

To obtain more information about the function of each module, you can search the internet. Or, you can read the long description of the package which can be found with the following command:

apt-cache show package_name

“Description-en” will have a detail explanation regarding the functionality provided by the module.

For example, using the following command, you can find out the function of “php-cli module.

apt-cache show php-cli

Using the “apt-get install” command, you can install a package if you feel it is needed to be done after researching. For example, to install “php-cli,” use the following command.

sudo apt-get install php-cli

If you want to install more than one module, use the following.

$ sudo apt-get install package1 package2 package3 ...

Now, your LAMP stack is installed. It is also configured.

Concluding Thoughts


I hope you could able to install the LAMP stack in your system. This platform will let you install and test various web software and popular CMS on your local server which you have just installed using the LAMP. I also hope that this piece of the tutorial on how to install LAMP on Ubuntu is quite helpful? If so, please take time to share this content on your social media. And don’t forget to share your suggestion and experiences in the comment section.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Post

Top 20 Best Openbox Themes for Linux System in 2019

Have you ever heard about the stacking window manager, Openbox? It is broadly used in Unix-like systems. Most probably,...

40 Simple Yet Effective Linux Shell Script Examples

Historically, the shell has been the native command-line interpreter for Unix-like systems. It has proven to be one of...

Top 20 Best NodeJS CMS Platforms To Use in 2019

NodeJs has been a popular web framework. It has been used to develop highly scalable web applications. A statistic...

50 Amazing Linux Crontab Commands For The SysAdmins

Linux offers some of the most reliable, consistent, and smart ways to control your system, be that personal or...

Most Talked Post

Linux or Windows: 25 Things You Must Know While Choosing The Best Platform

Choosing the best platform - Linux or Windows is complicated. Because both the system is versatile and capable of...

Most Stable Linux Distros: 5 versions of Linux We Recommend

At the very beginning, I would like to mention why the term ‘Stable’ comes in relation to Linux OS...

15 Best Things To Do After Installing Linux Mint 19 “Tara”

Linux Mint is one of the best Linux distros for newcomers, especially who comes from other Operating Systems like...

Linux Mint vs Ubuntu: 15 Facts To Know Before Choosing The Best One

Ubuntu and Linux Mint are two popular Linux distros available in the Linux community. Ubuntu is a derivative of...

Editors' Pick

How To Speed Up Ubuntu Linux: 12 Must Follow Tips

Ubuntu is very powerful and polished Debian based Linux...

Top 20 Best Linux VoIP and Video Chat Software in 2019

The Internet has become an integral part of our...

FreeBSD vs Linux: 20 Things To Know About Both The System

If you're an avid Linux system user like me...