CentOS 6 Web Server Setup: LAMP Stack Installation Guide

CentOS 6 Web Server Setup: LAMP Stack Installation Guide

Setting Up Your Website: A Beginner's Guide to LAMP on CentOS

The LAMP stack is a group of tools used to set up websites. LAMP stands for Linux, Apache, MySQL and PHP.

  1. Linux: It’s like the foundation of your website. CentOS is already there, serving as the base.
  2. Apache: Think of Apache as a traffic cop for your website. It directs visitors to the right places.
  3. MySQL: MySQL is a storage place for your website’s information. It keeps everything organized.
  4. PHP: PHP is a language that helps your website do things – like showing dynamic content.

Since your server is on CentOS, you just need to add Apache, MySQL, and PHP to make your website work.

Getting Started: Accessing Your Virtual Server

To follow along with this guide, you need special access to your virtual private server. It’s a bit like having a key to your online space. If you’re not sure how to get this key, check out the Initial Server Setup Tutorial for simple instructions.

Step One: Introducing Apache to Your Server

Let’s start by adding Apache to your server. Apache is like a free tool that helps your website be seen by lots of people. To get it, open the terminal and type in this special command:

sudo yum install httpd

After it’s done installing, you can make Apache start working on your online space (VPS):

sudo service httpd start

All done! To see if Apache is set up, just open your internet browser and go to your server’s address (like If everything’s good, a page saying ‘It works!’ should show up, just like that!

Locating Your Server: Finding Its Special Address

Wondering where to find your server’s address? Just use this simple command to uncover it:

ifconfig eth0 | grep inet | awk '{ print $2 }'

Step Two: Bringing in MySQL for Your Website's Data

Next up is MySQL, a powerful system that helps keep your website’s information organized on your online space.

To get MySQL, go to the terminal and type in these special commands

sudo yum install mysql-server sudo service mysqld start

As MySQL installs, it might ask for your permission twice. Just say ‘Yes’ both times, and MySQL will finish setting up.

After the installation is complete, you’ll get to choose a special password for the main access point, kind of like locking the door to your MySQL space:

sudo /usr/bin/mysql_secure_installation

The prompt might ask for a password you don’t have yet, called the ‘root password.’

Since MySQL is brand new, you can just press ‘Enter’ without typing anything to leave it empty.

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

After that, the system will ask if you want to create a password. Choose ‘Y’ for ‘Yes’ and follow what it says.

CentOS makes it easy by asking you simple ‘Yes’ or ‘No’ questions.

Just say ‘Yes’ to everything it asks. When you’re done, MySQL will finish up and put all the new stuff in place

By 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] y ... 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] y ... 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] y - Dropping test database... ... 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!

Step Three: Bringing in PHP for Dynamic Webpages

Now, let’s add PHP, a tool that helps create dynamic webpages, to your online space.

To get PHP, go to the terminal and type in this special command:

sudo yum install php php-mysql

After you say ‘Yes’ to the PHP question, PHP will finish installin

Exploring PHP Tools: Libraries and Modules

PHP comes with extra tools called libraries and modules that can enhance your server. To see what tools are available, just type.

yum search php-

After typing that, the terminal will show you a list of different modules. It will look something like this:

php-bcmath.x86_64 : A module for PHP applications for using the bcmath library php-cli.x86_64 : Command-line interface for PHP php-common.x86_64 : Common files for PHP php-dba.x86_64 : A database abstraction layer module for PHP applications php-devel.x86_64 : Files needed for building PHP extensions php-embedded.x86_64 : PHP library for embedding in applications php-enchant.x86_64 : Human Language and Character Encoding Support php-gd.x86_64 : A module for PHP applications for using the gd graphics library php-imap.x86_64 : A module for PHP applications that use IMAP

If you want to know more about what each tool does, type the following command in the terminal. Just replace the name of the tool with the one you’re curious about.

yum info name of the module

If you’ve chosen a tool you want to add, type the following command:

sudo yum install name of the module

You can add several tools together by typing their names with spaces in between.

Great job! Your online space now has the complete LAMP stack!

To make things even easier, let’s set it up so that everything starts running automatically when your server starts (PHP will start as soon as Apache does):

sudo chkconfig httpd on sudo chkconfig mysqld on

Step Four: Checking PHP on Your Server

Even though LAMP is now installed on your online space, you can still check out its parts by making a simple PHP info page.

To do this, let’s start by creating a new file:

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

Now, let’s add the following line:

<?php phpinfo(); ?>

After adding the line, save your work and close the file.

Now, let’s make sure all the changes apply to your online space. Restart Apache on your server:

sudo service httpd restart

To wrap up, check your PHP info page by opening this link in your browser (remember to use your own server’s IP address instead of the example):


Great job setting up your website base with CentOS 6 and the LAMP stack! You’ve got the essentials – Apache, MySQL, and PHP – ready for dynamic websites.

Ready for more? Explore extra features, keep your server safe and connect with fellow web builders online.

Keep coding and creating on your CentOS 6 server! Happy coding!


A cloud for entire journey

Bring your team together. No contracts, no commitments.


Copyright ©2023 Design & Developed by Cloudtopiaa