How to install LAMP on CentOS 6


LAMP is an acronym for Linux, Apache, MySQL, and PHP. All of these components together allow obtaining a full web-server. Each of them is responsible for a certain component of web-hosting.


All server settings are to be carried out with root privileges. To do this, run the command:

sudo su -

In the beginning, create a user under which we will work with site files. To do this, run the command:

useradd -m username

This command will also create a home directory in /home/username. Website catalogues of the server will be stored inside the user's home directory.

For your convenience, the root directory of each site will be called by its name. Create a root directory for our future site. After that, make our user the owner of the directory.

mkdir /home/username/
chown -R username:username /home/username/

Installing Apache

yum install httpd

Next, we set up the automatic loading at startup for the Apache server using chkconfig:

chkconfig httpd on

run Apache:

service httpd start
Starting httpd: [OK]

Configuring Apache

Basic settings

At this stage, it is necessary to make some changes in the Apache configuration files.

To do this, you will need a text editor such as nano. To install it, run the command

yum install nano

Let's start with the main Apache configuration file:

nano /etc/httpd/conf/httpd.conf

Find the following construction and leave a comment:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied

Insert the following construction below:

<Directory /home/username/>
AllowOverride All

This will allow the server to work with the catalogue /home/username/ and support .htaccess.

Adding a website

The most popular method is creating a virtual host file in the conf.d/ directory. The advantage is that the catalogue already exists, and the file httpd.conf contains the following line:

Include conf.d/*.conf

These instructions include all files with the ".conf" extension in the conf.d / directory. It means that any files in this directory that have the ".conf" extension will be treated as Apache configuration files. The files are processed in alphabetical order.

Run the command:

nano /etc/httpd/conf.d/

Example of a filled virtual host file

<VirtualHost Server-IP:80>
  DocumentRoot /home/username/
  • Server-IP – is the IP address of your server.

  • ServerName - the name of the virtual host must be set to the fully qualified domain name (FQDN), in our case determines which domain name serves this virtual host.

  • ServerAdmin - contact e-mail address of the domain administrator is included in the reports on the web server errors. It is recommended to have a separate mailbox for this purpose.

  • ServerAlias - alias hostname, the value is obligatory, so that your site would work with both www, and without.

  • DocumentRoot - the root folder of the virtual host. Specify the directory of the site placement / home / username /

After connecting a website, make sure that no mistakes have been made, and configuration files do not contain errors:

service httpd configtest
Syntax OK

After that, restart Apache to apply changes:

service httpd restart

Checking performance 

Put a PHP script in the root directory:

echo "It works !" ;

Set the correct script rights with help of chmod chown

Open your website in a browser. If your domain is not directed to the IP address of the server, you can always add a line:


- Server-IP is the IP address of your server.

To the file hosts on your computer that you use for settings. In Windows, it is usually located in C:\Windows\System32\drivers\etc\, and in nix systems it’s located in /etc/

MySQL Installation

When installing the MySQL database server, according to the specified dependencies perl-DBI, perl-DBD-MySQL, mysql, and mysql-server will be installed as well.


yum install mysql-server

Set MySQL to run automatically when the system launches:

chkconfig mysqld on

Run MySQL:

service mysqld start

Setting up MySQL

By default, after installation, we can connect to our database server under the root without entering the password. Therefore, we assign a password and make a few more settings by running the script:


This script (if you answer yes to all the questions) will set a new root password, remove anonymous users, prohibit connection from remote machines as root, and remove the test database. Please note that the root MySQL password should be stored in a safe place.

You can connect using a MySQL client:

mysql -u root -p

PHP Installation

yum install php

Installing a MySQL module for PHP:

yum install php-mysql

Basic installation includes a set of standard PHP modules. To see the list of available modules, run the command:

php -m

Installing extra modules (if you need them):

yum install php-common php-mbstring php-mcrypt php-devel php-xml php-gd

Adding a remi repository 

If the repositories that are specified in the system are missing some packages, add a remi repository:

sudo rpm -Uvh remi-release-6*.rpm

Remi repository will be turned off by default, but the packages can be installed using '--enablerepo=remi' for example:

sudo yum --enablerepo=remi install php-xml

It can also be activated in the file /etc/yum.repos.d/remi.repo

sudo nano /etc/yum.repos.d/remi.repo

Change enabled=0 to enabled=1

name=Les RPM de remi pour Enterprise Linux $releasever - $basearch


Suggested Articles

  • Linux administration

    How to install Munin on Ubuntu and CentOS

  • Linux administration

    How to install Zabbix on CentOS 6.8 and Ubuntu 12.04