The following How To will show you through setting up possibly the best way to serve PHP with NginX (Engine X), PHP-FPM (FCGI Modul since PHP 5.3.0 compiled in with needed Option. ) APC Support and the Caching Manager Memcache on Gentoo.

Actually we use a clean Install with Distri Gentoo 2008.
nginx/0.8.53
APC ( Opcode Cache )
PHP 5.3.5 with enabled PHP-FPM
Memcache ( memcached-1.4.5 )
Optional MySQL ( for MySQL i will write a new Tutorial. )
First we will get Gentoo up to date.
Important: Make sure your Portage is updated before performing any profile changes.
# emerge eselect
after doing this we can select our preferred profile
Viewing supported profiles
# eselect profile list
Available profile symlink targets:
[1] default/linux/amd64/10.0
[2] default/linux/amd64/10.0/desktop
[3] default/linux/amd64/10.0/desktop/gnome
[4] default/linux/amd64/10.0/desktop/kde
[5] default/linux/amd64/10.0/developer
[6] default/linux/amd64/10.0/no-multilib
[7] default/linux/amd64/10.0/server
[8] hardened/linux/amd64 *
[9] hardened/linux/amd64/no-multilib
[10] selinux/2007.0/amd64
[11] selinux/2007.0/amd64/hardened
[12] selinux/v2refpolicy/amd64
[13] selinux/v2refpolicy/amd64/desktop
[14] selinux/v2refpolicy/amd64/developer
[15] selinux/v2refpolicy/amd64/hardened
[16] selinux/v2refpolicy/amd64/server
i have choosen number 8 for my System doing by
# eselect profile set 8
Note : If you’d still prefer to change profiles manually, then simply do the following:
Changing profiles manually# rm /etc/make.profile# ln -s ../usr/portage/profiles/ /etc/make.profile
now let us begin for the update and enter some commands in our bash console :
# emerge --update --deep world
when everything was completed successfully, we can configures and compile the Nginx, php, and all other necessary applications.
first edit the file /etc/package.use
# echo "dev-lang/php ~amd64" >> /etc/package.keywords /* you can change ~amd64 to reflect your system */ # echo "dev-lang/php" >> /etc/package.unmask # echo "dev-lang/php fpm" >> /etc/portage/package.use # echo "www-servers/nginx fastcgi" >> /etc/portage/package.use
Hint : if you need more modules by nginx you can manually edit the file
/etc/portage/package.use
here i show you mine# cat /etc/portage/package.use www-servers/nginx fastcgi gzip gzip-static pcre ssl status webdav zlib dev-db/mysql -berkdb dev-lang/php -* unicode json crypt calendar curl curlwrappers bcmath exif jpeg pear zip xmlrpc tiff mysqli fpm cli apache2 ctype expat fastbuild ftp gd hash iconv memlimit mysql nls pcre pic pdo reflection session simplexml sockets spl ssl tokenizer truetype xml xsl zlibConsider while emphasizing the whole dependencies.
edit the file
/etc/make.conf for using Use-Flags before compile.
insert following data to /etc/make.conf :USE="unicode vim-syntax libwww ACCEPT_KEYWORDS=~amd64 NGINX_MODULES_HTTP="gzip memcached sub map refererredis secure_link flv addition realip rewrite ssi charset perl auth_basic fastcgi stub_status access uwsgi autoindex" HTTPD_USER="nginx" HTTPD_GROUP="nginx"now emerge everything
# emerge -v pecl-apc # emerge -v memcached # emerge -av nginx phphere some USE Variables :
USE="http http-cache pcre ssl vim-syntax -aio -debug -ipv6 -libatomic" NGINX_MODULES_HTTP="access addition auth_basic autoindex charset dav fastcgi flv geo geoip gzip gzip_static limit_req limit_zone map memcached perl realip referer rewrite secure_link ssi stub_status sub upstream_ip_hash uwsgi -browser -cache_purge -degradation -empty_gif -headers_more -image_filter -passenger -proxy -push -random_index -scgi -split_clients -userid -xslt" NGINX_MODULES_MAIL="-imap -pop3 -smtp"
RUBY_TARGETS="ruby18"Note: If you change some Variables or add new Modules to PHP or NginX, you must reemerge the Package.
# emerge nginx or -'PackageName'
we can edit our fresh installed PHP-FPM and NginX
Location PHP-FPM Configfile :
/etc/php/fpm-php5.3/php-fpm.conf
and the ini file for php
/etc/php/fpm-php5.3/php.ini
PHP Configuration should not be a problem since it defaults already brings with it all functions.
for NginX open
/etc/nginx/nginx.conf
and edit to the following
1
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access_log main;
error_log /var/log/nginx/localhost.error_log info;
root /var/www/localhost/htdocs;
location ~ .php$ {
set $memcached_key "XXX:$request_uri"; #XXX is the fileowner from the file and who is using memcache on this server , set it to whatever you want.
memcached_pass 127.0.0.1:11211;
default_type text/html;
error_page 404 405 502 = @no_cache;
}location @no_cache {
fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/locaslhost/htdocs$fastcgi_script_name; include fastcgi.conf; }}
starting :
# /etc/init.d/nginx start # /etc/init.d/php-fpm start
Start memcached:
Run “memcached -h” to see a list a options avaible to the memcached. Most likely when you are just starting to test out the deamon, you will do this:
# memcached -d -u nobody -m 512 127.0.0.1 -p 11211
This will start memcached, using 512MB on the localhost, and listening on the default port 11211.
Autostart memcached on Gentoo
First, configure the memcached by editing the file /etc/conf.d/memcached. Then do the following:
# rc-update add memcached default
its time for a beer cheers
here some nice Info .
[1] Nginx: [www.nginx.org]
[2] Nginx-Module: [wiki.nginx.org/NginxModules]
[3] Nginx-Rewrite-Modul: [wiki.nginx.org/NginxHttpRewriteModule]
[4] PHP-FPM: [php-fpm.org/]
[7] Homer Simpson : [Homer_Simpson]






















