# [Solved] Can't get PHP installed with Apache

## Littlenux

Hello,

I have Apache2 installed and PHP too, but the PHP module for Apache seem missing.

I have put:

"-D PHP5" in the APACHE2_OPTS option of /etc/conf.d/apache2 

USE="apache2 php" in /etc/make.conf

and done: 

```
emerge apache
```

but nothing change. I think it's a flag problem but I don't know how to set it.

Thanks for your help.Last edited by Littlenux on Thu Mar 10, 2011 2:43 pm; edited 1 time in total

----------

## desultory

Did you restart apache?

----------

## Littlenux

 *desultory wrote:*   

> Did you restart apache?

 

Yes

----------

## cjubon

you have to uncomment the following line in your httpd.conf:

# AddType application/x-httpd-php .php5 

or else, in the relevant  /etc/apache2/modules.d/ conf file

(I don't remember exactly and I'm not on my linux machine right now)

----------

## Littlenux

 *cjubon wrote:*   

> you have to uncomment the following line in your httpd.conf:
> 
> # AddType application/x-httpd-php .php5 
> 
> or else, in the relevant  /etc/apache2/modules.d/ conf file
> ...

 

Well, I have no AddType in httpd.conf and no php module in /etc/apache2/modules.d/

I think the problem is that th PHP module is not compiled with Apache but I don't know how to do that.

----------

## Anon-E-moose

You should have a /usr/lib/apache2/modules/libphp5.so file if you compile php with apache support

----------

## Littlenux

I don't have, here is the listing of /usr/lib/apache2/modules/ :

```
mod_actions.so          mod_authz_dbm.so        mod_cgi.so              mod_env.so              mod_log_config.so       mod_speling.so

mod_alias.so            mod_authz_default.so    mod_cgid.so             mod_expires.so          mod_logio.so            mod_ssl.so

mod_auth_basic.so       mod_authz_groupfile.so  mod_dav.so              mod_ext_filter.so       mod_mem_cache.so        mod_status.so

mod_authn_alias.so      mod_authz_host.so       mod_dav_fs.so           mod_file_cache.so       mod_mime.so             mod_unique_id.so

mod_authn_anon.so       mod_authz_owner.so      mod_dav_lock.so         mod_filter.so           mod_mime_magic.so       mod_userdir.so

mod_authn_dbm.so        mod_authz_user.so       mod_deflate.so          mod_headers.so          mod_negotiation.so      mod_usertrack.so

mod_authn_default.so    mod_autoindex.so        mod_dir.so              mod_include.so          mod_rewrite.so          mod_vhost_alias.so

mod_authn_file.so       mod_cache.so            mod_disk_cache.so       mod_info.so             mod_setenvif.so
```

----------

## Anon-E-moose

what does "emerge -pv php" return?

----------

## Littlenux

"emerge -pv php" result:

```
These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R   ] dev-lang/php-5.3.5  USE="apache2* berkdb bzip2 cli crypt ctype fileinfo filter gd gdbm hash iconv ipv6 json mysql* nls posix readline session simplexml snmp ssl tokenizer truetype unicode xml zlib -adabas -bcmath -birdstep -calendar -cdb -cgi -cjk -curl -curlwrappers -db2 -dbmaker -debug -doc -embed -empress -empress-bcs -enchant -esoob -exif -firebird -flatfile -fpm -frontbase -ftp -gd-external -gmp -imap -inifile -interbase -intl -iodbc -kerberos -kolab -ldap -ldap-sasl -libedit -mhash -mssql -mysqli -mysqlnd -oci8 -oci8-instant-client -odbc -pcntl -pdo -phar -pic -postgres -qdbm -recode -sapdb -sharedext -sharedmem -soap -sockets -solid -spell -sqlite -sqlite3 -suhosin -sybase-ct -sysvipc -threads -tidy -wddx -xmlreader -xmlrpc -xmlwriter -xpm -xsl -zip" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

 * IMPORTANT: 5 news items need reading for repository 'gentoo'.

 * Use eselect news to read news items.

```

----------

## patrix_neo

I so happens to have php/apache2 setup. And mine works.

Do you have this ?:

