Page 1 of 1

PHP Apache 101

Posted: Mon Mar 11, 2013 2:32 pm
by Hubertrum
I have just loaded Apache2, mySQL and PHP. I cannot get Apache to recognise my index.php file. It just displays it as raw text. Any ideas what I need to change? It's odd as a hello.php which has php imbedded in html does work. But an index.php with first line of <?php doesn't.

Re: PHP Apache 101

Posted: Mon Mar 11, 2013 2:47 pm
by poing
Did you close with ?> :?:

Re: PHP Apache 101

Posted: Mon Mar 11, 2013 2:53 pm
by Hubertrum
Yes,

I have reduced it to 3 lines in a file called index2.php

<?php
phpinfo();
?>

All 3 lines show as above in Midori

Re: PHP Apache 101

Posted: Mon Mar 11, 2013 4:49 pm
by Hubertrum
Looking at my error logs there's an error for
File does not exits: /var/www/favicon.ico

Is this what's causing my problem? If so how do I get around it?

Re: PHP Apache 101

Posted: Tue Mar 12, 2013 12:32 am
by garyckoch
Does your Apache config have a LoadModule statement to pull in php5 support? You can verify that the module is being loaded with:

Code: Select all

 apachectl -M | grep php
You will also need a section similar to this:

Code: Select all

                DirectoryIndex index.php index.html
                <FilesMatch "\.php$">
                        SetHandler application/x-httpd-php
                </FilesMatch>
                <FilesMatch "\.phps$">
                        SetHandler application/x-httpd-php-source
                </FilesMatch>
to have php files properly handled. My pi is running Arch. The DirectoryIndex block was provided in /etc/httpd/conf/extras. I needed to modify /etc/httpd/conf/httpd.conf to load the module (LoadModule php5_module modules/libphp5.so) and include the file from extras (Include conf/extra/php5_module.conf). Once I restarted Apache, index.php was properly parsed.

Re: PHP Apache 101

Posted: Mon Mar 25, 2013 11:51 pm
by RootShell
Open your Apache configuration file httpd.conf

Code: Select all

# vi httpd.conf
Find out line that read as follows:

Code: Select all

DirectoryIndex
Now set it as per your requirements:

Code: Select all

DirectoryIndex index.html index.htm default.htm index.php index.pl
Save and close the file. Restart the Apache web server:

Code: Select all

# /etc/init.d/httpd restart

Re: PHP Apache 101

Posted: Fri Apr 19, 2013 5:10 am
by freakqnc
I added to the configuration file the following lines:

Code: Select all

<Directory />
    DirectoryIndex index.php index.html
</Directory>

<FilesMatch "\.php$">
        SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
</FilesMatch>
In my apache2.conf and still get safari and opera trying to download the php file instead of interpreting and displaying it in the browser as they should :(

Tryed adding also :

Code: Select all

AddType application/x-httpd-php .php .php5
and that changed zilch... so what's the magic here to have apache pass the file to the PHP interpreter so that could be finally rendered by the browser as it should?

Thanks! :)

Re: PHP Apache 101

Posted: Fri Apr 19, 2013 9:17 pm
by andrum99
Hubertrum wrote:I have just loaded Apache2, mySQL and PHP. I cannot get Apache to recognise my index.php file. It just displays it as raw text. Any ideas what I need to change? It's odd as a hello.php which has php imbedded in html does work. But an index.php with first line of <?php doesn't.
Did you install the libapache2-mod-php5 package? Assuming you are using Raspbian, you would need to do this:

sudo apt-get update
sudo apt-get install libapache2-mod-php5

This is obviously as well as installing the apache2 and php5 packages, which I assume you have already installed. After installing libapaceh2-mod-php5, apache2 will be automatically configured to use the php5 module.

Cheers

Andrew.

Re: PHP Apache 101

Posted: Tue Aug 06, 2013 4:32 am
by dfreder1
Thanks andrum99! That worked for me. :D

Re: PHP Apache 101

Posted: Tue Aug 06, 2013 8:16 pm
by andrum99
You're welcome!

Andrew.