Introduction

LAMP is a combination of open-source software stack with an open-source operating system. It is mostly used to provision web servers.

 

In this tutorial we will demonstrate how to install the Apache, MySQL and PHP since the operating system has been previously installed. In this case we are using RHEL/CentOS/Scientific Linux 6.

 

We are assuming you have been logged to the server and have root privileges. We are also passing the "-y" option to the yum install command in order to get every question asked by the installer answered with a YES from us.

 

Install Apache Webserver


Apache is an open-source multi-platform web server. Most of the internet websites are powered by the Apache web server.

 

In terminal, type this command:

 

sudo yum install httpd -y

 

Now, we should start the Apache service and let it start automatically on every reboot, like this:

 

sudo service httpd start
sudo chkconfig httpd on

 

You must open port 80 on your firewall in order to get Apache to serve its content to the web. In this case we use iptables:

 

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

 

Save iptables:

 

sudo service iptables save

 

Restart iptables:

 

sudo service iptables restart

 

Test if Apache is Working:

 

Open your browser and navigate to your server’s IP address (eg. http://12.34.56.789).

 

You should see an Apache 2 Test Page on the browser.

 

How to find your server's IP address?

 

If you are not sure what your server or VPS IP address is, you can run the following command which will display it for you:

 

ifconfig eth0 | grep inet | awk '{ print $2 }'

 

You will have an output like this:

 

addr:12.34.56.789

 

Install MySQL


MySQL is an enterprise class, open-source database. MySQL is one of the top choices for dynamic content web applications. Most content management systems like Wordpress, Drupal and Joomla use MySQL as their default database.

 

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

 

sudo yum install mysql-server -y

 

Start MySQL server and tell it to start on every system reboot.

 

sudo service mysqld start
sudo chkconfig mysqld on

 

Set MySQL root password and initial configuration, by typing:

 

sudo /usr/bin/mysql_secure_installation

 

First of all, it will ask you for the current password, which will be none so leave it blank and press enter.

 

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

 

After that the prompt will ask you if you want to set a root password. Choose "Y" and follow the instructions.

 

Now you should answer a series of questions. Say YES to all of them:

 

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

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

Thanks for using MySQL!

 

Now, MySQL is installed and ready to use on your system.

 

Install PHP


PHP is a open-source scripting language. It is one of the most used scripting languages for open-sourced web development and can be embedded in HTML.

 

To install, type the following command:

 

sudo yum install php php-mysql -y

 

If there is an additional PHP module you'd like to install, look for it with the following command:

 

sudo yum search php-

 

You will get an output like this:

 

php-pear-HTTP-Client.noarch : Easy way to perform multiple HTTP requests and process their
                            : results
php-pear-HTTP-OAuth.noarch : Implementation of the OAuth spec
php-pear-HTTP-Request.noarch : Provides an easy way to perform HTTP requests
php-pear-HTTP-Request2.noarch : Provides an easy way to perform HTTP requests
php-pear-HTTP-Upload.noarch : Secure managment of files submitted via HTML Forms
php-pear-Image-Canvas.noarch : Common interface to image drawing
php-pear-Image-Color.noarch : Manage and handles color data and conversions

 

Once you have defined the modules you need, install it by typing:

 

sudo yum install name_of_module -y

 

Test PHP:


You can create a sample file like info.php in the Apache document root folder.

 

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

 

Append the following lines:

 

<?php
phpinfo();
?>

 

Save and exit.

 

Restart Apache service:

 

sudo service httpd restart

 

Navigate to http://your-server-ip-address/info.php and you should see a page with all the PHP details.

 

Install phpMyAdmin (optional)


phpMyAdmin is an excellent and free open-source web interface panel used to manage your MySQL databases. You need to add EPEL repository in order to get phpMyAdmin package installer.

 

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm

 

Now list out the installed repositories with the following command:

 

sudo yum repolist

 

You will get something like this:

 

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * Webmin: download.webmin.com
 * base: mirror.symnds.com
 * epel: www.gtlib.gatech.edu
 * extras: mirror.wiredtree.com
 * updates: mirror.umd.edu
repo id         repo name                                                                status
Webmin          Webmin Distribution Neutral                                                 175
base            CentOS-6 - Base                                                           6,367
epel            Extra Packages for Enterprise Linux 6 - x86_64                           10,685
extras          CentOS-6 - Extras                                                            14
poptop-stable   PoPToP stable repository for Red Hat Enterprise Linux 6 (x86_64)              5
pptp-stable     PPTP Client stable repository for Red Hat Enterprise Linux 6 (x86_64)        24
updates         CentOS-6 - Updates                                                          775
repolist: 18,045

 

Notice there is an "epel" repo id? It means the EPEL repository is now installed.

 

Now you can install phpMyAmdin as usual:

 

sudo yum install phpmyadmin -y

 

Configure phpMyAdmin:

 

Edit the phpmyadmin.conf by typing:

 

sudo vi /etc/httpd/conf.d/phpMyAdmin.conf

 

Find and replace all the 127.0.0.1 IP references to your safe, static IP address in order to access phpMyAdmin from the open internet. Be sure to use a secure IP from your home or office computer.

 

Save and Exit the file.

 

Now restart Apache service:

 

sudo service httpd restart

 

Now you should have access to the phpmyadmin web interface by entering your server's IP address in the address bar of your browser like this:

 

http://your-server-ip-address/phpmyadmin

 

To access phpMyAdmin enter your root MySQL username and password.

 

You're all set! LAMP stack is installed on your VPS.

 

Test on a Miami VPS Now

or

Deploy on a Miami Dedicated Server

Was this answer helpful? 3 Users Found This Useful (7 Votes)