# PHP not working with apache

## HitMaker

I am unable to make it work. Php files just show code, pure code  :Sad: 

I have the apache2 flag enabled:

 *Quote:*   

> dev-lang/php-5.2.14 was built with the following:
> 
> USE="apache2 berkdb bzip2 cli crypt ctype exif filter gd gdbm hash iconv ipv6 json ldap (multilib) mysqli ncurses nls pcre posix readline reflection session simplexml spell spl ssl tokenizer truetype unicode xml xmlreader xmlwriter zlib (-adabas) -bcmath (-birdstep) -calendar -cdb -cgi -cjk -concurrentmodphp -curl -curlwrappers -db2 -dbase (-dbmaker) -debug -discard-path -doc -embed (-empress) (-empress-bcs) (-esoob) (-fdftk) (-firebird) -flatfile -force-cgi-redirect (-frontbase) -ftp -gd-external -gmp -imap -inifile -interbase -iodbc -kerberos -kolab -ldap-sasl -libedit -mcve -mhash -msql -mssql -mysql -oci8 -oci8-instant-client -odbc -pcntl -pdo -pic -postgres -qdbm -recode -sapdb -sharedext -sharedmem -snmp -soap -sockets (-solid) -sqlite -suhosin (-sybase-ct) -sysvipc -threads -tidy -wddx -xmlrpc -xpm -xsl -yaz -zip" 
> 
> CFLAGS="-march=native -O2 -pipe -D_GNU_SOURCE"
> ...

 

And apache:

 *Quote:*   

> www-servers/apache-2.2.16 was built with the following:
> 
> USE="ldap (multilib) ssl -debug -doc (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker"                                         
> 
> LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--no-as-needed"
> ...

 

I've never had this problem. I am desperated already because I need it!  :Sad: 

Thanks by the way  :Smile: 

----------

## tomk

Did you add "-D PHP5" to APACHE2_OPTS in /etc/conf.d/apache2?

----------

## Yuu

Hi,

maybe I'm wrong but : did you add the php handler for .php files ?

In your /etc/apache2/modules.d/70_mod_php5.conf, you should have something like :

```
IfDefine PHP5>

        # Load the module first

        <IfModule !mod_php5.c>

                LoadModule php5_module    modules/libphp5.so

        </IfModule>

        # Set it to handle the files

        <IfModule mod_mime.c>

                AddHandler application/x-httpd-php .php .php5 .phtml

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

        </IfModule>

        DirectoryIndex index.php index.phtml

</IfDefine>
```

Another question : do you have a "-D PHP5" on the APACHE2_OPTS variable, in your /etc/conf.d/apache2 ?

Good luck.

----------

## HitMaker

Yeah I have both:

/etc/conf.d/apache2

 *Quote:*   

> APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

 

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

 *Quote:*   

> <IfDefine PHP5>
> 
>         # Load the module first
> 
>         <IfModule !mod_php5.c>
> ...

 

----------

## HitMaker

Any other idea  :Sad:   :Confused: 

Thanks!

----------

## cach0rr0

70_mod_php.conf gets included via this in /etc/apache2/httpd.conf

```

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

```

check and make sure that include is present? 

it...should be. I assume it's not something silly like not having restarted apache since building php?

----------

## HitMaker

That is also in the proper file  :Sad: 

 *Quote:*   

> # Supplemental configuration
> 
> # 
> 
> # Most of the configuration files in the /etc/apache2/modules.d/ directory can
> ...

 

I agree, I am sure there is some stupid option/module I am missing  :Sad: 

----------

## tomk

Starting to clutch at straws here but do your php files end with one of these extensions?

```
.php .php5 .phtml
```

If they do is there anything obvious in your Apache error log?

----------

## HitMaker

Yep, the files I test have the .php ending. All of them.

And the log looks correct  :Sad: 

----------

## AllenJB

You might want to check the output of the following commands:

```

/etc/init.d/apache2 configdump

/etc/init.d/apache2 modules

```

That should tell you what the configuration is, according to Apache, and whether it actually has the php module loaded.

----------

## HitMaker

/etc/init.d/apache2 modules:

 *Quote:*   

> Luis-Desktop ~ # /etc/init.d/apache2 modules
> 
> Loaded Modules:
> 
>  core_module (static)
> ...

 

