Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have added 2 more IPs and PHP is not working on those domains. Looks bizarre. I must've done something wrong but cannot figure out what.

IPs: 111.111.111.111, 222.222.222.222 and 333.333.333.333
Domains: 1.example.com, 2.example.com, 3.example.com

NSLOOKUP confirms that domains are bind to IPs correctly

OS UBUNTU SERVER 12.04 on Virtual Machine (VPS) with one network interface

ifconfig

eth0 Link encap:Ethernet HWaddr 00:16:3e:0f:2a:4f
inet addr:111.111.111.111 Bcast:111.111.111.255 Mask:255.255.255.0
....

lo Link encap:...

/etc/network/interfaces

auto lo eth0

iface lo inet loopback

iface eth0 inet static
address 111.111.111.111
netmask 255.255.255.0
gateway 111.111.111.1

/etc/rc.local - this is how I have 2 extra IPs added

ip address add 222.222.222.222 dev lo
ip address add 333.333.333.333 dev lo

exit 0

APACHE2 / 2.4.3

/path_to_install_dir/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost 111.111.111.111>
     DocumentRoot "/path/1.example.com/public_html/"
     ServerName 1.example.com
     AddType application/x-httpd-php .php
     ...

<VirtualHost 222.222.222.222>
    DocumentRoot "/path/2.example.com/public_html/"
    ServerName 3.example.com
    AddType application/x-httpd-php .php
    ...

<VirtualHost 333.333.333.333>
    DocumentRoot "/path/3.example.com/public_html/"
    ServerName 3.example.com
    AddType application/x-httpd-php .php
    ...

So now 1.example.com works correctly, 2.example.com and 3.example.com (on additional IPs) - "lost" PHP. I mean they're served by apache, but php is not working! And nothing in error.logs!

Lotsa configs, so thanks for pations, guys.

share|improve this question
    
You should define ports for these vhosts: VirtualHost 111.111.111.111:80 –  David Houde Mar 29 '13 at 14:37

2 Answers 2

You need to add these IP-addresses to eth0, not to the loopback device to make them accessible from the outside. Assuming your VPS-provider did the right thing with the routing, it should work right away.

share|improve this answer
    
Well, provider did mentioned that 'the easiest way' is to do as I show above. The easiest but not the only one. But what I do not understand is why domain_2.com/index.html works fine , but domain_2.com/index.php prints php code instead of executing it! Probably I should read more about how loopback works. –  Vitaly Mar 29 '13 at 14:38

/path_to_install_dir/apache2/conf/extra/httpd-vhosts.conf

Ah. You're not using the Ubuntu-provided apache/php etc. That's asking for trouble, so please get rid of that and install the Ubuntu packages. Always stick to what your distro provides, unless you have a very good reason not to. Php and virtualhosts are configured much nicer in the Ubuntu way of configuring, that'll solve that problem.

Your IP address config is also broken, these addresses should not be on the lo interface. I'm surprised it works (and guessing that it actually doesn't).

share|improve this answer
    
If I do as you say - I will never learn =) –  Vitaly Mar 29 '13 at 14:49
    
That's complete nonsense of course. You can learn a lot by looking at how Ubuntu has configured apache and why that way of configuring is a good idea. All you do now is set yourself up for security breaches, lack of understanding and an apache setup badly integrated with the OS. –  Dennis Kaarsemaker Mar 29 '13 at 14:52
    
Look, I had Ubuntu installed with bind and ssh and nothing else. Then I downloaded latest version of Apache and latest version of PHP. Spend 3 days compiling and installing those and related libraries. And this way I learned much more then I could have if I chose to use apt-get. Don't you agree? –  Vitaly Mar 29 '13 at 15:03
    
No I don't. You've wasted time compiling apache wich you could have spent learning how it works, which is a far more useful piece of knowledge. You now also need to keep doing it to make sure you stay up to date with security patches, which is a waste of time if you can rely on your distro to do this. –  Dennis Kaarsemaker Mar 29 '13 at 15:07
    
About security... you made me think. –  Vitaly Mar 29 '13 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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