Install LAMP Stack on CentOS 6

LAMP stack is an open source solution for building dynamic web sites and web applications. The acronym LAMP is derived from the software used which includes, Linux, Apache, MySQL, and PHP.

In this guide we will install a LAMP Server on CentOS 6. Note: you will need root privileges.


Step 1 – Install Apache

Setting up Apache is pretty quick and straightforward, but before we begin you should update your installation.

sudo yum update

Now go ahead and install Apache with the following command:

sudo yum install httpd

Start the apache service:

sudo service httpd start

To start apache on boot enter the following:

/sbin/chkconfig --levels 235 httpd on 

Configuring Name-Based Virtual Hosts

If you plan on having multiple domains or sites you will need to set up Virtual hosts.

Edit the file /etc/httpd/conf.d/vhost.conf and modify it suiting your needs

NameVirtualHost *:80  <VirtualHost *:80>       ServerAdmin webmaster@example.com      ServerName example.com      ServerAlias www.example.com      DocumentRoot /srv/www/example.com/public_html/      ErrorLog /srv/www/example.com/logs/error.log       CustomLog /srv/www/example.com/logs/access.log combined </VirtualHost>  <VirtualHost *:80>       ServerAdmin webmaster@example.org           ServerName example.org      ServerAlias www.example.org      DocumentRoot /srv/www/example.org/public_html/      ErrorLog /srv/www/example.org/logs/error.log       CustomLog /srv/www/example.org/logs/access.log combined </VirtualHost>

Important lines here are:

ServerAlias www.example.com

DocumentRoot /srv/www/example.com/public_html/

Server alias is the domain name you want to use. DocumentRoot is the location where your site files are stored.

Once you have made your changes you will need to restart your server to apply them.

Service httpd restart


Step 2 – Install MySQL

MySQL is It is used to store data for many popular applications, including Wordpress, Drupal and Joomla.

To install MySQL enter the following in your terminal:

sudo yum install mysql-server

If you wish to have MySQL start on boot enter:

/sbin/chkconfig --levels 235 mysqld on

start the mysql service:

sudo service mysqld start

Once it is done installing, you can set a root MySQL password:

sudo /usr/bin/mysql_secure_installation


Step 3—Install PHP

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.

To be able to develop your websites using PHP, you need to install it.

sudo yum install php php-mysql php-pear


Step 4 - Test PHP on your Server

To test PHP and see various information about your installation e.g memory use, modules installed and log locations you can create a sim[ple php file:

sudo nano /var/www/html/phpinfo.php

Enter the following in the file:

<?php phpinfo(); ?>

You can now visit this file on your server and it will display all the details related to your PHP installation.

 

Thats the end of the tutorial!. Your LAMP Stack is now installed and ready to go!

 



Share this post


Comments