```

~ # cat /etc/apache2/httpd.conf |grep -i php

LoadModule php5_module modules/libphp5.so

```

and this?

```

ls -l `locate libphp5.so`

lrwxrwxrwx 1 root root      36  9 jan 16.16 /usr/lib64/apache2/modules/libphp5.so -> /usr/lib64/php5.3/apache2/libphp5.so

-rw-r--r-- 1 root root 8681528  9 jan 16.16 /usr/lib64/php5.3/apache2/libphp5.so

```

----------

## Anon-E-moose

 *Littlenux wrote:*   

> "emerge -pv php" result:
> 
> ```
> These are the packages that would be merged, in order:
> 
> ...

 

I think you need to recompile php, it looks like it's wanting to pickup new flags (I think that's what the asterisks mean)

----------

## palettentreter

I'm having the same problem. /usr/lib64/apache2/libphp5.so just went away when upgrading from php-5.3.3-r1 to 5.3.5:

# qlist dev-lang/php | grep libphp

/usr/lib64/php5.3/apache2/libphp5.so

# qlist -Iv dev-lang/php

dev-lang/php-5.3.5

# tar -tjf /usr/portage/packages/dev-lang/php-5.3.3-r1.tbz2 | grep libphp

./usr/lib64/apache2/modules/libphp5.so

# eix -I dev-lang/php

[I] dev-lang/php

     Available versions:  

        (5)     5.2.14{tbz2} 5.3.3-r1{tbz2}

        (5.2)   5.2.16 5.2.17

        (5.3)   5.3.4 5.3.5{tbz2} ~5.3.5-r1

        {adabas apache2 bcmath berkdb birdstep bzip2 calendar cdb cgi cjk +cli concurrentmodphp crypt +ctype curl curlwrappers db2 dbase dbmaker debug discard-path doc embed empress empress-bcs enchant esoob exif fdftk +fileinfo +filter firebird flatfile force-cgi-redirect fpm frontbase ftp gd gd-external gdbm gmp +hash +iconv imap inifile interbase intl iodbc ipv6 +json kerberos kolab ldap ldap-sasl libedit mcve mhash msql mssql mysql mysqli mysqlnd ncurses nls oci8 oci8-instant-client odbc pcntl +pcre pdo +phar pic +posix postgres qdbm readline recode (+)reflection sapdb +session sharedext sharedmem +simplexml snmp soap sockets solid spell (+)spl sqlite sqlite3 ssl suhosin sybase-ct sysvipc threads tidy +tokenizer truetype unicode wddx (+)xml (+)xmlreader xmlrpc (+)xmlwriter xpm xsl yaz zip zlib}                 

     Installed versions:  5.3.5(5.3){tbz2}(12:55:00 AM 02/03/2011)(apache2 berkdb bzip2 calendar cli crypt ctype fileinfo filter ftp gd gdbm hash iconv imap json kerberos ldap mysql nls pdo phar pic posix postgres readline session simplexml ssl suhosin threads tokenizer truetype unicode xml xpm zip zlib -adabas -bcmath -birdstep -cdb -cgi -cjk -curl -curlwrappers -db2 -dbmaker -debug -doc -embed -empress -empress-bcs -enchant -esoob -exif -firebird -flatfile -fpm -frontbase -gd-external -gmp -inifile -interbase -intl -iodbc -ipv6 -kolab -ldap-sasl -libedit -mhash -mssql -mysqli -mysqlnd -oci8 -oci8-instant-client -odbc -pcntl -qdbm -recode -sapdb -sharedext -sharedmem -snmp -soap -sockets -solid -spell -sqlite -sqlite3 -sybase-ct -sysvipc -tidy -wddx -xmlreader -xmlrpc -xmlwriter -xsl)

why does the ebuild do this?

----------

## patrix_neo

If interested, here is my USE-flags:

```

[ebuild   R   ] dev-lang/php-5.3.5  USE="apache2 berkdb bzip2 cli crypt ctype exif fileinfo filter gd gdbm hash iconv ipv6 json ldap mysql nls phar posix readline session simplexml spell sqlite ssl tokenizer truetype unicode xml zlib 

```

```

