How to install LAMP (Linux, Apache, MySQL, PHP) on CentOS

This tutorial is a step by step guide to installing MySQL and PHP-enabled Apache webserver on CentOS.

Before getting started make sure your server is up to date:

yum update
Now we can proceed to install LAMP components starting with Apache.

Installing and configuring Apache

To install the last version of Apache run:

yum install httpd httpd-devel mod_ssl

Creating the virtual host config:

vi /etc/httpd/conf.d/vhost.conf

In our example, the IP is 111.222.333.444 and the domain is
NameVirtualHost 111.222.333.444:80

<VirtualHost 111.222.333.444:80>
DocumentRoot /var/www/
ErrorLog /var/www/
CustomLog /var/www/ combined

To create webwebsite directory run:

mkdir -p /var/www/{html,logs}

You can create an example page to make sure it's working:

echo 'example page' > /var/www/

To make Apache start on boot run:

chkconfig --levels 235 httpd on

Start Apache:

/etc/init.d/httpd start

Navigate to your IP in browser. You should see the "example page" created earlier.

Installing MySQL

To install MySQL run:

yum install mysql mysql-server mysql-devel

To start MySQL on system boot run:

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

For secure mysql installation run:

This will walk you through setting MySQL root password, removing anonymous users, disabling remote root access, and removes the test database.

Installing PHP

To install PHP5, Apache PHP5 module and some basic php packages, including MySQL support, run:

yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel

Restart Apache:

/etc/init.d/httpd restart

To test php, add a phpinfo page

echo '<?php phpinfo();' > /var/www/

Navigate http://111.222.333.444/phpinfo.php in a browser, you should get to the phpinfo page. After checking if it works fine, delete this page.

Now we have all LAMP components installed and working.

  1. Albert
    2014-08-13 21:33:09

Got a comment?

captcha =


  1. System (20)
    1. FreeBSD (5)
    2. Linux (9)
  2. Email (2)
  3. DNS (2)
  4. Databases (1)
  5. WebServer (27)
Copyright © 2012-2015 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.