Gentoo – PHP


In a previous guide I discussed how to set up an Apache web server on your Gentoo box. In this part I will show you how to set up PHP so it works with Apache and MySQL which will allow you to host dynamic content rich websites on your web server. Plus by having MySQL, Apache, and PHP installed and working together you have access to a whole slew of web based tools that make managing your server much simpler.

In order to install PHP we must do the following as root:

echo "dev-lang/php  gd" >> /etc/portage/package.use

Save the file and type:

emerge -av php

PHP will take a while to compile even on a very fast PC so take a break and go do something for a half hour to an hour …

It’s done? Ok, now we need to make sure that apache is set up to use PHP. So as root type:

nano -w /etc/conf.d/apache2

In this file you will find a line that reads:


At the end of this line, still in the quotes add: -D PHP5 if it is not there already. The newer PHP ebuilds have been adding this automatically as of lately, but check it just to be sure. Once you have added or verified that it is there then save the file and exit. Then restart apache:

/etc/init.d/apache2 restart

Now lets test to make sure that PHP is installed correctly. We will put a test file in our localhost folder that will give us a ton of information about our PHP setup. So as root again do the following:

  • cd /var/www/localhost/htdocs
  • nano -w phpinfo.php
  • In the editor type the following
    <?php phpinfo(); ?>
  • Save the file and exit.
  • In a web browser on another PC on the local network type the following: http://server_ip_address/phpinfo.php
  • If PHP is installed correctly you should see a fancy PHP info page with a lot of information.

Thats it! Simple aye? Try installing PHP and get it working that fast on a Windows/IIS server, hehe good luck!

  1. No Comments