1. Home
  2. Installing LAMP stack on CentOS 6

Installing LAMP stack on CentOS 6

 What is LAMP stack?

LAMP stack is a combination of operating system and open source softwares stack which are significant in setting up a server initially. The acronym stands for Linux, Apache HTTP server, MySQL/MariaDB and PHP/Perl/Python. This article will guide you through the steps involved in installing Apache HTTP server, MySQL and PHP on your server assuming that the Operating system CentOS 6 is already installed in it.

Prerequisite

Prior to following this article, you must have non root user account set up on your server.

Installing Apache HTTP server

Apache or Apache HTTP is the most commonly used web server around the world accounting for more than 50% of the market share currently. To install apache follow the steps below:

Step 1: Use the following commands in the terminal

sudo yum update

After the update process is finished, install Apache HTTP server using the command.

sudo yum install httpd

You will receive an authentication message, accept it by entering Y and continue with the installation. Then start your web server installed on the VPS by running the command

sudo service httpd start

Step 2: Verify the installation by entering the following URL on your web browser.

http://server_ip_address/

If the web server has been installed properly, your web browser will direct you to the web page that looks similar to the following:

Installing MySQL

MySQL is a database management system software which is used to handle, store and retrieve databases in DB servers. To install MySQL, follow the steps below:

Step 1: Enter the command in the terminal

sudo yum install mysql-server

While the installation is in process you will be asked for permission, enter y and continue the installation. When the installation is finished successfully you can start mysql.

sudo service mysqld start

Step 2: Run the following command to address several security issues with the default MySQL installation.

sudo /usr/bin/mysql_secure_installation

You will be asked to enter root password, since you jut installed MySQL you wont be having any root password. So press enter and continue.

You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost and remove test databases. It is recommended that you answer yes to these options and move on with the process.

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

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


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!

Installing PHP

PHP is a scripting language used in web designing to build dynamic web pages.

Step 1: Use the following command in the terminal

sudo yum install php php-mysql

You will receive a prompt message, enter y and finish the installation.

Step 2: Lots of additional PHP modules are available that can be installed easily. Eventhough this is an optional step, if you want to install additional modules follow the steps below.

To check the available modules, enter the command in the terminal

yum search php-
Output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.fibergrid.in
 * extras: mirror.fibergrid.in
 * updates: mirror.fibergrid.in
========================================================================== N/S Matched: php- ===========================================================================
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-fpm.x86_64 : PHP FastCGI Process Manager
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
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pdo.x86_64 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pecl-apc.x86_64 : APC caches and optimizes PHP intermediate code
php-pecl-apc-devel.i686 : APC developer files (header)
php-pecl-apc-devel.x86_64 : APC developer files (header)
php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon
php-pgsql.x86_64 : A PostgreSQL database module for PHP
php-process.x86_64 : Modules for PHP script using system process interfaces
php-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php-recode.x86_64 : A module for PHP applications for using the recode library
php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-tidy.x86_64 : Standard PHP module provides tidy library support
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php-zts.x86_64 : Thread-safe PHP interpreter for use with the Apache HTTP Server

  Name and summary matches only, use "search all" for everything.

To know the details of the package or module type the following

yum info module-name

In place of module-name, enter the name of the corresponding module. For example,

yum info php-bcmath

To install that package, type the following

sudo yum install php-bcmath

You can install multiple php packages according to your requirements.

We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):

sudo chkconfig httpd on
sudo chkconfig mysqld on

Step 3: To verify if php is installed properly into your VPS, create a file by using the command below

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

Press the key I to edit the file, enter the following content in the file and then save and exit by pressing ESC key followed by :wq! then hit Enter.

<?php
phpinfo();
?>

Restarting web server

The final step in installing the LAMP stack on CentOS 6 is to restart the Apacheweb server . This is done in order for the web server to recognize the changes done to the server.

sudo service httpd restart

This will restart the server immediately and there you go. You have now installed LAMP stack on your server running on CentOS 6.

You can check the installation of php by entering the following URL in your web browser.

http://server_ip_address/info.php

.

Updated on December 20, 2016

Was this article helpful?

Add A Comment