I'd started thinking I am stupid or something like that  :Sad: 

But then I try out a custom php instead of the Joomla instalation... and it works.

EDIT: Sorry for this post, it has been a busy week at work and when I was at home I wasn't thinking clear enough  :Sad: 

I didn't have the redirect enabled. I just enabled and now is working everything like it should be  :Smile: 

----------

## Krugy

I'm having troubles with php too, i always make the same mistake by updating apache, mysql and php without searching for any problems / configuration changes, this leaves me crying out loud and figuring out some configuration problems which usually have been pretty easy to solve.

This time things have changed...

Now i'm at this situtation where apache starts and lists apache2 as process at 'ps aux|grep apache', but it seems it's a zombie process, it will not open any pages from the server, and there is no pid file.

I'm now trying to get apache and php to work with pretty much default configuration after reinstall.

 *Quote:*   

> Apache2 flags:
> 
> [ebuild   R   ] www-servers/apache-2.2.16  USE="ssl -debug -doc -ldap (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 0 kB

 

 *Quote:*   

> PHP flags:
> 
> [ebuild   R   ] dev-lang/php-5.2.14  USE="apache2 berkdb bzip2 cli crypt ctype filter gd gdbm hash iconv json ncurses nls pcre pic posix readline reflection session simplexml snmp spl ssl tokenizer truetype unicode xml xmlreader xmlrpc xmlwriter zip zlib -adabas -bcmath -birdstep -calendar -cdb -cgi -cjk -concurrentmodphp -curl -curlwrappers -db2 -dbase -dbmaker -debug -discard-path -doc -embed -empress -empress-bcs -esoob -exif -fdftk -firebird -flatfile -force-cgi-redirect -frontbase -ftp -gd-external -gmp -imap -inifile -interbase -iodbc -ipv6 -kerberos -kolab -ldap -ldap-sasl -libedit -mcve -mhash -msql -mssql -mysql -mysqli -oci8 -oci8-instant-client -odbc -pcntl -pdo -postgres -qdbm -recode -sapdb -sharedext -sharedmem -soap -sockets -solid -spell -sqlite -suhosin -sybase-ct -sysvipc -threads -tidy -wddx -xpm -xsl -yaz" 0 kB

 

 *Quote:*   

> /etc/conf.d/apache2:
> 
> APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

 

When i start apache it shows running in the processes but does nothing. When i remove the -D PHP5 from APACHE2_OPTS, the server works fine.

'apache2ctl configdump' or 'modules' will not work with php enabled, error_log has nothing in it.

Any advice?

----------

## richard.scott

try and re-emerge php?

----------

## Krugy

 *richard.scott wrote:*   

> try and re-emerge php?

 

I've done this for around 10 times already, for apache, mysql and php, now i've removed mysql just to get this working.

I did try to update PHP to latest (5.3.3-r1) version earlier, the compile failed, does this have something to do with the problem?

Since that, i have removed php and re-emerged 5.2.14 version but no avail.

----------

## richard.scott

what does "php -v" show?

----------

## Krugy

 *richard.scott wrote:*   

> what does "php -v" show?

 

Segmentation fault

----------

## richard.scott

try re-emerging glibc and php one after the other... it may help.

----------

## kpsyran

I too am having this issue on my test server, Apache wouldn't start once I emerged php 5.3.3-r1. I removed the "-D PHP5" command, and apache will run properly without supporting php.

I tried to go back to 5.2.14, but continue to have the same issue with a segmentation fault any time I run "php -v" on the server.

I have tried re-emerging glibc as well. Php will compile without any errors.

I did the following:

 *Quote:*   

> revdep-rebuild -i --library libssl.so.0.9.8 
> 
> revdep-rebuild -i --library libcrypto.so.0.9.8

 

And now my php and apache are working properly  :Smile: [/quote]

----------

## John5788

i had the same problem with php-5.3.3-r1. I masked it and went back to 5.2.14

----------

## hazza

For me it was an issue with some sites working, others not. Traced it to a directive in /etc/php/apache2-php5/php.ini:

```
short_open_tag = Off
```

Changing it to 

```
short_open_tag = On
```

fixed the issue, however I'm undertaking a change to move all PHP tags to the long-style tag as the comments imply this will soon be depreciated.

