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.

link|improve this question

25% accept rate
feedback

2 Answers

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
link|improve this answer
Also (possibly) need a Loadmodule directive. – Rich Homolka Jun 13 '11 at 22:19
feedback

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
    </Directory>
link|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
feedback

Your Answer

 
or
required, but never shown

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