Knowing how to install LAMP stack on Centos 6 is a fundamental step of setting up your new Centos server. This tutorial will detail the steps involved from start to finish, including full installation guides for setting up Linux, Apache, MySQL and PHP.

This tutorial will utilise the command line for quick and efficient installation, so you should be familiar using SSH and have full root access to your Centos server.

To begin with you should own or have access to a Linux server. Companies such as Ramnode provide competitive VPS solutions, but if you are not based near their server locations you should look for a company who are closer to you.

Tutorial Details

Installation Difficulty: Medium

Installation Time: 20 Minutes

How to install Apache on Centos 6

Firstly, we need to install Apache onto our Centos 6 server. Your server should be a fresh installation to avoid conflictions and errors during this installation.

To install Apache, run the following command in your SSH client.

sudo yum install httpd

When Apache has finished installing and you see that it has been successful, start the Apache service.

sudo service httpd start

How to install MySQL on Centos 6

Secondly, we need to be able to create databases for our websites so we must install MySQL.

sudo yum install mysql-server

Lets start our MySQL server now.

service mysqld start

MySQL requires us to create a root password, so we must launch the installation script which is automatically provided when installing MySQL.

sudo /usr/bin/mysql_secure_installation

You will be prompted to create a root password, but you also have the option of leaving it unset.

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

Finally, MySQL will ask for some setup information and upon finishing this section, you will have successfully install MySQL.

y 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]                                            
 ... 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]
... 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]
 ... 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!

How to install PHP on Centos 6

Next up on our road to install LAMP stack on Centos 6 is PHP.

Install PHP and the PHP MySQL extension.

sudo yum install php php-mysql

To test that PHP has been successfully installed, we can create a PHP file and visit it in our browser.

touch /var/www/html/index.php
vim /var/www/html/index.php

In this file we can just show our PHP information.

<?php phpinfo(); ?>

Visiting your servers homepage should now show the PHP info page, which indicates a successful installation.

Conclusion

To sum up, we have learnt how to install LAMP stack on Centos 6, which has prepared our server to host websites. Visit our Linux tutorials for more tutorials and inspiration on where to take your server next.