How to setup a web server on CentOS 6.4

Earlier this week we talked about Linux CentOS version 6.4 distribution.  The article was about how to install CentOS 6.4 on a new computer or spare hard drive, including step-by-step screenshots.  Today, following this, we will show you how to setup a development web server for your CentOS 6.4 installation, including database software MySQL, web server Apache and PHP language.


– CentOS 6.4 installation.  See our guide here.

How to setup CentOS 6.4 Web Server

1. Open a terminal session.  Right anywhere on your desktop and select ‘Open in Terminal’.

CentOS Open in Terminal

2. Login as ‘root’ using following command : su

3. Create a custom user (command : useradd username) for the web server, in our example we chose : webuser

CentOS User Add Web

4. Verify that user has been created.  Type the following command : cat /etc/passwd | grep webuser

Verify User Creation CentOS

5. Change webuser’s password using the following command : passwd webuser

CentOS Change User Password

6.  Add webuser to the sudoer list (root privileges).  Type the following command : visudo. Add the following : webuser  ALL=(ALL) ALL

Visudo Add User CentOS

7. If you intend to run it as a production server you will need to configure iptables to accept http connection.  In our case we deactivate it, since it’s a development server.  Type the following 2 commands to do so :  service iptables stop && chkconfig iptables off

Deactivate iptables CentOS

8.  Update and confirm your packages using : yum update

CentOS Yum Update

CentOS Update Packages Part 2

9. Install web server packages.  This will include web server (apache), database server (mysql), php language and php connection to database module.  To do so, type the following command : yum install httpd php mysql-server php-mysql

CentOS Install Web Server with YUM

Yum WebServer Install

10. Type the following commands to configure and set permissions to your web server :

chown apache:apache /var/www/html/ -R

chcon -R -u system_u -t httpd_sys_content_t -r object_r /var/www/html/

CentOS WebServer Chown and Chcon commands

11. Next step is to start web server and database server (MySQL). To do so, please type the following command :

service httpd start && service mysqld start

CentOS Start httpd and mysqld

12. Edit index.html webpage to test your web server.  You can edit it using the following command : nano /var/www/html/index.html

WebServer CentOS Index.html edit

13. Test your webserver  by browsing local ip address :

CentOS Webserver Running Hello Word


Installing a clean and stable web server with database on CentOS 6.4 is as easy as pie.  Only need a few minutes of your time and you can start develop php code.  Stay tune, we will show you soon how to install wordpress.

Spread the love...Share on FacebookShare on Google+Pin on PinterestShare on RedditTweet about this on TwitterEmail this to someone