Apache2 server cant not run .php file!

hello guys, i’m new here. need some help regarding php and apache2. recently i’ve installed apache2 and php5. After installation, the server can succesfully run .html files only. (http://localhost/~myname/). but when i tried to open .php files. it’ll ask me to save/open it. why is that happening?

Try adding php5 to APACHE_MODULES in /etc/sysconfig/apache2 and restarting apache

most common cause of this problem is skipping the ‘restart apache’ portion of this instruction :wink:

… yup, right up there alongside not knowing about Mysql’s FLUSH PRIVILEGES … :slight_smile:

i tried already…still the same…

that’s what i thought at the first time, i restarted few times already but still the same.

Did you complile PHP / Apache from source? If so what ./configure arguments did you use?

when i compile from /var/www it works but when i compile from folder which i created in desktop it cant run.

first, do you have in your config file something like:


LoadModule php5_module "/php/path/module"
AddType application/x-httpd-php .php
PHPIniDir "/php/ini/path"

?

If yes, restart and check the Apache log.

Second, try

-t -D DUMP_MODULES

to check if PHP is there.

\

i’ve uploaded a picture showing the .php files can’t run when it is clicked. please give your comment.

Do you mean placing the php file in /var/www/ allows it to execute but placing it in /~myfolder/ does not?

If so, you need to configure /~myfolder/ as a virtual directory allowed to execute php.

Look for

    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>

In your php5.conf (located in /etc/apache2/mods-enabled/)

Try changing Off to On and restart apache.

yes,thank you for understanding my problem…i don’t really know how to explain at first…anyway, i tried to change php_admin_value engine to On but still it can’t execute .php file…i’ve uploaded a picture regarding the problem…please take a look…for .php file, the symbol is question mark…but for .html file, it’s different.

Can you post the contents of your php5.conf? I’d like to see it, as maybe I’m missing something obvious that someone else would catch. But I think that file is what we need to be focusing on right now.

As for the ? icon, don’t worry about that, that is apache stating, it doesn’t have an icon for the php extension (my setup shows that too, and I can execute php files just fine).

this is my php5.conf content

<IfModule mod_php5.c>
<FilesMatch “\.ph(p3?|tml)$”>
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch “\.phps$”>
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule …> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>

i’ve turn the php_admin_value engine off as it didnt work just now…

So I suck at reading :stuck_out_tongue:

The file clearly states to comment out the entire <IfModule> block not set it to On. sigh

Make your file look like the one below:

<IfModule mod_php5.c>
    <FilesMatch "\\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    #<IfModule mod_userdir.c>
    #    <Directory /home/*/public_html>
    #        php_admin_value engine Off
    #    </Directory>
    #</IfModule>
</IfModule>

Then restart apache.

OMG,it works! haha,thanks dude. ^^,

i’m having another problem where even when i execute http://localhost/~myname/ i get the page “IT WORKS”. i didn’t see my files anymore. why is that happening? but when i execute http://localhost/~myname/test.php i can see the result. means the file is still there,but i just can’t see it.

this is what i’m talking about…it keeps come out this page…what happen?

Hmm… Do you have any files named “.htaccess index.html index.cgi index.pl index.php index.xhtml index.htm” in your folder? From what I can tell, the default setup should permit directory listings