4

is there anyone who knows how to install / configure php under apache?

I have emerge php apache both. I wanted to use mod_php for apache in GENTOO OS.

php temp.php

command line runs fine, but http://localhost/temp.php is not executing on web server instead it shows the content of the php code.

shahjapan
  • 13,637
  • 22
  • 74
  • 104

5 Answers5

6

I found a blog and I followed his instruction and it works ! I'm sharing the solution Referenced Blog

I put these lines in /etc/make.conf:

USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png"

If you want to install also phpmyadmin, then you should also add pcre session unicode:

USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png pcre session unicode"

I then changed the file /etc/init.d/apache2, in order to enable public_html folders for users (corresponding to the ~ directory), setting -D USERDIR:

APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5 -D USERDIR

Before starting mysql, you must create (once and for all) the mysql main database, and this can be done simply by running:

/usr/bin/mysql_install_db
Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
shahjapan
  • 13,637
  • 22
  • 74
  • 104
  • 7
    -1: putting single-package USE flags in /etc/make.conf is strongly discouraged, as they will be applied to the whole system (which might cause problems with dependencies and such). – Misguided Feb 09 '12 at 22:23
  • 2
    I think you meant changing `/etc/conf.d/apache2` not `/etc/init.d/apache2`. – Rene Saarsoo Apr 19 '12 at 14:25
  • echo "dev-lang/php apache2 my sql php pam ssl [...]" >> /etc/portage/package.use is an example how to specify per-package use flags. apache, php, and mysql will need added with specific use flags if you decide not to have them as global flags. After emerging gentoolkit, equery uses dev-lang/php will give you a description of available use flags for this package. I also find equery files [package] use-full. – TamusJRoyce Apr 23 '12 at 12:58
  • 2
    This answer is correct, but more than most people will probably need. The real key here is adding "-D PHP5" to APACHE2_OPTS in /etc/conf.d/apache2 then restarting via /etc/init.d/apache2 restart – nacitar sevaht Jan 02 '13 at 15:29
  • @JulianBayardoSpadafora Hey if you've rights to update the answer - kindly make those changes. – shahjapan May 09 '13 at 05:27
  • I had to add the `pdo` use flag, but otherwise this worked for me in 2023. – NuclearPeon Jul 21 '23 at 19:56
4

There appear to be a number of ways to achieve this but many seem a bit out of date or overly complicated. As of Feb 1 2010 all I did to get PHP and Apache2 working on Gentoo was to install Apache and PHP like this:

  1. bash$ emerge apache
  2. Followed the instructions for the particular extensions I wanted at this list at the Gentoo site
    • NOTE: this is the important one to get Apache and PHP working together:
      • bash$ echo "dev-lang/php apache2" >> /etc/portage/package.use
    • Another common PHP extension:
      • bash$ echo "dev-lang/php mysql" >> /etc/portage/package.use
    • And so on.
  3. Then just run bash$ emerge dev-lang/php and restart Apache with the /etc/init.d/apache2 script. PHP should now be available.
1

You may find some informations in Apache 2.0 on Unix systems

Especially, the

LoadModule php5_module modules/libphp5.so

and

SetHandler application/x-httpd-php

Lines should help :-)

The corresponding lines I have in my Apache's configuration (Apache 2, PHP 5.2, Ubuntu) are :

LoadModule php5_module /usr/lib/apache2/modules/libphp-5.2.9.so
<IfModule mod_php5.c>
  AddType application/x-httpd-php .php .phtml
  AddType application/x-httpd-php-source .phps
</IfModule>
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
1

above link dead, try this one:

http://overlays.gentoo.org/proj/php/

jms
  • 19
  • 1
-1

Try to use official GENTOO documentation:

http://www.gentoo.org/proj/en/php/php4-php5-configuration.xml

Sergey Olontsev
  • 1,084
  • 7
  • 19