LAMP is an acronym which consists of: Linux (in our case Ubuntu), Apache web server, MySQL database for storing our website data and PHP for handling the dynamic content.

Creating a non-root user with super user privileges

Before we begin with the installation of the LAMP instance we have to make sure we have a non-root user with super user privileges. This step is important because in Linux managing your system while logged in as root user is considered bad practice. The reason behind this is that the root user has very broad privileges which allow him to gain access and to execute critical commands-commands that can possibly lead to system failure.

In order for us to make a non-root user with super user privileges we need to be logged in as a root user.

Type su in your shell for logging in as root user.

If you don’t have a root account you have to create one.

In order to do so you need to run the following commands

You will be prompted for a password for your root account. Then you need to execute the following command in order to unlock your root account.

Now let’s create the user. Execute the following command:

You’ll be asked some questions. Other than the password the other fields aren’t mandatory.

In order to give your user root privileges execute the following:

This will add your user to the sudo group. As a consequence every time when you run a command starting with sudo you’ll be executing it with root privileges.

In order to log in with your newly created user type this:

Now let us get back to installing the LAMP instance.

Installing Apache Web Server

First we need to install the Apache web server. We’ll be using the Ubuntu repository for the task.

First we have to make sure that our repository is updated. We should run the following.

After our repository has been updated we are ready to install the apache web server. Type this command:

Now our Apache Web Server is installed. To check if your Apache web server installation was successful type your server ip address in your browser. You have to see the Apache2 Ubuntu Default Page.

If you don’t know your server public ip address type the following:

Next to inet you”ll find your ip address

When a directory is requested by default Apache first looks for index.html. We want to change that so as a result apache will look first for index.php. To do so type this:

We want to move the index.php in the first place next to the DirectoryIndex

Now we need to restart the Apache web server in order for our changes to take effect.

Installing MySQL

MySQl is a database management system. With it you can easily store, access and organize your website information.

We need to run the following command in order to install MySQL:

During the installation you’ll be prompted for the MySQL root user password. Just generate one and enter it. After the installation we have to generate MySQL database directory structure.

After that we have to run a security script in order to secure our MySQL installation.

Remove the anonymous user, disallow the remote root login and remove the test database. After that reload the privileged tables. That’s it.

Installing PHP

PHP is going to be used in order to display our dynamically generated content. Again we are going to use the apt-get.

Now our php package has been installed. Php comes with optional modules you can install. In order to search them up type:

From the additional modules we will install php5-cli- command-line interpreter for the php5 scripting language.

Our last task is to test how php handles things. We have to create a test file in a specific directory (web root). on our server.

Now we want to put the following and to save the file:

In order to test our php we need to navigate to the newly created test.php file in our browser.

You have to see something like this:

php
In order to keep your server secured you should remove the test.php file

Now you have a working LAMP instance ready to host your websites.