15

So I setup my server using this tutorial, and when the test.php file works with no problem when I enter the address using my server's IP as

http://1.2.3.4/test.php

However, if I use virtualhosts, the browser just offers to download the file rather than executing it. So this:

http://blog.mydomain.com/test.php

offers to download the file rather than executing the script.

The code I use in /etc/apache2/apache2.conf for virtual hosts is the following:

Include /etc/phpmyadmin/apache.conf
Include /etc/apache2/mods-available/php5.conf

<VirtualHost *:80>
    DocumentRoot /path/to/vhosts/folder1
    ServerName www.mydomain.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /path/to/vhosts/folder2
    ServerName blog.mydomain.com
</VirtualHost>

NameVirtualHost *:80

Though I have to say that when I restart the apache2 server I get a warning message:

[....] Restarting web server: apache2
[Sun Jan 19 13:33:40 2014] [warn] NameVirtualHost *:80 has no VirtualHosts ... waiting [Sun Jan 19 13:33:41 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
Braiam
  • 67,791
  • 32
  • 179
  • 269

5 Answers5

20

I got it to work with the line:

sudo apt-get install libapache2-mod-php7.0

sudo service apache2 restart
muru
  • 197,895
  • 55
  • 485
  • 740
Alastair Mason
  • 301
  • 2
  • 3
  • Thanks for naming this library. I knew I had to install a library to fix this but did not know the name. – Rahul Prasad Jan 28 '16 at 13:09
  • The libapache2-mod-php7.0 package does not exist in the main Ubuntu repository. Not until 16.04 is released. You should use libapache2-mod-php5 instead. – Dan Apr 06 '16 at 16:54
5

Sometimes even worse things can happen.... I just forgot to install php

Tebe
  • 271
  • 5
    I hardly think this can be called a real answer, but I guess it sorta is. – Seth Dec 04 '14 at 05:36
  • 3
    When you have a reasonable number of machines and it's reasonably late in the evening, this is definitely a valid answer. – Avio Dec 21 '15 at 21:27
  • 1
    A valid answer indeed. I had a problem juggling php5, php5-cli, php5-fpm, and php-whatnot. Apache was just missing the right package. – famousgarkin Feb 04 '16 at 09:25
0

I found the solution here. It turns out I had to enable some modules...


Taken from this Stack Overflow answer by user1075581:

This finally put me on the right path:

http://www.linuxquestions.org/questions/linux-server-73/php-not-working-on-one-vhost-but-works-on-all-others-851093/

Here's the solution:

In the <Directory> section, I included these lines:

<IfModule sapi_apache2.c>
    php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
    php_admin_flag engine on
</IfModule>

Or, a redacted copy/paste of the solution on my server:

<Directory "/var/www/vhosts/A2/httpdocs">
    <IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>

    (Other configuration parameters)

</Directory>
0

I've been searching this for a long time and I just found a solution that works in my case. I had put my file (processorder.php5) in the directory /var/www in a standard ubuntu installation. I thought this was the place that php looked. But for html (or php files which are probably considered the same thing) it looked in /var/www/html, ie the html subdirectory of /var/www.

When I moved my file down a directory it worked. I'm suspicious because I don't think I've seen this documented anywhere

0

permission problems can also lead to get this strange behavior

chmod -R u=rwX,go=rX my_publishing_directory

will get rid of permission problems (644 on files and 755 on directories)