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, 2014 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? Jan 19, 2014 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, 2016 at 14:13
  • @Godworld What directory? Apache config files are in /etc/apache2/. Apr 19, 2016 at 20:55
  • 1
    Possible duplicate of PHP script not executing on Apache server Apr 20, 2016 at 11:59

5 Answers 5


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. Jan 28, 2016 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, 2016 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, 2014 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, 2015 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. Feb 4, 2016 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)

You must log in to answer this question.

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