10

I've been trying to set up a CentOS server for the first time (ever setting up a Linux server). The installation went fine, I installed LAMPP (and the required dependencies for x86), used the lampp security tool, and went to http://192.168.0.112:8888/ using elinks.

So far so good... But then I wanted to access the server from the other computers in my network (including the host of the VM). But I can't get it to work and keep getting 404's...

Note that I have another webserver running on this network (on port 80), so I changed Listen 80 to Listen 8888 in httpd.conf and forwarded 8888 in my router to the IP from the CentOS installation (static: 192.168.0.112, according to ifconfig).

Ping 192.168.0.112 returns:

Ping statistics for 192.168.0.112:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

Server details:

  • CentOS 6.5 minimal, installed from .iso
  • LAMPP 1.8.1 (via wget from apachefriends.org)

Host details:

  • Windows 8.1 x64
  • VirtualBox is using a Bridged Network Adapter (translated from Dutch: Netwerk bridge adapter)

Any ideas on how to fix this issue? I'm relatively new to networking and server as I'm a front-end developer myself, but I really want to get into back-end stuff.

It's getting really late now, so I'm off to bed. Hopefully I get some good insights in how networking/CentOS works in the morning!

Thanks in advance.

2
  • I am little bit confused by what are you trying to achieve. If your web server is listening to port 8888, have you specified this in elinks while trying to connect? (http://192.168.0.112:8888)
    – VL-80
    Jan 4, 2014 at 1:37
  • I made a few mistakes in my original question, yes. I was trying to connect at http://192.168.0.112:8888. Jan 4, 2014 at 9:34

4 Answers 4

0

More than likely is a virtualhost configuration inside apache. There is a section in there that will say "allow from [something]". Make sure it says "allow from all".

Here is what mine looks like;

<Directory /var/www/>
    Options FollowSymLinks
    AllowOverride AuthConfig FileInfo Limit
    Order allow,deny
    allow from all
</Directory>

My personal opinion is to not use xampp at all. You are actually making things more difficult. Just use the native packages in CentOS. Here is a good tutorial (from a quick google search)

https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6

Or, you can install Ubuntu Server and there is an option during the install phase that you can check to install LAMP. It will download and install all of the packages for you.

Good luck.

6
  • He said he is getting 404 Not found as oppose to 403 Forbidden.
    – VL-80
    Jan 4, 2014 at 1:39
  • Wow, you right, my bad.
    – Linuxx
    Jan 4, 2014 at 1:56
  • You can edit your answer to fix this... Before crowd will start to downvote.
    – VL-80
    Jan 4, 2014 at 1:58
  • Although I wasn't getting a 403 error, the solution of not using LAMPP appeals to me. I've always been using XAMPP on Windows so I decided to find an alternative for unix, but using the native packages sounds way better and I will learn more from it! I have one question though, how secure will this be? I want my webserver to be open tot the internet so I can develop wherever I am. Jan 4, 2014 at 9:39
  • 1
    @CasCornelissen, it could be secure. Although security is absolutely separate subject at this point and I will not touch it in this question. You have few options here. You can use FTPS to upload content and code (PHP? or whatever) to the server. You can use SSHfs as well, but later is Linux specific tool while FTPS can be implemented on platform/OS independent basis.
    – VL-80
    Jan 5, 2014 at 2:42
15

I also had this issue. From your description I was running the same set up as you. It turned out I had firewalld installed and was running and so had to use the commands:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

This then enabled me to access the apache server running on my virtual machine from outside of the vm.

2
  • Thanks! this answered why my Centos 7 VB with Apache 2.4 in a Windows 7 host couldn't work together superuser.com/questions/1120134/… Sep 2, 2016 at 14:47
  • Thanks, thanks, thanks. Four hours debugging and it was this firewall. For me what worked was just stopping the service: systemctl stop firewalld. Maybe because my http server was on port != 80. Thank you again
    – felipeek
    Nov 16, 2018 at 20:08
3

Run the following commands:

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

To make the changes persist, go to /etc/sysconfig/ and add to the following line to iptables:

-A INPUT -i eth1 -p tcp -m tcp --dport 80 -j ACCEPT

Then, restart the webserver:

service httpd restart

And now you can access out of VirtualBox.

1
  • with centOS 6 it took adding the following line to /etc/sysconfig/iptables, in order to unblock the HTTP traffic: -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT (don't forget to restart iptables after you make the change: sudo service iptables restart , didn't need to restart the web server) May 14, 2015 at 12:58
0

It sounds like you forwarded traffic on your router to 192.168.0.112 when really you wanted 192.168.0.112:8888. It would be helpful to know some more about what computers you can and cannot ping the CentOS machine from, how your router is configured to forward ports to it, and what the contents of /etc/httpd/conf/httpd.conf are.

Also, it shouldn't matter that you have another webserver on this network, unless you're routing out to another network that you want to be able to access this webserver and both webservers will have the same external IP.

If this is the case, then say your "external" ip is 10.10.10.10 and the internal IP of this router is 192.168.0.1. Assume your CentOS webserver is at 192.168.0.112 as described, and your other server is at 192.168.0.110 and is hosting a webserver at port 80.

Because you wanted 192.168.0.110 to be able to serve HTTP traffic to devices on 10.10.10.*, you forwarded 10.10.10.10:80 to 192.168.0.110. However, this doesn't mean you have to serve web traffic on port 8888 from 192.168.0.112. Only if you would like to access 192.168.0.112 from devices that need to route through 192.168.0.1 do they need a port besides 80. So in this case, you would keep 192.168.0.112 serving web pages on port 80 and forward traffic inbound from 10.10.10.10:8888 to 192.168.0.112:80.

Finally, the fact that you're getting 404 messages in a browser means you're hitting some kind of webserver:

The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested. (Wikipedia)

2
  • Thanks for the answer! So, as long as it's on my local network I should be ok with two webservers running both on port 80, since the local ip is different? But when connecting from outside of my network it won't work since all computers have the same IP at that point, right? Jan 4, 2014 at 9:36
  • Quite right. Once the traffic goes through your router, everything outside the router only knows the IP of the router. Your internal network is condensed into a single IP from an observer's standpoint.
    – ndt
    Jan 4, 2014 at 16:20

You must log in to answer this question.

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