Install LAMP (Linux Apache, Mysql Server and Php) on an Ubuntu 14.04 64bit VPS Server
Introduction
What is a LAMP server?
Basically it is a server installed with Apache, Mysql and PHP to serve websites and web applications for public consumption. This is in the background of every websites you visit, every app you open on your phone, your laptop, your desktop and even your tv.
It serves data that can be used by your phone applications, it processes information that will be shown in your desktop applications. In short, a webserver installed with LAMP can be called part of the building blocks of the internet.
In this guide we will show you how to install a LAMP server including tutorials on how to configure and how you can use this technology for good use.
Prerequisites
The tutorial will assume that:
- You have an Ubuntu 14.04 64bit vps server from vpsserver.com. If you dont have, you can purchase one from https://www.vpsserver.com/plans/
- You have already logged in to your vps server using an ssh terminal.
- You have knowledge in the basic command for Ubuntu or linux.
Installing Apache
The apache web server is a piece of open-source software that processes information requested by the user. Once a user requested a webpage, it looks for the file and show the webpage to the user. It also handles communication between your computer and the server.
To install apache we can start by executing the following commands. Remember, if you do not have administration rights or root privileges on the server you will have to add sudo as a starting command.
sudo apt-get update
sudo apt-get install apache2
You can verify if Apache is installed properly by going to your web browser and entering the ip address of your server. You should see the below webpage:
Knowing your Server's IP address
In case you do not know the IP address of your server you can always enter the command below:
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
This will return the ip address of your vps server.
Installing Mysql
After verifying that Apache is up and running we can now start the installation of our Mysql server.
A Mysql server stores valuable information from your website using a file called a database. This database consist of a table which then consist of rows and columns of data that can be retrieved by our webpage to be shown to users or for use by an application.
To install Mysql server we will need to run the following commands:
sudo apt-get install mysql-server php5-mysql
Again, I am assuming that the user do not have root privileges that is why i added sudo at the start of the command.
During the installation, the server will ask you to select and confirm your administrator or root password, These root passwords will be used when you would like to add or make changes to the database and mysql server configuration.
Once the installation is finished you will have to create a database structure which will be used to store mysql server information.
sudo mysql_install_db
Afterwards, run the following script to secure your mysql server installation. This will lock down access to the server and avoid security and performance issues.
sudo mysql_secure_installation
During the configuration you will be asked for the root password that you entered earlier. It will also ask you if you want to change this password or not. If you can happy with your password you can skip this step. You can just simply hit ENTER for the rest of the questions.
Now that your database and Apache server is already up and running we can now move on to installing PHP.
Installing PHP
PHP is a software that processes dynamic content for your webpage and, depending on your needs, it can communicate with our Mysql server to provide realtime, dynamic results and data to our users.
Some use of PHP is to provide information on user accounts, traffic updates, location information and many more. To install PHP we will execute the following commands.
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
This will install the basic requirements of running php in your webserver. We will test the configuration later on.
From our configuration, when a user requested a webpage it will direct them to index.html file and this is not what we want, We would like to provide our users with a php page so we will exit the Apache file to include index.php in the configuration.
Type the below command to open our dir.conf:
sudo nano /etc/apache2/mods-enabled/dir.conf
Afterwards, look for the line below:
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
We will move index.php so Apache will look for index.php first:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
After that, save the file by pressing CTRL+X and exit by confirming the save by pressing Y. Then hit Enter.
Next, we need to restart Apache so it will read the new configuration.
sudo service apache2 restart
Installing other PHP modules
To further enhance the capabilities of php we can optionally install some modules. A reason to add modules is that it may be required by our application or webpage.
To check for available modules type the following commands:
apt-cache search php5-
The modules available will then be shown to you like below:
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-common - Common files for packages built from the php5 source
...
To get an information on what the module does, you can get the name of the module and use the following command below. Alternatively, you can search thru the internet as well.
apt-cache show php5-gd
To install a module, you can execute the command below:
sudo apt-get install php5-gd
Or to install multiple modules just add it into the existing command:
sudo apt-get install php5-gd php5-common
Testing PHP
In order to check if our PHP installation is working and that all installed modules are properly configured we will have to create a php file containing our php information.
To do this we will creat a file in our /var/www/html directory called info.php.
sudo nano /var/www/html/info.php
Open the file and paste the following php script inside the file:
<?php
phpinfo();
?>
Save and close the file. Afterwards, open your web browser and enter your server ip address followed by the filename we just created.
http://your_server_IP/info.php
You should see the same page as below. The data in your info page may be different from mine since some of the modules I have may not be installed on your server. What is important at this time is that your page is properly processing php information.
You can use this information later on to check on the health of your server as well as to have an idea on what modules you will need to install in order to get your application or webpage up and running.
Now that your LAMP server on Ubuntu 14 64bit is all set-up and configured we can now install applications that we will need. You can install wordpress or create a dynamic php file for your users.
If you have any questions or suggestions you can always comment below.
Related Tutorials
Installing LAMP (Linux Apache MySQL and PHP) Stack on CentOS 7 64bitSetup a Master-to-Master Replication Between Two MariaDB Servers
Setup and Configuration of FreeRadius + MySql on Ubuntu 14.04 64bit
Setup and Configuration of Strongswan & Accel-PPP on Ubuntu 14.04 64bit
Common SSH Commands