• Get In Touch
April 5, 2016

How to Install LAMP with phpMyAdmin on Ubuntu

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

In this tutorial we’ll learn how to install LAMP (Linux Apache, MySQL, PHP) on Ubuntu. A basic web server installation should include these three packages as they are important to serve both static and dynamic pages.

Apache web server serves the static web page content. MySQL is Open Source Relational SQL database management system and PHP is a scripting languages and widely used to process the dynamic content. phpMyAdmin is a web based application written in PHP and it is used to manage the databases in MySQL server using graphical user interface.

You must have access to the terminal of ubuntu before you install any packages. If you are logged into a non root account then you will have to use sudo command before executing any administrative command. If you are logged into root account then you can omit using sudo before the commands. In this tutorial we’ll use a non root account hence we’ll use sudo before the commands.

We will use Ubuntu’s default repository to install the packages which is apt. It is a best practice to update the apt repository before proceeding to any installation by issuing the following command.

    sudo apt-get update

Installing Apache

You can install Apache Web Server by issuing the command

    sudo apt-get install apache2

It will ask you if you want to continue with installation, press y and then enter. Once the server is installed you can start the server by issuing the command

    sudo service apache2 start

You can check if the Apache web server is working by going to the browser of your computer and accessing your website through the public IP address of your VPS. Which will look like

    http://

For example if IP address of your machine is 164.31.0.40 then go to the following web address.

    http://164.31.0.40

This will show you the default apache web page with some instructions written on it like the one shown below.

Apache Default Page

Configuring Apache

You can remove the default Apache page or put any HTML page in the web root directory which is located at

    /var/www/html/

To remove the default page run this command

    sudo rm /var/www/html/index.html

You can make changes to the apache global configuration file which is located at /etc/apache2/apache2.conf
This file holds main configuration files of Apache2 web server. There are three sections in the global configuration file which are Apache server processes, configuration for the default server and configuration for virtual hosts. We will look at some global configuration here.

You can edit the global configuration file using any editor, in this tutorial we will be using VIM editor. To edit the global configuration file use the following command

    sudo vim /etc/apache2/apache2.conf

You can specify a Timeout for your web server, default is 300 seconds, you can keep it as much as you wish, ideal is 30 seconds, Just replace

    Timeout 300

with

    Timeout 30

You can configure KeepAlive On or Off, KeepAlive specifies that, if Apache should allow more than one request per connection. Default is On. You can also specify MaxKeepAliveRequests, this configuration specifies that how many requests are allowed during a single connection. Default is 100 but recommended is 0 to set this option to handle unlimited requests. KeepAliveTimeout specifies how many seconds to wait for the next request from same connection. Default is 5, you can leave it as it is. If it does not receive the request within the specified time period then Apache will disconnect the KeepAlive session.

Installing MySQL

Installing MySQL server will give you capability to store your data in organized manner. MySQL is a relational database management system. To installing MySQL run the following command.

    sudo apt-get install mysql-server php5-mysql

It will ask you if you want to continue the installation, hit y and enter. Then it will also ask you to set a root password for MySQL, Enter your desired password.

After installing the MySQL server you can start the database server a by issuing the following commands.

    sudo service mysql start

This will run your MySQL server.

You must not confuse with root passwords of Ubuntu server and MySQL server. Both passwords are different. When you are asked for root password of Ubuntu, you must enter the password assigned to root account of your server. When you are asked for root password of MySQL server, you must enter the password you created when installing MySQL server.

It is also strongly advised that after installing your MySQL You should run mysql_secure_installation script once to secure your MySQL installation. You can start running this script by executing the following command.

    sudo mysql_secure_installation

This will ask you for the root password for your MySQL server, if you have provided any password during MySQL installation you will need to enter that password, if not then you can leave this field blank.

If you have no root password for MySQL server then it will ask you to create a password for root user. If you have an existing password then it will ask you, if you wish to change your password, choose the option accordingly.

Then it will ask you if you want to remove anonymous users, by default the MySQL installation creates an anonymous user who can login without any username or password. Press y and then enter key to remove anonymous users and proceed further.

Then It will ask you if you wish to disallow the remote root login, enter y to enable this, it will protect your root password from bruteforcing. It will again ask you if you wish to remove the test database and its privileges, enter y to remove the database.

Finally it will ask you if you want to reload privilege tables, press y to reload the privilege tables, this will write the changes you have just made and MySQL will implement them immediately. You should now see the success message like shown below.

    All done!  If you've completed all of the above steps, your MySQL installation should now be secure.
    Thanks for using MySQL!

Now you can login into your MySQL command line using the following command

    mysql -u root -p

It will ask you for your root password, once you enter your password for the root user, it will show you the following screen.

This confirms that your MySQL installation is working properly.

Installing PHP

Apache can only serve static pages, PHP is used to enhance web pages. PHP is most widely used scripting language. Installing PHP will make Apache to process the PHP code with PHP compiler before serving them.
You can install PHP by issuing following command.

    sudo apt-get install php5 libapache2-mod-php5

This command will install PHP. libapache2-mod-php5 package provides php for Apache2. In order to use PHP with Apache server we will need to restart the server by issuing the following command.

    sudo service apache2 restart

You can also install PHP modules by issuing following command.

    sudo apt-get install  

For example if you want to install three modules at a time which are php5-curl, php5-fpm and php5-cli, you can run the following command.

    sudo apt-get install php5-curl php5-fpm php5-cli

This should install the PHP packages without any error. After installing PHP modules you will again need to restart your server.

You can verify PHP installation by creating a php file with phpinfo(); function. This function will display all the information about PHP processor and all the installed modules of PHP. Execute the following command to create a PHP file using VIM editor inside the Web root directory.

    vim sudo rm /var/www/html/php.php

This command will open VIM editor and you can insert the following lines of code into the file.


After putting these lines quit from VIM editor with writing the changes into php.php file.
Finally you can view the PHP information by browsing this file through web browser, if Public IP of your VPS is 164.31.0.40, then go to the following address.

    http://164.31.0.40/php.php

It should show you all the information about PHP like the screenshot attached.

Installing phpMyAdmin

phpMyAdmin provides a graphical user interface to manage MySQL databases and data inside them. You can also run a custom query through phpMyAdmin. This also gives you capability to create, drop or manage privileges of any databases. You can also export or import the data through phpMyAdmin interface.
To install phpMyAdmin use the following command.

    sudo apt-get install phpmyadmin

It will ask you if you want to continue with the installation, press Y and hit enter to proceed with the installation.

After that it will ask you to select your webserver so that it can configure the server automatically. Select Apache2 by pressing spacebar key and then pressing enter key to proceed. Then It will ask you to use dbconfig-common to setup the database, select yes. Next it will ask you provide a password for phpMyAdmin, you can create any password. Finally it will ask you database administrator password, please enter your database’s root password here, which we had created during MySQL installation.

This will successfully install phpMyAdmin, finally restart the Apache web server by issuing the following command.

    sudo service apache2 restart

Finally you can access your phpMyAdmin at the following address.

    http:///phpMyAdmin

For example if you have a VPS with IP address 164.31.0.40then go to the following address to access your phpMyAdmin.

    http://164.31.0.40/phpMyAdmin

Now you can login to phpMyAdmin using the username root password you have created at MySQL Installation. Once you are logged in you will see a screen like shown below.

Summary

In this tutorial we learned how to install Apache, PHP and MySQL onto Ubuntu. You now have a fully working web stack which can be used for hosting a single or multiple PHP based websites.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]