Results 1 to 25 of 34
-
02-22-2011, 12:11 AM #1Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
nginx + php-fpm + debian squeeze tutorial - the fastest way to host php!
Here is a quick howto for setting up nginx and php-fpm on a Debian 6 VPS. We will be using the dotdeb repository for this so a big thanks goes to the dotdeb guys for building such reliable Debian packages.
This has been tested on a Debian 6 OpenVZ minimal template:
First add the dotdeb repo to your sources.list file:
Code:nano /etc/apt/sources.list
Code:deb http://packages.dotdeb.org stable all
Code:wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | sudo apt-key add - rm dotdeb.gpg
Code:apt-get update
Code:apt-get install php5 php5-fpm php-pear php5-common php5-mcrypt php5-mysql php5-cli php5-gd
Code:apt-get install nginx
Code:nano /etc/php5/fpm/php5-fpm.conf
Code:pm.max_children = 25 pm.start_servers = 4 pm.min_spare_servers = 2 pm.max_spare_servers = 10 pm.max_requests = 500
Code:request_terminate_timeout = 30s
Code:/etc/init.d/php5-fpm restart
Code:nano /etc/nginx/nginx.conf
Code:client_max_body_size 20M; client_body_buffer_size 128k;
Code:cd /etc/nginx/sites-enabled rm default
Code:nano /etc/nginx/sites-available/www.website.com
Code:server { listen 80; server_name website.com www.website.com; access_log /var/log/nginx/website.access_log; error_log /var/log/nginx/website.error_log; root /var/www/www.website.com; index index.php index.htm index.html; location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/www.website.com$fastcgi_script_name; include fastcgi_params; } }
Code:ln -s /etc/nginx/sites-available/www.website.com /etc/nginx/sites-enabled/www.website.com
Code:/etc/init.d/nginx restart
Code:listen 443;
Code:ssl on; ssl_certificate /path/to/certificate/www.website.com.crt; ssl_certificate_key /path/to/certificate_key/www.website.com.key;
AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
-
02-27-2011, 01:55 AM #2New Member
- Join Date
- Jan 2011
- Posts
- 2
Thanks for share.
-
02-27-2011, 03:19 AM #3Disabled
- Join Date
- Jul 2010
- Location
- Australia
- Posts
- 154
Good information for beginners or ones that need help.
I hope you continue to share more.
-
02-28-2011, 05:51 PM #4New Member
- Join Date
- Feb 2011
- Posts
- 3
thanks for sharing, it certinaly helped me out
-
02-28-2011, 09:55 PM #5Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
You are all most welcome! I hope more people can benefit from tutorials like this. I plan on posting more here in the future.
AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
-
04-25-2011, 04:21 AM #6New Member
- Join Date
- May 2005
- Posts
- 1
Hey, Thanks for the nice tut.
I'm not a Linux noob, but I'm new to Dotdeb and some of the steps here are new to me. Namely this one
Tweak the php-fpm configuration:
Code:nano /etc/php5/fpm/php5-fpm.conf
Cheers
Aaron
-
04-25-2011, 09:56 AM #7Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
Hey thanks for pointing that out. That might actually be a typo. I'll have to look at my configs later to see but typically the file is called php-fpm.conf. Try editing that file and continue on. You shouldn't have any more problems from there.
-
04-26-2011, 01:25 AM #8Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
Update:
Okay, so I've checked my configuration and my servers actually have a file called 'php5-fpm.conf' so perhaps the dotdeb binaries have changed to use the 'php-fpm.conf' file name instead... Try editing that file and if you could report back if it works that would be great. If not then just copy the file or symlink it and see if that works as well.
-
05-22-2011, 03:16 PM #9Newbie
- Join Date
- Sep 2010
- Posts
- 24
What else would I need to install other than MySQL to get wordpress working?
Thanks
-
05-22-2011, 03:31 PM #10Aspiring Evangelist
- Join Date
- Oct 2010
- Location
- Iraq
- Posts
- 409
@OP thanks for this informative tutorial
@thomas01155 nothing else (nginx + php-fpm + mysql) is what you need to run WordpressXsltel OÜ | Fast and Steady Internet services
cPanel Webhosting | VPS Hosting | Since 2011
-
05-22-2011, 04:06 PM #11Newbie
- Join Date
- Sep 2010
- Posts
- 24
Thanks, I have my wordpress site working now. I keep getting 502 bad gate way errors when I update stuff on the site however. Do you know how to fix this?
Thanks,
Tom
-
05-22-2011, 04:12 PM #12Aspiring Evangelist
- Join Date
- Apr 2010
- Location
- North Carolina
- Posts
- 442
Security issue:
http://scott.yang.id.au/2011/04/secu...tcgi-on-nginx/
-
05-22-2011, 04:41 PM #13Newbie
- Join Date
- Sep 2010
- Posts
- 24
OK so now its but I'm still getting the same error
location ~ .php$ {
if (-f $request_filename) {
fastcgi_pass 127.0.0.1:9000;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/*removed*.com$fastcgi_script_name;
include fastcgi_params;
}
2011/05/23 00:43:40 [error] 1987#0: *15 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/profile.php"
2011/05/23 00:43:42 [error] 1987#0: *15 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/edit.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/index.php"
2011/05/23 00:43:44 [error] 1987#0: *15 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/post.php?post=1&action=edit HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/edit.php"
2011/05/23 00:43:46 [error] 1987#0: *21 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 11.111.11.11, server: *remove*.com, request: "POST /wp-admin/post.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/post.php?post=1&action=edit"
2011/05/23 00:43:48 [error] 1987#0: *21 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com"
2011/05/23 00:43:51 [error] 1987#0: *21 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/profile.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/"
2011/05/23 00:43:53 [error] 1987#0: *21 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/edit.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/profile.php"
2011/05/23 00:43:57 [error] 1987#0: *21 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/edit.php?post_type=page HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/edit.php"
2011/05/23 00:43:59 [error] 1987#0: *21 readv() failed (104: Connection reset by peer) while reading upstream, client: 11.111.11.11, server: *remove*.com, request: "GET /wp-admin/post.php?post=5&action=edit HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/edit.php?post_type=page"
2011/05/23 00:44:00 [error] 1987#0: *21 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 11.111.11.11, server: *remove*.com, request: "POST /wp-admin/post.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*remove*.com", referrer: "http://*remove*.com/wp-admin/post.php?post=5&action=edit"
netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
raw6 0 0 :::1 :::* 7
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 716910858 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 716887395 /var/run/saslauthd/mux
unix 2 [ ACC ] STREAM LISTENING 716887911 /var/run/sendmail/mta/smcontrol
Thanks,
TomLast edited by thomas01155; 05-22-2011 at 04:53 PM. Reason: more information
-
05-22-2011, 05:21 PM #14Newbie
- Join Date
- Sep 2010
- Posts
- 24
Here are some more logs if anyone can help me solve this problem
php5-fpm.log
[23-May-2011 01:16:49] WARNING: [pool www] child 3574 exited on signal 11 (SIGSEGV) after 62.058702 seconds from start
[23-May-2011 01:16:49] NOTICE: [pool www] child 3597 started
[23-May-2011 01:16:57] WARNING: [pool www] child 3575 exited on signal 11 (SIGSEGV) after 67.750219 seconds from start
user.log
May 22 23:47:51 V-1040 suhosin[3173]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
May 22 23:47:53 V-1040 suhosin[3177]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
May 22 23:53:26 V-1040 suhosin[3175]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
May 22 23:53:27 V-1040 suhosin[3178]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
May 22 23:53:29 V-1040 suhosin[3184]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
May 22 23:53:31 V-1040 suhosin[3186]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xx.xxx.xx.xx', file '/var/www/xx***********/wp-admin/admin.php', line 109)
Thanks
-
05-22-2011, 10:26 PM #15Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
Did you see this thread:
http://serverfault.com/questions/178...-on-a-test-ser
It suggests that this could be a configuration problem and that this line in nginx.conf will fix it:
Code:request_terminate_timeout = 30s
Also, how much memory do you have and how much is free? Simply run:
Code:free -m
If you are still experiencing problems after triple checking your configs and free memory I'd be glad to help you further.AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
-
05-23-2011, 12:53 AM #16Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
Also I am noting that you have this in your configuration:
Code:location ~ .php$ { if (-f $request_filename) { fastcgi_pass 127.0.0.1:9000; }
You should no longer use the depreciated if statements inside of a location block as per this article on the nginx wiki:
http://wiki.nginx.org/IfIsEvil
It explicitly says on the above page:
The only safe things may be done inside if in location context are:
return ...;
rewrite ... last;
Anything else may cause unpredictable results up to SIGSEGV.AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
-
05-23-2011, 04:22 AM #17Newbie
- Join Date
- Sep 2010
- Posts
- 24
OK, this is my new virtual host config file for my site:
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/xxxxxxxxxx.co.cc$fastcgi_script_name;
include fastcgi_params;
}
/etc/php5/fpm/php5-fpm.conf
pm.max_children = 25
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 500
request_terminate_timeout = 30s/etc/php5/fpm/php-fpm.conf
http://pastebin.com/RzJjMK6K
I noticed this ;include=/etc/php5/fpm/*.conf is commented. I tried uncommenting it but php5-fpm fails to restart when I do that. So is it even reading my php5-fpm.conf?
Restarting PHP5 FastCGI Process Manager: php5-fpm failed!I moved the php.ini from cli to here
/etc/php5/fpm/php.inifree -m
total used free shared buffers cached
Mem: 2048 190 1857 0 0 0
-/+ buffers/cache: 190 1857
Swap: 0 0 0
Tom
PS: I very new to all of this, so thank you again for your help : )Last edited by thomas01155; 05-23-2011 at 04:26 AM.
-
05-23-2011, 04:54 AM #18Newbie
- Join Date
- Sep 2010
- Posts
- 24
This is my nginx.conf if it helps: http://pastebin.com/3Qv084Jw
Do I need a block with upstream php {}?
I can't get my site to load at all, I just get 502 Bad Gateway everytime now. I don't know why it managed to load for a bit yesterday.
ThanksLast edited by thomas01155; 05-23-2011 at 05:02 AM.
-
05-23-2011, 09:59 AM #19Newbie
- Join Date
- Sep 2010
- Posts
- 24
Is php5-fpm.conf meant to be in /etc/php5/fpm/pool.d/ folder?
I have /etc/php5/fpm/pool.d/www.conf inside the pool.d folder.
I'm so
-
05-23-2011, 12:30 PM #20Newbie
- Join Date
- Sep 2010
- Posts
- 24
OK, I have it working after all day trying to get it to xD I put all the tweaks in: /etc/php5/fpm/pool.d/www.conf and the line php_admin_value[memory_limit] = 256M
Thanks xx
-
05-23-2011, 01:07 PM #21Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
Is php5-fpm.conf meant to be in /etc/php5/fpm/pool.d/ folder?
It sounds like you may have it working now but if you need any help please respond back to this thread.AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
-
05-23-2011, 03:14 PM #22Newbie
- Join Date
- Sep 2010
- Posts
- 24
-
05-23-2011, 03:38 PM #23Newbie
- Join Date
- Sep 2010
- Posts
- 24
My used memory just seems to keep increasing till I get the gateway error
total used free shared buffers cached
Mem: 2048 703 1344 0 0 0
-/+ buffers/cache: 703 1344
Swap: 0 0 0
-
05-23-2011, 04:22 PM #24Newbie
- Join Date
- Sep 2010
- Posts
- 24
-
05-23-2011, 06:28 PM #25Junior Guru Wannabe
- Join Date
- Oct 2010
- Location
- USA
- Posts
- 53
No you do not need to set php_admin_value[memory_limit] to any value. Just leave this line commented out for the default value to take affect. Also, you are right about the min and max server count. If you leave the default setting for child processes as dynamic:
Code:pm = dynamic
There are example values for those settings in the walkthough on page 1 of this thread and if you have 2GB of memory like your posts show then those values should work quite nicely.
However, if you are experiencing high memory usage simply adjust each of those settings down until you get an exceptable amount of memory usage.
You can also check to see exactly how many php-fpm processes are being spawned with this command:
Code:ps -A | grep php-fpm
Code:top
Typically when using top, the RES column is the most accurate for actual memory usage whether it's cached, shared, etc.Last edited by AltruHost; 05-23-2011 at 06:35 PM. Reason: more info...
AltruHost - Our Public Beta has been announced!!! - A webhost on the Rise... Altruism AKA Selflessness AKA The Golden Rule. That is what AltruHost is all about.
http://www.altruhost.com - Like Us on Facebook - Follow Us on Twitter
Similar Threads
-
nginx + php-fpm shared hosting
By AltruHost in forum Web HostingReplies: 19Last Post: 03-04-2011, 08:33 AM -
nginx and php installation on Debian tutorial
By fb904 in forum Hosting Security and TechnologyReplies: 3Last Post: 07-27-2010, 03:05 PM -
nginx with php-fpm troubles
By whdev in forum Hosting Security and TechnologyReplies: 4Last Post: 04-10-2010, 01:52 PM -
Any dedicated host provider with nginx+php-fpm+mysql support
By hvs69 in forum Dedicated ServerReplies: 2Last Post: 01-15-2010, 02:01 PM -
Apache vs Nginx (mod_php VS php-fpm)
By bostjan in forum Hosting Security and TechnologyReplies: 7Last Post: 06-25-2009, 07:19 AM