Cheers,

Harry

----------

## Lu Tze

I had the same issue here after upgrading to php-5.3.3-r1. I eventually found out (after re-emerging php) that for some reason libphp5.so is not executable.

```

root#> chmod a+x /usr/lib/apache2/modules/libphp5.so

```

fixed the issue, now everything works beautifully. Perhaps it is worth filing a bug report? The issue is somewhat difficult to track down simply because it is so trivial.

Hope that helps.

----------

## cwc

 *cach0rr0 wrote:*   

> 70_mod_php.conf gets included via this in /etc/apache2/httpd.conf
> 
> ```
> 
> Include /etc/apache2/modules.d/*.conf
> ...

 

The 70_mod_php.conf module is not loading at /etc/apache2/modules.d/  when I emerge apache and php

I used the use flags from apache and php from emerge -pv and I get apache to work but not php.

I put the use flags in package.use and I wonder if my syntax is correct.

When I emerge I don't get any atom errors.

My package.use file is located at:   http://pastebin.com/8rDDzSrk

----------

## Snaketails

After trying *all* of the above, without any luck on anything, doing a php or php -v both gave seg faults, I did the following, 

 *Quote:*   

> 
> 
> emerge -e php
> 
> 

 

somewhere after the 200 of 275 (and before the 258'th one) php finally began working again  :Smile: 

 *Quote:*   

> 
> 
>  ~ # php
> 
> Segmentation fault
> ...

 

----------

## cwc

I also did an emerge -e php and now I'm running PHP Version 5.3.3-pl1-gentoo

Plus I made sure the conf files were configured. all is good.

httpd.conf

LoadModule php5_module modules/libphp5.so

# /etc/conf.d/apache2: config file for /etc/init.d/apache2

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

thanks for all the tips.  nice thread!

----------

## Naam

 *tomk wrote:*   

> Did you add "-D PHP5" to APACHE2_OPTS in /etc/conf.d/apache2?

 

Thanks, this work for me !

----------

## cwc

 *Naam wrote:*   

>  *tomk wrote:*   Did you add "-D PHP5" to APACHE2_OPTS in /etc/conf.d/apache2? 
> 
> Thanks, this work for me !

 

Yes.  Here's my test page and apache2

http://68.119.15.136/test.php

```

azzerare ~ # more /etc/conf.d/apache2

# /etc/conf.d/apache2: config file for /etc/init.d/apache2

# When you install a module it is easy to activate or deactivate the modules

# and other features of apache using the APACHE2_OPTS line. Every module should

# install a configuration in /etc/apache2/modules.d. In that file will have an

# <IfDefine NNN> directive where NNN is the option to enable that module.

#

# Here are the options available in the default configuration:

#

#  AUTH_DIGEST  Enables mod_auth_digest

#  AUTHNZ_LDAP  Enables authentication through mod_ldap (available if USE=ldap)

#  CACHE        Enables mod_cache

#  DAV          Enables mod_dav

#  ERRORDOCS    Enables default error documents for many languages.

#  INFO         Enables mod_info, a useful module for debugging

#  LANGUAGE     Enables content-negotiation based on language and charset.

#  LDAP         Enables mod_ldap (available if USE=ldap)

#  MANUAL       Enables /manual/ to be the apache manual (available if USE=docs)

#  MEM_CACHE    Enables default configuration mod_mem_cache

#  PROXY        Enables mod_proxy

#  SSL          Enables SSL (available if USE=ssl)

#  STATUS       Enabled mod_status, a useful module for statistics

#  SUEXEC       Enables running CGI scripts (in USERDIR) through suexec.

#  USERDIR      Enables /~username mapping to /home/username/public_html

#

#

# The following two options provide the default virtual host for the HTTP and

# HTTPS protocol. YOU NEED TO ENABLE AT LEAST ONE OF THEM, otherwise apache

# will not listen for incomming connections on the approriate port.

#

#  DEFAULT_VHOST      Enables name-based virtual hosts, with the default

#                     virtual host being in /var/www/localhost/htdocs

#  SSL_DEFAULT_VHOST  Enables default vhost for SSL (you should enable this

#                     when you enable SSL)

#

#cwc APACHE2_OPTS="-D PHP5"

APACHE2_OPTS="-D PHP5 -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE"

```

----------

