LAMP (Apache, MySQL, PhpMyAdmin) Install on CentOS 6

This guide will show you how to install a basic LAMP stack setup on CentOS 6. LAMP stands for Linux, Apache, MySQL, PhpMyAdmin and provides the basic tools needed to host web files on your server. There's also alternative web servers to use such as Nginx, but require additional configuration.

Before we get started lets install nano, which is an easy to use linux text editor, wget which is required to download files, unzip to unzip archives, and then update our currently installed packages. Updating all of the system packages might take some time as it will need to download new updates.
sudo yum install nano -y
sudo yum install wget -y
sudo yum install unzip -y sudo yum update -y

Once nano is installed and you've updated the system packages lets continue and install the Apache web server. The package manager will also install a few other required packages for the web server automatically.
sudo yum install httpd -y

Once Apache is installed lets start the web server.
sudo service httpd start

Now we can install and setup the MySQL server, run the following command to install MySQL.
sudo yum install mysql-server -y
> Sample Output

Start the MySQL server.
sudo service mysqld start

Now we'll ened to run the MySQL server installer script to setup a root MySQL password and change a few settings, depending on your needs or preference.
sudo /usr/bin/mysql_secure_installation
> Sample Output

The MySQL installations script will ask you if you want to set a root password, type Y and press enter then enter a root password for the MySQL server to use. The other steps are to remove anonymous users, disallow root login remotely, remove test database, and to reload the privilege tables for MySQL. By default these are all set to Y (yes).

Once that's done we can install PHP and the MySQL extension along with the mcrypt extension (optional).
sudo yum install php php-mysql php-mcrypt -y
> Sample Output

Once PHP and the modules are installed restart the Apache web server so the changes take affect.
sudo service httpd restart

Now lets set the two server processes to start after bootup, so if your server is rebooted the services will start automatically.
sudo chkconfig mysqld on
sudo chkconfig httpd on

Now a basic LAMP stack is setup on your server, you can navigate to your server IP in your web browser (e.g. http://your_server_ip) to check if it's working properly.

We can download PhpMyAdmin and set it up on your web server now. PhpMyAdmin lets you manage your MySQL database through your web browser remotely and is nice to have if you're not an experiened MySQL user and don't know many commands.

Lets navigate to your Apache web server directory first. By default this is the /var/www/html directory.
cd /var/www/html

Now lets download the latest PhpMyAdmin script. For this we'll be using version 4.2.12.
wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.12/phpMyAdmin-4.2.12-english.zip/download

Unzip the archive that you just downloaded. By default it should save the file as th name 'download' since we didn't specify a differnt output name.
unzip download

After unzipping it will create a folder in the directory called "phpMyAdmin-4.2.12-english", lets rename it to make it eaiser to access, then enter the directory we renamed
mv phpMyAdmin* phpmyadmin
cd phpmyadmin

Before we can use PhpMyAdmin we'll need to rename the configuration file, make sure to edit any options in this if necessary.
mv config.sample.inc.php config.inc.php

Now PhpMyAdmin is setup and you can access it by navigating to your server IP/phpmyadmin (e.g. http://your_server_ip/phpmyadmin).


Everything is ready now!


Additional Tips
1) You may want to disable SELinux, it can cause permission issues with packages and might be a hassle if you're running certain web scripts on your server. Run "setenforce 0" to set SELinux to permissive mode.
2) If you can't connect to your web server, you might have the firewall on the server blocking connections to port 80 which is the default web server port. You can flush (clear) all IPTables rules by running the "iptables -F" command in SSH. You can also run the following commands below to add rules to allow traffic on port 80 (Web), 443 (Mail), and 3306 (MySQL)
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT


If you have any questions you can always send in a technical support ticket and one of our technicians can assist you to the best of their ability.
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

Install VNC Server and Desktop on CentOS 6

By default your server would probably be setup as a headless (server) version, without a desktop...

Installing EPEL Repository for CentOS 5, 6, 7

The EPEL repository is a separate repository which provides many additional software not provided...

Installing cPanel/WHM on CentOS 6

cPanel is a linux based web hosting control panel with a graphical interface for managing web...

LAMP (Apache, MySQL, PhpMyAdmin) Install on Ubuntu 14.04

This guide will show you how to install a basic LAMP stack setup on Ubuntu 14.04. LAMP stands for...

LAMP (Apache, MySQL, PhpMyAdmin) Install on CentOS 7

This guide will show you how to install a basic LAMP stack setup on CentOS 7. LAMP stands for...