[ebuild   R   ] www-servers/apache-2.2.16  USE="ldap ssl " APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif speling status unique_id userdir usertrack vhost_alias 

```

I removed the non-used USE-flags from it.

----------

## palettentreter

yes, it's the apache2 useflag on php that should make it install the apache module, right? Could you tell me which package installed the symlink you have in /usr/lib64/apache2/modules? I.e. I need the output of "qfile /usr/lib64/apache2/modules/libphp5.so". BTW, all the other files in my /usr/lib64/apache2/modules are actual files, not symlinks, and as shown above, it used to be the same with php-5.3.3-r1. So what has happened? Rebuilding php doesn't help. And even if it had, it shouldn't have been necessary in the first place when the apache2 useflag has always been set and other useflags didn't change either...

----------

## patrix_neo

 *palettentreter wrote:*   

> yes, it's the apache2 useflag on php that should make it install the apache module, right? Could you tell me which package installed the symlink you have in /usr/lib64/apache2/modules? I.e. I need the output of "qfile /usr/lib64/apache2/modules/libphp5.so". BTW, all the other files in my /usr/lib64/apache2/modules are actual files, not symlinks, and as shown above, it used to be the same with php-5.3.3-r1. So what has happened? Rebuilding php doesn't help. And even if it had, it shouldn't have been necessary in the first place when the apache2 useflag has always been set and other useflags didn't change either...

 

```

 ~ # qfile /usr/lib64/apache2/modules/libphp5.so

 ~ # qfile /usr/lib64/php5.3/apache2/libphp5.so

dev-lang/php (/usr/lib64/php5.3/apache2/libphp5.so)

```

It was a long time ago I was installing this. But either it was a manual work you had to do. If you dont have /usr/lib64/php5.x/apache2/libphp5.so, you cant have a symlink to it, I guess? It just have to be found at ../modules/libphp5.so as a symlink or actual file for Apache to be able to load the module according to

```

LoadModule php5_module modules/libphp5.so

```

btw, I have a multilib setup. Maybe that is changing the behaviour, when looking at the libphp5.so place, if you are on a true 64-bit only setup? And, yes, you certainly need USE-flag apache2 for the dev-php install.

----------

## Littlenux

 *patrix_neo wrote:*   

> I so happens to have php/apache2 setup. And mine works.
> 
> Do you have this ?:
> 
> ```
> ...

 

Result before compilation:

```
gentoo ~ # cat /etc/apache2/httpd.conf |grep -i php

gentoo ~ # LoadModule php5_module modules/libphp5.so

-bash: LoadModule: command not found

gentoo ~ # ls -l `locate libphp5.so`

total 44

-rw-r--r-- 1 root    root     4766 Mar  1 22:16 index.html

-rw-r--r-- 1 root    root    27206 Mar  1 19:20 msg

drwxr-xr-x 7 portage portage  4096 Nov 27 17:52 portage-2.1.9.25

drwxr-xr-x 3 root    root     4096 Mar  4 02:32 portage-recover
```

 *Anon-E-moose wrote:*   

> I think you need to recompile php, it looks like it's wanting to pickup new flags (I think that's what the asterisks mean)

 

That was the problem !

After "emerge php", "apache2ctl modules" return "php5_module (shared)"

Remarque 1: I had already do this "emerge php", so several compilations is perhaps necessary or I had done it before putting USE="apache2 php" in /etc/make.conf, I don't remember. So, Anon-E-moose you remarque about the asterix is certainly right.

Remarque 2: /usr/lib/apache2/modules/libphp5.so is now well present.

Remarque 3: "ls -l `locate libphp5.so`" return exactly the same result after compilation so it's not significant.

So thanks a lot! But now I have a new problem  :Sad: 

I had restart Apache and I can see it in the process list but when I try to get 127.0.0.1/index.html I have nothing.

With "netstat -ln --tcp" I can see port 80 is not listening  :Mad:   I will examine httpd.conf but if you have an idea...

----------

## Stonic

Do you get any errors when starting apache2? Check:

/var/log/apache2/error_log after you start it (I know in some cases, the init script reports apache started OK, but error log says otherwise).

