How To Install Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04 Linux server

15 October 2015, Thursday 0 Comments

About LAMP

LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest.


Set Up

The steps in this tutorial require the user on the virtual private server to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.


1. Install Apache

Apache is a free open source software which runs over 50% of the world's web servers.

To install apache, open terminal and type in this command:

sudo apt-get update
sudo apt-get install apache2

That's it. To check if Apache is installed, direct your browser to your server's IP address (eg. http://12.34.56.789). The page should display the words “It works!" like this.

You can find your server's IP address from "Servers" page:



If you see this page, then your web server is now correctly installed.





2. Install MySQL

MySQL is a powerful database management system used for organizing and retrieving data on a virtual server

To install MySQL, open terminal and type in these commands:

sudo apt-get install mysql-server php5-mysql

During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install.

Once it is done installing, you can set a root MySQL password:

sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password.

Since you just installed MySQL, you most likely won't have one, so leave it blank by pressing enter.

Enter current password for root (enter for none): 

Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

Ubuntu automates the process of setting up MySQL, asking you a series of yes or no questions.


3. Install PHP

PHP is an open source web scripting language that is widely used to build dynamic webpages.

To install PHP on your virtual private server, open terminal and type in this command:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Once you answer yes to the PHP prompt, PHP will be installed.

PHP Modules

PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:

apt-cache search php5-

Terminal then will display the list of possible modules. The beginning looks like this:

php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Human Language and Character Encoding Support
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP

To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.

apt-cache show package_name

Once you decide to install the module, type:

sudo apt-get install package1 package2 ...

You can install multiple libraries at once by separating the name of each module with a space.


4. See PHP on your Server

Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

sudo nano /var/www/html/info.php

Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Restart apache so that all of the changes take effect on your virtual server:

sudo service apache2 restart

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php




Congratulations! Your LAMP setup has been completed.


Share this


Comments