bu neeee
great how to , thumbs up
Hi Dennis.
Sag mal, werden die anderen Dienste automatisch eingetragen ? also als default ?
habe nämlich das Problem, dass der Dienst enginx nicht mehr nach Neustart da ist. lieben Gruss, die Marlis aus Mainz.
Eigendlich macht des Gentoo. Kannst aber auch selber machen.
Einfach “rc-update add nginx default”
dürfte reichen.
Natürlich auch für andere Dienste.
Und es heisst nginx (ausgesprochen wie englisches ‘engine-ex’ oder ‘engine x’… gruss dennis
netter blog, solltest aber mal ein wenig mehr Inhalt zeigen
I can see you might be an expert at your field! I am launching a website soon, and your details will be quite intriguing for me.. Thanks for all your help and wishing you all of the success.
I think (or rather sure) that your point of view is similar to mine, but I’ve need you to clear one thing up, so i @ You. Thank you in adcance! Oh, I bbokmarked your installing nginx, php-fpm, apc + memcache on Gentoo | blog.hot-root.com in Digg also
thank you for digging
more updates on blog and tutorials soon.
It really is rather great precisely how often the most basic thought spins into a fabulous entire short article, is it not? You create articles efficiently, and I really only wish I have a small bit of your ability to write by myself! – Diane
I were sent here since this post was tweeted by a chap I was following and feel pleased I made it here.
That config with memcached makes no sense.
What exactly is memcache going to cache. You have nothing in the Nginx config telling memcached to cache anything.
APC is the only cache that will cache opcode automatically.
So tell what am I missing? What is the purpose of memcached here? What is it caching?
hi, i have updated the tut. i have only forgoten to add the lines with memcache . im sorry
I’m truly enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! one thing i would do. write your tutorials in both language. maybe this is good for more publicity. anyway i wish you a nice day. Golli
I have bookmarked your blog.hot-root.com !
great i found your page. pls make a tutorial with nginx and debian if you can. thank you. btw. i love to read your pitgin english style xD. heiner
maybe when i have time….