You might need to check the vhost configurations for apache as well:

```
/etc/apache2/vhosts.d/00_default_vhost.conf
```

-and-

```
/etc/apache2/vhosts.d/default_vhost.include
```

----------

## patrix_neo

 *Littlenux wrote:*   

>  *patrix_neo wrote:*   I so happens to have php/apache2 setup. And mine works.
> 
> Do you have this ?:
> 
> ```
> ...

 

LoadModule is not a command through the console/terminal. It is a part of the configuration file. You can find that one at: 

/etc/apache2/httpd.conf

You will find a lot of LoadModule lines in httpd.conf. Just put it at the top of all those LoadModule lines. Then you are a step closer to a proper setup for apache/php.

----------

## Littlenux

 *Stonic wrote:*   

> Do you get any errors when starting apache2? Check:
> 
> /var/log/apache2/error_log after you start it (I know in some cases, the init script reports apache started OK, but error log says otherwise).
> 
> You might need to check the vhost configurations for apache as well:
> ...

 

/var/log/apache2/error_log report nothing since the compilation. No "resuming normal operation" or no "shuting down" when stoping/restarting Apache. This is strange.

```
# apache2ctl virtualhosts
```

return:

```
apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.0.11 for ServerName

VirtualHost configuration:

wildcard NameVirtualHosts and _default_ servers:

_default_:443          localhost (/etc/apache2/vhosts.d/00_default_ssl_vhost.conf:11)

*:80                   is a NameVirtualHost

         default server localhost (/etc/apache2/vhosts.d/00_default_vhost.conf:38)

         port 80 namevhost localhost (/etc/apache2/vhosts.d/00_default_vhost.conf:38)

Syntax OK
```

/etc/apache2/vhosts.d/00_default_vhost.conf

and

/etc/apache2/vhosts.d/default_vhost.include

seem ok.

----------

## Littlenux

 *patrix_neo wrote:*   

> 
> 
> LoadModule is not a command through the console/terminal. It is a part of the configuration file. You can find that one at: 
> 
> /etc/apache2/httpd.conf
> ...

 

OK, I have failed to catch the "httpd.conf" word in your original message.

For the record, since the recompilation the PHP module is loaded but it does not appear in /etc/apache2/httpd.conf. Here is how it work:

In /etc/apache2/httpd.conf there's an include line: "Include /etc/apache2/modules.d/*.conf"

and in /etc/apache2/modules.d/ there's a "70_mod_php5.conf" file which load the PHP module.

----------

## patrix_neo

 *Littlenux wrote:*   

>  *patrix_neo wrote:*   
> 
> LoadModule is not a command through the console/terminal. It is a part of the configuration file. You can find that one at: 
> 
> /etc/apache2/httpd.conf
> ...

 

I dont know exactly how all those config-files interact with eachother. I do know that most if not ALL config options was moved back in to httpd.conf again. This happened late 2010 if my memory is correct.

I did NOT touch any 70_mod_php5.conf files either. When examining the file, it supposedly loads the module and adds the php handler. Very annoying splitting options among files, in my opinion. But options is good - I suppose.

[edit] Happy news. I did an experiment and commented the LoadModule-line for php5 in /etc/apache2/httpd.conf and restarted apache with success. I can report that php works with the 70_mod_php5.conf. I did learn something new this day too. How about that.   :Shocked: 

----------

## Littlenux

For the record, about Apache which do not listen:

A simple emerge apache + restart does not solve the problem

I had to:

 emerge --unmerge apache 

 rm -r /etc/apache2/

 emerge apache

then apache worked again but without PHP...

so I do again:

 apache2ctl stop

 emerge php

 apache2ctl start

then again apache start without listen on port 80...

One point I noticed: when Apache was working well there was several Apache process (normal), when Apache was not listening there was only a single process and I had to kill it, apache2ctl stop did nothing.

At this point I give up, something seem broken. I reload a backup.

----------

## chiefbag

For the record its better to use the init files for starting and stopping.

```
/etc/init.d/apache2 start

/etc/init.d/apache2 stop 

/etc/init.d/apache2 reload

/etc/init.d/apache2 restart
```

----------

