0

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
  </Directory>
</VirtualHost>

Note abc.com above is the hostname of my server and I connect to the server as [email protected]

  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:

127.0.0.1 localhost.localdomain localhost
108.175.9.103 abc.com

and /etc/sysconfig/network file is:

NETWORKING=yes
HOSTNAME=localhost.localdomain

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

Update2: My iptables file looks like:

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-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
COMMIT

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.

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

1 Answer 1

3

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.

8
  • 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, 2012 at 8:02
  • Using name based virtual hosting it would yes.
    – user9517
    Nov 7, 2012 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, 2012 at 8:16
  • @gentrobot: sorry typo should be -j (lowercase)
    – user9517
    Nov 7, 2012 at 8:17
  • Excellent ! It worked for me :) Thanks a lot @lain
    – gentrobot
    Nov 7, 2012 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .