# Apache PHP problem

## [Mad]Masenko

no matter what I do I can't get apache to process php pages.

I've tried all sorts of versions of apache, php and mod_php and nothing I do seems to be able to get apache to process the php pages.

I setup a apache/php server about 6-8 weeks ago and it pain free, only had to enable the -D php4 in the apache.conf file.

I've tried adding alot of extra processing commands into httpd.conf like:

```
AddHandler php-script .php

AddType application/x-httpd-php php

AddType application/x-httpd-php-source phps

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

AddType application/x-httpd-php-source phps

```

But nothing seems to work. Anyone got it working recently that could shed some light on the situation?

```
mad-reborn / # emerge -pv apache php mod_php

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-www/apache-2.0.54-r1  +apache2 -debug -doc -ldap -mpm-leader -mpm-peruser -mpm-prefork -mpm-threadpool -mpm-worker -no-suexec +ssl -static-modules -threads 0 kB

[ebuild   R   ] dev-php/php-5.0.3-r1  -adabas -bcmath +berkdb -birdstep -bzlib -calendar -cdb -cpdflib +crypt -ctype -curl -curlwrappers -db2 +dba -dbase -dbm -dbmaker -dbx -debug -dio -empress -empress-bcs -esoob -exif -fam -fdftk -filepro -firebird -flatfile -frontbase +ftp +gd -gd-external +gdbm -gmp -hyperwave-api -iconv -imap -informix -ingres -inifile -iodbc +jpeg -kerberos -ldap -libedit -mcve -memlimit -mhash -mime -ming -mnogosearch -msession -msql -mssql +mysql -mysqli +ncurses -nis +nls -oci8 -odbc -oracle7 -ovrimos -pcntl -pcre -pfpro +png -posix -postgres -qdbm +readline -recode -sapdb -sasl +session -sharedext -sharedmem -simplexml -snmp -soap -sockets -solid +spell -spl -sqlite +ssl -sybase -sybase-ct -sysvipc -tidy +tiff -tokenizer +truetype -wddx +xml2 -xmlrpc -xpm -xsl +zlib 0 kB

[ebuild   R   ] dev-php/mod_php-5.0.4  -adabas +apache2 -bcmath +berkdb -birdstep -bzlib -calendar -cdb -cpdflib +crypt -ctype -curl -curlwrappers -db2 +dba -dbase -dbm -dbmaker -dbx -debug -dio -empress -empress-bcs -esoob -exif -fam -fdftk -filepro -flatfile -frontbase +ftp +gd -gd-external +gdbm -gmp -hyperwave-api -iconv -imap -informix -ingres -inifile -interbase -iodbc +jpeg -kerberos -ldap -libedit -mcve -memlimit -mhash -mime -ming -mnogosearch -msession -msql -mssql +mysql -mysqli +ncurses -nis +nls -oci8 -odbc -oracle7 -ovrimos -pcntl -pcre -pfpro +png -posix -postgres -qdbm +readline -recode -sapdb -sasl +session -sharedext -sharedmem -simplexml -snmp -soap -sockets -solid +spell -spl -sqlite +ssl -sybase -sybase-ct -sysvipc -threads -tidy +tiff -tokenizer +truetype -wddx +xml2 -xmlrpc -xpm -xsl +zlib 0 kB

Total size of downloads: 0 kB

mad-reborn / #

```

[edit]When i try to include the module it says its already been loaded... so I'm thinking along the lines of the apache recogizing what files should be processed by php[/edit]

----------

## hds

 *[Mad]Masenko wrote:*   

> 
> 
> I setup a apache/php server about 6-8 weeks ago and it pain free, only had to enable the -D php4 in the apache.conf file.
> 
> 

 

not in apache.conf - but in /etc/conf.d/apache2 !

and then dont forget to run env-update; source /etc/profile

----------

## c4

 *Quote:*   

> 
> 
> I setup a apache/php server about 6-8 weeks ago and it pain free, only had to enable the -D php4 in the apache.conf file.
> 
> [ebuild   R   ] net-www/apache-2.0.54-r1
> ...

 

Regarding /etc/conf.d/apache2 shouldn't your apache start options be set to 

```
APACHE2_OPTS="-D PHP5"
```

 as you are using php5

----------

## hds

sheesh! - he is using mod_php5, right you are  :Wink: 

----------

## [Mad]Masenko

I tried -D PHP5 as well.. still didn't work...

I set it to -D PHP4 as I was trying to get mod_php4 to work before trying mod_php5...

----------

## lusken

I just had the same problem. Fixed it by 

"cp /etc/apache2/modules.d/70_mod_php5.conf /etc/apache2/conf/modules.d/"

This might be a bug, but I really are a total noob on this. 

Now if I just could remember where I did set mysql memlimit to 8MB..

----------

## [Mad]Masenko

I got it working in the end. 

steps:

1) emerge sync

(updates portage tree)

2) nano -w /usr/portage/profiles/package.mask

(tell portage it should use the latest version of php)

and commented out the following lines:

```
# Stuart Herbert <stuart@gentoo.org> (10 Jun 2005)

# Masked until the eclass is finished, and the PECL packages are done

#=dev-php/php-5*

#=dev-php/mod_php-5*

#=dev-php/php-cgi-5*

#=dev-php/phpconfig-5*
```

3) emerge -Du apache php mod_php

(install and/or update php and php dependancies)

4) nano -w /etc/apache/httpd.conf 

```
AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

```

 (Added this to apache configuration to tell apache what files to associate with the php interpreter)

5) /etc/init.d/apache restart

(start or restart latest version and configuration of apache)

now everything works  :Smile:  *hooray*

----------

## iwalmsley

I was running across the same problem.

I too, when I go to /gallery/setup or /gallery All i get is the php code and it does not interept it.

I followed those instructions and I am still having issues, now it opens a window and asks me if I want to save or open the file.

I beleive I have php4 installed, I do not understand why it did not install php5.

Any suggestions?

----------

## [Mad]Masenko

It masked because its still in the experimental phase... as in it might have bugs etc...

edit /etc/conf.d/apache2 and change the line to this:

```
APACHE2_OPTS="-D PHP5"
```

if your using php4, then just change where ever u see php5 to php4

----------

## jonlb

I'm also running into this problem. I've tried everything in this thread to no avail. Whenever I try to load a php page I get a dialog asking it I want to save or open.

I'm currently running: 

apache 2.0.54

php-5.0.4-r1

mod_php-5.0.4

any ideas?

Thanks!

Jon

----------

## homer77

Unfortunately the same with my apache2 and php4 (php_mod) configuration. The same save-dialogue despite it worked some days ago - I don't get it ... Dont know, what may have changed ...

----------

## dadodrake

I have the same problem

----------

## dkmweeks

I recently scratched out a new  web server, with php, using blind defaults, and it's working fine.

What I wanted to do, but didn't since I'm fairly new to Gentoo, is adopt PHP5.  This has been out for a while; I used it on my Red Hat machines without a problems, and it is Object Oriented!

I'd really like to see its adoption.

If you've emerged php, then you have php, and php isn't the problem:

# which php

Make sure you have your php modules loaded and your permission set for the location of your php files.

A good test is to create a page with phpinfo();  If that works then all is well.  If not then I still think you have an apache config issue:

<html>

  <head>

    <title>phpinfo(); Test.</title>

  </head>

  <body>

    <h2>Hello World.  Here's phpinfo()</h2>

<?php

  phpinfo();

?>

    <p>WOW!</p>

  </body>

</html>

<!-- This will show you what you've got in the way of apache/php/sql stuff/... -->

Save that to phpinfo.php and put it into your url.  If php isn't working, apache will merely print out the php code.  Yes, I realize you likely know this.  Me, I don't worry about anything else until I get this to render.

----------

## dadodrake

OK, I'm using apache-2.0.54-r7 and mod_php-4.3.11 (php-4.3.11) in stable x86 branch. Today I recompiled the whole php, because I added the "gd" USE flag. Now If I try to access any php file, the browser is doing anything. I already tried some test phps, but no luck. And I cannot find anything in my logs.

----------

## LLSLIM

 *dadodrake wrote:*   

> OK, I'm using apache-2.0.54-r7 and mod_php-4.3.11 (php-4.3.11) in stable x86 branch. Today I recompiled the whole php, because I added the "gd" USE flag. Now If I try to access any php file, the browser is doing anything. I already tried some test phps, but no luck. And I cannot find anything in my logs.

 

did you add your "gd" use flag using /etc/portage/package.use for defining use flags just to the php package, or in your global use flags in /etc/make.conf?

if you used /etc/portage/package.use, then update php and dependencies to incorporate the new use flag with emerge:

```

root@system # emerge --newuse -u -D php 

```

if you used /etc/make.conf (or the ufed utility), then update your world file with the same flags with emerge:

```

root@system # emerge --newuse -uD php 

```

see the manual pages of emerge and portage for more information.

```

(for using emerge flags)

root@system # man emerge

and

(for using /etc/package.use)

root@system # man portage

```

Hope this helps.

peace,

-Slim.

----------

## dadodrake

I know portage, but thanx (I put gd USE flag into make.conf and did and emerge -Du --newuse world. And it recompiled php and mod_php of course).

Now I recompiling back, without the "gd" flag. But I think there is another problem.

----------

## jonlb

I just tried re-emerging apache and php and mod_php by:

```
emerge -C apache php mod_php
```

and then 

```
emerge -av apache php mod_php
```

after this I made sure that apache was indeed running and I still get the "download or open" dialog box.

Anyone else got any ideas here? This was working up until I updated my system about a week ago and hasn't worked since.

Thanks!

Jon

----------

## dadodrake

I solved it!

It was the hardenedphp USE flag. I had to disable it. I just wanted a safer PHP...

----------

## jonlb

Well, I looked at my use flags and I DON'T have the hardenedphp Use flag set.

here's what I ran to install everything:

```

moses ~ # emerge -av apache php mod_php

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-www/apache-2.0.54-r11  +apache2 -debug -doc -ldap -mpm-leader -mpm-peruser -mpm-prefork -mpm-threadpool -mpm-worker -no-suexec +ssl -static-modules -threads 0 kB

[ebuild   R   ] dev-php/php-5.0.4-r1  -adabas -bcmath -berkdb -birdstep -bzip2 +calendar -cdb -cpdflib +crypt -ctype +curl -curlwrappers -db2 -dba -dbase -dbm -dbmaker -dbx -debug -dio -empress -empress-bcs -esoob -exif +fam -fdftk -filepro -flatfile -frontbase -ftp +gd -gd-external -gdbm -gmp -hardenedphp -hyperwave-api -iconv -imap -informix -ingres -inifile -interbase -iodbc +jpeg -kerberos -ldap -libedit -mcve -memlimit -mhash -mime -ming -mkconfig -mnogosearch -msession -msql -mssql +mysql +mysqli +ncurses -nis +nls -oci8 -odbc -oracle7 -ovrimos -pcntl -pcre -pfpro +png -posix -postgres -qdbm +readline -recode -sapdb -sasl +session -sharedext -sharedmem +simplexml -snmp -soap -sockets -solid +spell -spl -sqlite +ssl -sybase -sybase-ct -sysvipc -threads -tidy +tiff -tokenizer +truetype -wddx +xml2 -xmlrpc -xpm -xsl +zlib 0 kB

[ebuild   R   ] dev-php/mod_php-5.0.4  -adabas +apache2 -bcmath -berkdb -birdstep -bzip2 +calendar -cdb -cpdflib +crypt -ctype +curl -curlwrappers -db2 -dba -dbase -dbm -dbmaker -dbx -debug -dio -empress -empress-bcs -esoob -exif +fam -fdftk -filepro -flatfile -frontbase -ftp +gd -gd-external -gdbm -gmp -hardenedphp -hyperwave-api -iconv -imap -informix -ingres -inifile -interbase -iodbc +jpeg -kerberos -ldap -libedit -mcve -memlimit -mhash -mime -ming -mkconfig -mnogosearch -msession -msql -mssql +mysql +mysqli +ncurses -nis +nls -oci8 -odbc -oracle7 -ovrimos -pcntl -pcre -pfpro +png -posix -postgres -qdbm +readline -recode -sapdb -sasl +session -sharedext -sharedmem +simplexml -snmp -soap -sockets -solid +spell -spl -sqlite +ssl -sybase -sybase-ct -sysvipc -threads -tidy +tiff -tokenizer +truetype -wddx +xml2 -xmlrpc -xpm -xsl +zlib 0 kB

Total size of downloads: 0 kB

Do you want me to merge these packages? [Yes/No]

```

and everything installed fine - it's just that php doesn't seem to work. I can pull regular .html files but  not .php. They simply won't process. anybody have any ideas - either to fix this or where I could possibly get some help?

thanks!

jonlb

----------

## Sheepdogj15

same problem here, and re-merging it without "hardenedphp" fixed the problem. 

bummer though, i'm working on a secured system and really wanted hardenedphp  :Confused: 

----------

## drjimmy42

Same problem here.  No hardening.  If I take the stuff out of 70_mod_php.conf and just dump it into httpd.conf, I just get a warning on startup that php4 is already loaded.  But I still get the download dialog.  No errors in the log about php4 failing on load.  That means that the module is fine but apache is not configured to recognize pages correctly.  Still working on it.

----------

## SQLBoy

