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

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


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 *:80>
    DocumentRoot /path/to/vhosts/folder2
    ServerName blog.mydomain.com

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
  • Are you aware that that is a LAMP server? – Braiam Jan 19 '14 at 16:10
  • @Braiam to be honest I'm lost between LAMP and Apache... I don't know the difference... however, you got an answer to my question? – The Quantum Physicist Jan 19 '14 at 16:27
  • where do i find this directory? it does not work for me. please help? how do i reload vhost vie terminal? – God world Apr 19 '16 at 14:13
  • @Godworld What directory? Apache config files are in /etc/apache2/. – The Quantum Physicist Apr 19 '16 at 20:55
  • 1
    Possible duplicate of PHP script not executing on Apache server – Florian Diesch Apr 20 '16 at 11:59

I got it to work with the line:

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

sudo service apache2 restart
  • 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 6 '16 at 16:54

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

  • 5
    I hardly think this can be called a real answer, but I guess it sorta is. – Seth Dec 4 '14 at 5: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 4 '16 at 9:25

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:


Here's the solution:

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

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

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 mod_php5.c>
        php_admin_flag engine on

    (Other configuration parameters)


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


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)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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