Gentoo - Installing PHP

In this article we’ll cover installing PHP and give an example set of USE flags to get started with.

This article assumes that you have completed the Slice Setup articles and the Installing Apache article.

PHP5 Install

First, let’s see what compile options and built in php libraries are available:

emerge php -vp

Remember, you can get more info on the USE flags with:

equery uses php

Update your USE flags to include the options and modules that you require. Personally, I chose the flags listed below, and added them all in one line in ‘/etc/portage/package.use’ like this:

dev-lang/php apache2 cgi ctype curl curlwrappers -doc exif fastbuild filter ftp 
hash inifile json mysql mysqli pdo pic posix sharedext sharedmem 
simplexml sockets spell truetype xml xmlreader xmlrpc xmlwriter xpm zip

I’ve word wrapped this example, but in the actual file, it’s important that it’s all on one line. If the file doesn’t exist, you can just create it.

In my flags I’ve included ‘mysql’ and ‘mysqli’; those will cause the install to depend on the mysql database server, and install that along with php. If you’re using postgresql, or another database you might want to use different USE flags.

Once you’re happy with the USE flags you’ll need, install it for real:

sudo emerge php

This took about 46 minutes for me. As usual, keep an eye on the output, and follow any advice or warnings it gives.

Don’t worry too much about getting the USE flags correct, you can always modify them and re-install later. Re-installing php on it’s own took 9 minutes for me.

Once done, restart Apache:

sudo /etc/init.d/apache2 restart


Before going any further, it is always a good idea to test your setup and make sure that everything you’ve already done is working as expected.

You can test that Apache and PHP are playing nicely together very easily by creating a simple php file with a call to the phpinfo method and then loading it in your web browser.

First create the file:

sudo nano /var/www/localhost/htdocs/test.php

Now add some basic HTML and a call to the phpinfo method to the file:

<title> PHP Test Script </title>
phpinfo( );

Great, now you should be able to load that script in your web browser using your Slice IP address:

If everything is installed properly, you should see a PHP generated page that displays all sorts of information about your PHP installation:

PHP Info Screen

Great! No need to worry about what all that means for now. We just wanted to verify that PHP was working.

Now that we know it is, go ahead and remove that test script, you don’t need the whole world knowing about your PHP installation.

sudo rm /var/www/localhost/htdocs/test.php

Almost Done

Well, it’s almost ready to use.

In the next article we’ll go through installing external PHP modules.

Article Comments: commented Thu Jul 10 21:23:10 UTC 2014:

Firstly, there chair mode activated are many ecommerce business owners did not concern themselves so much with web design. That's the perception And I think if you look in the kitchen, bedroom, dining, and conservatory.

Here is my page :: chair design,,

Ferienhaus Kanaren commented Mon Jul 14 00:23:44 UTC 2014:

Its like you read my thoughts! You seem to grasp a lot about this, like you wrote the book in it or something. I feel that you simply can do with some p.c.

to drive the message home a bit, but other than that, this is excellent blog. A fantastic read. I will certainly be back.

Jewell commented Wed Jul 16 21:35:15 UTC 2014:

I'm extremely impressed with your writing skills and also with the format on your weblog. Is that this a paid topic or did you customize it yourself? Anyway keep up the nice quality writing, it is rare to see a nice blog like this one these days.. commented Thu Jul 17 05:51:27 UTC 2014:

Older boys like them and your toddler boy wants to be as much in fashion as they do. They will still love and be proud of their little man they are making. You should always try to give the food to your baby that is best for him and organic food provides quality as well best food for your baby.

Venus factor reviews commented Mon Jul 21 15:54:01 UTC 2014:

This allows fruit flies to get in but usually keeps them from gwtting out, therefore breaking their breeding cycle and substantially reducing their number. You understand, the matter is that precisely why diets frequently fail is usually thaat theyre certainly not adjusted for you to each individuals physique, metabolism, and make-up.

If the 2 H is in P K Y, then the native will have dire vicissitudes.

custom wine glasses commented Sat Jul 26 01:49:23 UTC 2014:

Hey there! This is my first visit to your blog! We are a group of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a outstanding job!

My web page; custom wine glasses

Want to comment?

(not made public)


(use plain text or Markdown syntax)