I have an empty CentOS 6.3 box. I need to run multiple websites from this server. Things that I have done so far are:

  1. Installed Apache, MySQL, PHP and PHP modules by following this article.
  2. I created a test file index.html inside the /var/www/html/ folder and tried to visit the default site by pointing my browser to the server's IP. But it didn't show anything.
  3. I commented the line "DocumentRoot /var/www/html" inside the httpd.conf file and added Virtualhost settings as:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName abc.com
  DocumentRoot /var/www/vhosts/abc.com
  DirectoryIndex index.php
  <Directory "/var/www/vhosts/abc.com">
    DirectoryIndex index.php
    AllowOverride All
    Allow from All

Note abc.com above is the hostname of my server and I connect to the server as root@abc.com

  1. I created folders /vhosts/abc.com and placed a file index.php in it
  2. I then restarted the server using service httpd restart

Pointing my browser to either the server's IP or abc.com, shows me a "Page cannot be displayed". If I try to check /var/log/httpd/access_log or /var/log/httpd/error_log, it shows me nothing.

UPDATE: My /etc/hosts file is like: localhost.localdomain localhost abc.com

and /etc/sysconfig/network file is:


How do I check where does the problem lie ? What possibly could be wrong here ?

Update2: My iptables file looks like:

-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

After the las line (after COMMIT), I tried to add:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

But a restart of the iptables service throws an error.

  • whats the output of: service httpd status
    – Hex
    Nov 7 '12 at 7:49
  • httpd (pid <pid value>) is running...
    – gentrobot
    Nov 7 '12 at 7:56

You probably need to open port 80 in the iptables firewall

iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

If this works then you need to save the state of the firewall

service iptables save

If this works, as it looks like you're going to use document roots outside the standard /var/www then you should also need to change the SELinux context for the new root so look at this answer for how to do that.

  • Before I try the above solution, once I open the port 80, after that can I have as many websites as I want, in the same manner as explained in the question ? By creating VirtualHost settings ?
    – gentrobot
    Nov 7 '12 at 8:02
  • Using name based virtual hosting it would yes.
    – user9517
    Nov 7 '12 at 8:11
  • I tried to run the above command, but it throws an error saying "-J requires an argument". I also tried to modify the iptables files (updated the question with my steps) but it didn't work.
    – gentrobot
    Nov 7 '12 at 8:16
  • @gentrobot: sorry typo should be -j (lowercase)
    – user9517
    Nov 7 '12 at 8:17
  • Excellent ! It worked for me :) Thanks a lot @lain
    – gentrobot
    Nov 7 '12 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.