How to install LAMP on Ubuntu 14.04

How to install LAMP on Ubuntu 14.04

LAMP stands for Linux, Apache, MySQL and PHP. This is a group of opensource applications commonly used to run a web server for hosting and development. This tutorial will include the steps needed to set up a simple web server to get your website up and running. 

Linux is the operating system used to run your server. Since it is already installed we will skip this step. 
Connect to your server though an SSH Session to run the following steps.

Step 1: Installing Apache

Apache is an open source, commercial-grade web server. We will install Apache with the apt command provided by Ubuntu's package manager. 
In your terminal window type the following commands:
  1. sudo apt-get update
  2. sudo apt-get install apache2
When using the sudo command, it will prompt you for your password to execute root privileges. 
You will see something like this 
user@ubuntu1404:~$ sudo apt-get install apache2
[sudo] password for user:
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  apache2-bin apache2-data libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine apache2-suexec-custom apache2-utils openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
0 upgraded, 8 newly installed, 0 to remove and 176 not upgraded.
Need to get 1,289 kB of archives.
After this operation, 5,368 kB of additional disk space will be used.
Do you want to continue? [Y/n]
The default is Y or Yes so you can just click enter and it will start the installation. 
Once this command has been executed the Apache web server will be installed. You can check this by visiting your web server IP address.
  1. http://ip-address-of-your-server/
Once you visit this page you will see the default Apache2 Ubuntu Page. It will look something like this: 


If you see this page then you have installed Apache correctly and we are ready to move on. 

Step 2: Install MySQL

Our next step now that Apache is installed, is to install a database management system called MySQL. This is needed for sites like Wordpress and many other development applications that need to store information in a database. 
From the command line type the following command: 
  1. sudo apt-get install mysql-server php5-mysql
This time running the sudo command does not prompt you for the password as you are within a set time to continue using root privileges. 
After running this command you will see an output like this: 
user@ubuntu1404:~$ sudo apt-get install mysql-server php5-mysql
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18 libterm-readkey-perl mysql-client-5.5 mysql-client-core-5.5 mysql-common
  mysql-server-5.5 mysql-server-core-5.5 php5-common php5-json
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libplrpc-perl libsql-statement-perl libipc-sharedcache-perl tinyca mailx php5-user-cache
The following NEW packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18 libterm-readkey-perl mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 php5-common php5-json php5-mysql
0 upgraded, 15 newly installed, 0 to remove and 176 not upgraded.
Need to get 10.1 MB of archives.
After this operation, 98.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]
The default is Y or Yes so you can just click enter to continue the installation. During the installation you will receive a popup box that asking for a MySQL 'root' user password. This user will have increased privileges. We recommend you adding a very secure password for this user. You will be able to create additional uses later. 



After you enter your password it will ask you to confirm the password.


Next we sill continue setting up MySQL by running a command to create its database directory structure where it stores all the information. 
Do this by running the following command: 
  1. sudo mysql_install_db
Next we will run a security command that will set a few initial parameters that are more secure than the default Ubuntu/MySQL installation
Do this by running the following command: 
  1. sudo mysql_secure_installation
After you run this command you will be asked for the 'root' password of your MySQL database. This is the same password you entered above. Once you enter that password it will ask you if you want to change that password. If you are ok with the current password enter 'n' or 'no' and press enter.
It will continue asking you questions: 
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
You can choose the default Y and click enter though all of these. This will make sure your MySQL instance is secure. 

Now that we have our MySQL database installed we can move on to installing PHP.

Step 3 Install PHP

PHP is used to display dynamic content on your web page. It can communicate with the MySQL database to get information to display to your users. 
To install PHP run the following command in the terminal: 
  1. sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
Running this command will prompt you with something like this: 
user@ubuntu1404:~$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following extra packages will be installed:
  libmcrypt4 php5-cli php5-readline
Suggested packages:
  php-pear libmcrypt-dev mcrypt
The following NEW packages will be installed:
  libapache2-mod-php5 libmcrypt4 php5 php5-cli php5-mcrypt php5-readline
0 upgraded, 6 newly installed, 0 to remove and 176 not upgraded.
Need to get 4,442 kB of archives.
After this operation, 19.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]
The default is Y or Yes so you can just click enter and it will begin installation. As like before if you are still within the windows to use root privileges you will not be prompted for a password. 

Now that we have PHP installed we want to edit the configuration files to tell Apache to use our preferred file index.php. By default the web server will use index.html. 
To do this we need to edit the following file:
  1. sudo vim /etc/apache2/mods-enabled/dir.conf
The contents of that file will look something like this:
<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
Press i to start typing and edit the file to look like it does below:
<IfModule mod_dir.c>
        DirectoryIndex index.php ndex.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Now press ESC then :wq and that will write and save the file. 
Now that we have edited this file we need to tell the Apache web server to read this file again and execute the changes we made. 
To do this run the following command: 
  1. sudo service apache2 restart

Step 4: Testing PHP

Now that we have everything installed for our basic web server. We need to test to make sure PHP is working and being phrased properly. To do that we can create a basic PHP file in our root direct of our website located at /var/www/html/. 
Type the following in the terminal to create the file:
  1. sudo vim /var/www/html/info.php
This will open a blank file and allow us to edit the contents. In this file enter the following information: <
  1. <?php
  2. phpinfo();
  3. ?>
Now you can save and close the file just like we did before press ESC then :wq
Now you can visit your IP address and add /info.php afterwards like this:
  1. http://ip-of-your-server/info.php
You should get a response that looks something like this. 


This info page will give you information about what modules are installed for your PHP instance. To see a list of available modules you can run the following command: 
  1. apt-cache search php5-
You will get an output similar to this: 
php5-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5-cli - command-line interpreter for the php5 scripting language
php5-common - Common files for packages built from the php5 source
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-odbc - ODBC module for php5
php5-pgsql - PostgreSQL module for php5
php5-oauth - OAuth 1.0 consumer and provider extension

This will give you a list of available modules you can install. To install a module you simply run 'sudo apt-get install package-name' 
For instance if you wanted to install php5-oauth you would run the following command: 
  1. sudo apt-get install php5-oauth

Conclusion

Now that we have everything installed and working for our basic web server. It is time for you to get to work to show the world what you can do. This basic setup will allow you to install Wordpress, the most popular content management system. 
We hope this tutorial has helped you. 


    • Related Articles

    • How to install LAMP on Ubuntu 16.04

      LAMP stands for Linux, Apache, MySQL and PHP. This is a group of open source applications commonly used to run a web server for hosting and development. This tutorial will include the steps needed to set up a simple web server to get your website up ...
    • Managing MySQL

      Plesk Shared Hosting: Managing MySQL XMission's Shared Hosting powered by Plesk has phpmyadmin essentially built right into it! From the Control Panel, click on the "Domains & Websites" tab near the top of the screen. On the left, click the button ...
    • Adding MySQL Databases

      Plesk Shared Hosting: Adding MySQL Databases Create and remove databases used by your websites, and manage them using integrated administrative web application. From the Control Panel, click on the "Domains & Websites" tab near the top of the screen. ...
    • Password Protecting a Directory With ".htaccess"

      Introduction This document assumes you have a basic understanding of the UNIX shell. Web access control on XMission is a function of the web server. It lets you set permissions on who can access your web documents based on username/password, a group ...
    • What is Spam?

      What is Spam? Spam is a word adopted by the Internet community to describe mass-message posting via email or Usenet newsgroups. These messages are usually unsolicited and invasive commercial advertising, typically for get-rich-quick scams or to ...