I'm following these instructions exactly: http://wiki.debian.org/LaMp

But my test PHP file, created at:

# nano /var/www/apache2-default/test.php

wants to download in the browser, not display as a PHP file.

2 Answers 2


You can also use the AddHandler and AddType directives in your conf files. There's no need to make files executable when they really don't need to be.

AddHandler php5-script .php
AddType text/html .php
  • Also (possibly) need a Loadmodule directive. Jun 13, 2011 at 22:19

You must tell apache that the file is a cgi script (don't forget to chmod +x it). Usually, apache is set up the think of everything in [wwwdir]/cgi-bin as a script, so just try putting it in there. Otherwise, you'll need something like this in your apache configuration (inside the VirtiualHost section):

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
  • Thanks! chmod a+x fixes the problem, but is this safe?
    – simon
    May 11, 2011 at 18:13
  • Not only safe, but also necessary: For a PHP script to generate any output, it must be executed. It's a program, after all. May 11, 2011 at 20:39
  • @Tobias Plutat you don't need to execute it, @Xeonoactive's answer is correct. Apache recognizes it as a php file, and uses the php embeded in apache. Apache doesn't see as a CGI. Jun 13, 2011 at 22:21
  • Following this method runs your PHP files as CGI scripts. While this is technically functional, it's not as efficient as running them under a PHP5 module. You'll probably notice that not many other sites run PHP as a CGI.
    – Xenoactive
    Jun 20, 2011 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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