Hubertrum
Posts: 29
Joined: Tue May 22, 2012 11:56 am

PHP Apache 101

Mon Mar 11, 2013 2:32 pm

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.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: PHP Apache 101

Mon Mar 11, 2013 2:47 pm

Did you close with ?> :?:

Hubertrum
Posts: 29
Joined: Tue May 22, 2012 11:56 am

Re: PHP Apache 101

Mon Mar 11, 2013 2:53 pm

Yes,

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

<?php
phpinfo();
?>

All 3 lines show as above in Midori

Hubertrum
Posts: 29
Joined: Tue May 22, 2012 11:56 am

Re: PHP Apache 101

Mon Mar 11, 2013 4:49 pm

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?

garyckoch
Posts: 2
Joined: Fri Feb 22, 2013 8:48 pm

Re: PHP Apache 101

Tue Mar 12, 2013 12:32 am

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.

RootShell
Posts: 3
Joined: Fri Mar 22, 2013 10:35 pm
Location: Albufeira / Portugal
Contact: Website

Re: PHP Apache 101

Mon Mar 25, 2013 11:51 pm

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

freakqnc
Posts: 9
Joined: Thu Feb 16, 2012 3:33 am

Re: PHP Apache 101

Fri Apr 19, 2013 5:10 am

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! :)

andrum99
Posts: 843
Joined: Fri Jul 20, 2012 2:41 pm

Re: PHP Apache 101

Fri Apr 19, 2013 9:17 pm

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.

dfreder1
Posts: 12
Joined: Sat Feb 18, 2012 3:06 pm
Location: Sacramento, California

Re: PHP Apache 101

Tue Aug 06, 2013 4:32 am

Thanks andrum99! That worked for me. :D

andrum99
Posts: 843
Joined: Fri Jul 20, 2012 2:41 pm

Re: PHP Apache 101

Tue Aug 06, 2013 8:16 pm

You're welcome!

Andrew.

Return to “Other programming languages”