How to install LAMP server on Ubuntu

Recently a friend of mine asked me for step-by-step guide for installing LAMP server. Since there is such a need, I decided to share this guide with a larger community.


LAMP is an abbreviation of the first letters of Linux (operating system), Apache HTTP Server (web server), MySQL / MariaDB (database server) and PHP / Perl / Python (script language). The AMP software package works on other operating systems such as Microsoft Windows (and then it is called WAMP), Mac OS (MAMP), Solaris (SAMP) or OpenBSD (OAMP). Although the original authors of these programs have not designed them all to work with each other, the contemporary development philosophy and toolsets are common and have been developed in close collaboration. This software combination has become popular because it is free and opensource, so it’s easy to modify and because of the universality of the components of the package that come with every modern Linux distribution.

To the point. I will skip the installation of Linux itself 😉 and will go straight to installing the rest of LAMP server on Ubuntu 16.04 LTS Xenial Xerus. Of course, all commands are executed in the console / terminal.

Apache HTTP Server

To install Apache HTTP Server you need to issue one command only:

Your web server should be accessible in your browser, just type http://localhost/.

Apache2 Ubuntu Default Page

Apache2 Ubuntu Default Page

Apache2 looks for website in the default location /var/www/. By default this directory is writable by root user only. To host homepages of all other users you can enable userdir module. In this case regular user stores its homepage in ~/public_html/ directory and it is accessible on the web at http://localhost/~username/.

After making changes, you need to restart Apache server.

Self-signed SSL Certificate for Apache HTTP Server

Next thing to do is to create a self-signed SSL Certificate which will allow you to encrypt traffic to your server. Additionally, the certificate can show server’s identification information to site visitors.

The first command openssl will create a self-signed SSL Certificate. I will tall a bit about its parameters:

  • req – this specifies a subcommand for X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that SSL adheres to for its key and certificate managment. Since we are wanting to create a new X.509 certificate, this is what we want.
  • -new – this option will create the certificate request.
  • -x509 – this option specifies that we want to make a self-signed certificate file instead of generating a certificate request.
  • -days 1461 – this specifies that the certificate we are creating will be valid for 3 years. Don’t create certificates valid only for one year, in my opinion this is to short.
  • -key – this parameter names the input private key file already present in Ubuntu installation.
  • -out – this option names the output file for the certificate that we are generating.

The command will be asked a number of questions. The most important and the only requested item is the line that reads Common Name (e.g. server FQDN or YOUR name). You should enter the domain name you want to associate with the certificate, or the server’s public IP address if you do not have a domain name.

The second and third command will activate the SSL module and the SSL Virtual Host.

Apache2 SSL UserDir

Apache2 SSL UserDir


PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MariaDB / MySQL or PostgreSQL databases to get information, and hand the processed content over to our web server to display. Installing PHP is easy. Besides PHP itself we will install additional package, so that PHP code can run under the Apache server.



MariaDB and phpMyAdmin

It’s time to install MariaDB server. MariaDB is a database management system and it is a fork of MySQL. Installing MariaDB isn’t as easy as PHP, but we can handle it as well. The beginning is obvious:

By default MariaDB uses Unix Socket to login as root. Unix Socket enables logging in by matching uid of the process running the client with that of the user in the mysql.user table. In other words to access MariaDB as root you have to be logged in as root. In order to make phpMyAdmin work, we have to change logging in method to mysql_native_password.

Now we can install phpMyAdmin without problems and then secure MariaDB installation. phpMyAdmin is a set of PHP scripts for easy MariaDB / MySQL database management. It allows you to create / delete databases, add / delete relationships, and edit their structure and contents. All operations can be performed from a web browser, in a graphical environment, without having to work with the default text interface. The phpMyAdmin installer will ask you to choose a web server that will be automatically configured to run phpMyAdmin and the password for phpmysql user. If we leave it blank, the installer will generate the password itself for the newly created phpmyadmin user.

phpMyAdmin on LAMP

phpMyAdmin on LAMP

The second command will ask you a few questions on production servers I strongly encourage you to answer 'Yes’ to all questions:

This is enough to make LAMP work, but the field for configuration changes is large.

0 0 votes
Article Rating
Powiadom o
0 komentarzy
Inline Feedbacks
View all comments