# [SOLVED] Apache and PHP

## mvelez215

Hello

I have installed Apache, PHP, and MySQL and apache is working fine but when I try to use a PHP file it does not run or work it just shows the code.

I have tried doing emerge php and it downloads but I guess not everything.

Then I tried to do emerge apache mod_php and got the following error:

areyana / # emerge apache mod_php

Calculating dependencies       ... done!

emerge: there are no ebuilds to satisfy "mod_php".

Any idea why its not loading and besides emerge php, what else do I have to install for PHP and what settings do I have to change to get it working with apache?  Thank you in advance for all your help!

----------

## aztech

Well ...

If you have installed dev-lang/php5, for example,

then to enable the apache-module, you need to edit a file.

in /etc/conf.d/apache*

Add "-D PHP5" to the argument line in that file.

then restart apache and you should be fine.

----------

## mvelez215

Ok I will try this and let you know how it went, thank you!

----------

## mvelez215

lol, sorry for being such a noob but when you say "argument line" do you mean like anywhere in that file as long as it is not commented out (#) or there is a section that I "must" put it in? Thank you.

----------

## aztech

Yes exactly.

As mine shows ...

```

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

```

So simply add "-D PHP5" to the end of that line and restart apache.

By then, you should have a webserver that can serve PHP-files.

btw ... if you don't need it, then nevermind the USERDIR, PROXY and maybe even SSL.

// andreas

----------

## mvelez215

Ok, I added the -D PHP5 there and nothing. I think I might be missing a module? Maybe the one to make php work for apache like mod_php because in a few sites I seen them say you have to do 

```
 emerge apache mod_php
```

But when I do that I get this

areyana ~ # emerge apache mod_php 

Calculating dependencies       ... done!

emerge: there are no ebuilds to satisfy "mod_php".

Not sure if I am typing it wrong I mean I did copy and paste. lol

Is there anything else I might be missing or I can check. Apache runs will but when I click on a php page it shows the code in the page, as if I right clicked on the page and clicked on view source.

Thank you once again in advance!    :Smile: 

----------

## aztech

It's not "mod_php" you're looking for.

It's a matter of use-flags for php and apache.

Make sure that your php installation uses apache, by doing/checking this ...

/etc/portage/package.use

```

bionic ~ # cat /etc/portage/package.use | grep php

dev-lang/php bzip2 bcmath gdbm ssl threads tokenizer zlib pcre ctype session unicode cli mysql xml sockets gd simplexml mysqli snmp ftp zip

```

Make sure you have the "apache2" use-flag set for PHP, in /etc/portage/package.use.

Also, this is where you "bake" in support for mysql via php.

So basicly, you need to edit the use-flags for PHP and then reemerge PHP.

After doing this, it should work by adding "-D PHP5" to the argumentline,

in /etc/conf.d/apache2

PS.

A fast way to se exactly what a package is using or CAN use,

is to do a verbose pretend emerge..

```

bionic ~ # emerge -pv php

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

Calculating dependencies... done!

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

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

```

Hope it helps

----------

## Ahenobarbi

Do what aztech told you to - but use equery to make sure your php USE is good ( it's better than doing it manually).

---

Install app-portage/gentoolkit if you don't have it. When you have gentoolkit make sure you installed php with apache support:

```

equery u php

```

will output all use flags that influence php ( and flags descriptions). Look for line with apache2 itshould be

```
 + + apache2             : Add Apache2 support

```

( 1st + means php will be emerged with apache support if you emerge it now, 2nd + means it was installed with apache support). If there is one or two '-' instead of '+' then enable apache support for php ( make.conf or /etc/portage/package.use/ ) and reemerge it.

When you have php with apache supprot edit /etc/conf.d/apache2 and add "-D PHP5" to APACHE2_OPTS. My /etc/conf.d/apache2 is

```

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

```

----------

## mvelez215

Hey I got it working now, thank you very much for everyones else, I was missing something there the last post told me to add and it worked. Perfect, once again thank you everyone for all your help!

----------

