Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm following these instructions exactly:

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.

share|improve this question

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
share|improve this answer
Also (possibly) need a Loadmodule directive. – Rich Homolka Jun 13 '11 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
share|improve this answer
Thanks! chmod a+x fixes the problem, but is this safe? – simon May 11 '11 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. – Tobias Plutat May 11 '11 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. – Rich Homolka Jun 13 '11 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 '11 at 2:52

You must log in to answer this question.

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