I had a wierd problem, ended up being a combination of FireFox and the httpd.conf file from Apache. Basially, the path to include all the files in modules.d was wrong, so I fixed it to point to /etc/apache2/modules.d/*.conf.  Then PHP started working, only for new URLS though.  If I went to a URL that I went to when PHP5 was not being loaded correctly, it would give me the download prompt.  So, after clearing the Firefox cache, everything worked fine.

I was getting pissed though because if I went to http://localhost/index.php I got the download prompt.  If I went to http://localhost the page worked fine. Thats when I knew it was firefox.

----------

## jurrie

It's just ridiculous.. can't get PHP5 to work whatever I do.

I'll manually configure apache and php tomorrow or something. That never failed me.

----------

## PChaos

Uhm, that Firefox Cache idea was good, at least for me.

The wrong include for modules.d was allready fixed days ago.

----------

## frozenJim

Aren't we all just missing the mime type in Apache2 configuration?  /etc/apache2/conf/apache2.conf has no entry at all to tell it what to do with a .php file.

It doesn't seem that either Apache or PHP are broken... just that Apache doesn't care when you call a PHP page.

----------

## frozenJim

GRRRRR.....

The FIRST thing that I did was to uncomment the line in /etc/conf.d/apache2

```
APACHE2_OPTS="-D PHP4"
```

This did not solve the problem so I went on to a million other things - none of which helped. 

I just now went back and looked at my /etc/conf.d/apache2 file and guess what?  The line is commented again after one of the installs!!!  I have no idea how LONG it has been re-commented and thus I have no idea what fixed my php.  But I uncommented it again and my PHP is miraculously working.

Now the one other thing that I did - which didn't help AT THE TIME - was to add the two lines to allow the .php mime type to my /etc/apache2/conf/mime.types file 

```
application/x-httpd-php         php

application/x-httpd-php-source  phps
```

Maybe this is part of my solution.... maybe it is unnecessary.  Who knows?  

Damn I hate this kind of fix.  Don't know what I did right so I have learned nothing (except to keep uncommenting that damn line in /etc/conf.d/apache2). :Embarassed: 

----------

## tlianza

 *frozenJim wrote:*   

> Aren't we all just missing the mime type in Apache2 configuration?  /etc/apache2/conf/apache2.conf has no entry at all to tell it what to do with a .php file.
> 
> It doesn't seem that either Apache or PHP are broken... just that Apache doesn't care when you call a PHP page.

 

I don't think that's the case, at least not in my situation.  Apache checks /etc/apache2/httpd.conf which has the following lines:

```

#

# Extra Modules

#

# We Include extra .conf files from /etc/apache2/modules.d

# This is used to load things like PHP and mod_ssl.

#

Include /etc/apache2/modules.d/*.conf

```

It then uses that to go through 70_mod_php.conf which is in that directory, and you'll see that file is what's supposed to define the mime types.

That's why I'm confused... because it all looks like it should work.

----------

## badgers

I second the problem

is there a howto on what it takes to make this work?

how do I tell if the mod_php  is loaded.

this seems really silly why this doesn't seem to work

PS I have cleared the cache and rebooted.

nothing has seemed to help

PHP4 is what I am using in case it makes a difference

thanks

----------

## kinge48

I am having this same type of issue. When I try to view my wordpress blog, which is php, i am getting a directory listing. Then if I choose to view the index.php manually I am asked if i want to save the file. I have tried everything suggested throughout this thread and nothing has seemed to work. This issue just recntly started after the system working properly for months without issue. Anyone have any more ideas?

----------

## kinge48

 *kinge48 wrote:*   

> I am having this same type of issue. When I try to view my wordpress blog, which is php, i am getting a directory listing. Then if I choose to view the index.php manually I am asked if i want to save the file. I have tried everything suggested throughout this thread and nothing has seemed to work. This issue just recntly started after the system working properly for months without issue. Anyone have any more ideas?

 

I have solved my problem as stated above. What I ended up doing is following [Mad]Masenko's guide from earlier:

 *[Mad]Masenko wrote:*   

> I got it working in the end. 
> 
> steps:
> 
> 1) emerge sync
> ...

 

After I did all that (but with PHP4) it still was not working so i went into /etc/conf.d/apache2 and changed the line that was refered to by a number of people:

```
APACHE2_OPTS="-D PHP4"
```

only mine actually read

```
APACHE2_OPTS="-D DEFAULT_VHOST"
```

so it became

```
APACHE2_OPTS="-D PHP4 DEFAULT_VHOST"
```

When i did this everything stopped working. So after much frustration a friend pointed out that it should be:

```
APACHE2_OPTS="-D DEFAULT_VHOST -D PHP4"
```

It turns out that the -D option is needed for each entry. 

Maybe all of you know this, I didn't so hopefully it helps someone else. 

In any event my stuff is all back up and running now.

----------

## badgers

I don't think that's the case, at least not in my situation.  Apache checks /etc/apache2/httpd.conf which has the following lines:

```

#

# Extra Modules

#

# We Include extra .conf files from /etc/apache2/modules.d

# This is used to load things like PHP and mod_ssl.

#

Include /etc/apache2/modules.d/*.conf

```

It then uses that to go through 70_mod_php.conf which is in that directory, and you'll see that file is what's supposed to define the mime types.

That's why I'm confused... because it all looks like it should work.[/quote]

You fixed it for me!

I copied the contents of 70_mod_php.conf and pasted it into /etc/apache2/httpd.conf right above where it "should" bring in the file and it worked.

I don't really care why it wasn't pulling in that file, but now that I pasted that info in it works just fine.

Thanks

----------

## Christof_Deluca

Just so you know... The issue with the 70_mod_php.conf is solved by chmod it readable...Last edited by Christof_Deluca on Tue Nov 01, 2005 1:09 am; edited 1 time in total

----------

## badgers

thanks, is the permissions on the file something that can be done in the ebuild. It seems this is not an isolated case.

Is the file readable by root? maybe those people who said it worked for them should make sure they don't run apache as root....

----------

## Christof_Deluca

Yes, it is readable by root. But not by apache. I just chmod'd the whole /etc/apache2/modules.d/ directory 777 and it solved my php and ssl problems in one fell swoop.

----------

## vrm-ol

 *Christof_Deluca wrote:*   

> Just so you know... The issue with the 70_mod_php.conf is solved by chmod it readable...

 

In my case there was another issue to be solved ...

The above file was after re-emerging mod_php correctly filed in "/etc/apache2/modules.d". It contained ...

```

<IfDefine PHP4>

        # Load the module first

        <IfModule !sapi_apache2.c>

                LoadModule php4_module    modules/libphp4.so

        </IfModule>

[...]

```

If understand this correctly, this file tells apache to load libphp4.so from the directory /etc/apache2/modules. This was, in my case, a symlink to "../../usr/lib/apache2". In this directory ist no libphp4.so but (amongst other stuff) another directory called "modules", which contained the library.

Changing the symlink to "../../usr/lib/apache2/modules/" made php working. 

One problem remains: PHP4-scripts work fine, but only when I call it via http://localhost/somedir/somescript.php!  When I call the same script via http://localhost/~someuser/somedir/somescript.php the problemk remains.  The 'somdirs' are actually symlinks, so the scripts ist the same. Both locations are readable by apache.  

regards,

vrm

----------

## pacman13

I was having the same problem.  Here's what fixed it for me:

I changed the line in /etc/conf.d/apache2

```
APACHE2_OPTS="-D PHP4 -D DEFAULT_VHOST -D SSL_DEFAULT_VHOST"
```

to

```
APACHE2_OPTS="-D PHP4 -D DEFAULT_VHOST"
```

I haven't completely looked through modules.d/ to figure out what having one/both of the *DEFAULT_VHOST files will do, but that was causing the problem for me.

----------

## TealVeal

I've got a similar problem, apache will parse a *.php file correctly, <?php phpinfo(); ?> results in what it should result in, but placing that line inside a .html file results in a blank page and when I check the source I see <html><?php phpinfo();?></html>

If I do not manually place a load module command in the httpd.conf file *.php files are downloaded by my web browser.  I thought the -D PHP4 option would load the php4 module?

I had this working earlier this week and reformated to make sure I could build it back from scratch, obviously not, heh.

Shouldn't this code in my php conf file load php if I have -D PHP4 set?

```

<IfDefine PHP4>

<IfModule !sapi_apache2.c>

    LoadModule php4_module    modules/libphp4.so

</IfModule>

...

</IfDefine>

```

If I change the APACHE2_OPTS to include -D PHP instead of -D PHP4 and change the IfDefine to be PHP then I am no longer prompted to download phtml files, apache interprets them.  Why is this?  I'm not sure I understand why removing a 4 from two files would do this.

I see nothing in /var/log/apache2/error_log which indicates PHP has a problem loading.

----------

## ExWindowsFan

i found a fix for it here....

https://forums.gentoo.org/viewtopic-t-422629-highlight-php5.html

----------

