PHP (6) PHPwithfpmandNGINXPHP (6) examples. WeshoulduseApplicationsXcod PHP (6) PHP with fpm and NGINX
PHP (6) PHP with fpm and NGINX
1. Set Up latest PHP with Nginx
If get some problem with libtool to build some library. We shocould use
/Applications/Xcode. app/Contents/Developer/Toolchains/XcodeDefault. xctoolchain/usr/bin/libtool
Install the nginx, place the pcre installation package there, you may need that.
Install the PHP with factCGI and work with nginx
Http://sillycat.iteye.com/blog/2078154
Http://sillycat.iteye.com/blog/2149513
PHP-FPM VS FastCGI
Mod_php, it is a build-in module under apache. Apache HTTP server can support PHP.
FastCGI, interface between PHP and HTTP server. mod_fastcgi is a module under apache support FastCGI protocol. We can separate the PHP and Web Server.
PHP-FPM powerful, similar to span-cgi, support remote FastCGI. (FastCGI Process Manager)
Download the latest package
> Wget http://ar2.php.net/distributions/php-5.6.10.tar.gz
Unzip that and prepare the tools we need.
>. /Configure -- prefix =/home/carl/tool/php-5.6.10 -- with-openssl -- with-iconv-dir =/usr/lib -- with-curl =/opt/local/include/ curl -- with-mysql -- with-pdo-pgsql -- with-zlib-dir -- with-freetype-dir -- enable-mbstring -- with-libxml-dir =/usr -- enable-soap -- enable-calendar -- with-curl -- with-mcrypt -- with-zlib -- with-gd -- with-pgsql -- disable-rpath -- enable-inline-optimization -- with-bz2 -- with-zlib -- enable-sockets -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex -- enable-exif -- enable-bcmath -- with-mhash -- enable-zip -- with-pcre -regex -- with-mysql -- with-pdo-mysql -- with-mysqli -- with-jpeg-dir =/usr -- with-png-dir =/usr -- enable-gd-native -ttf -- with-fpm-user = www-data -- with-fpm-group = www-data -- with-libdir =/lib/x86_64-linux-gnu -- enable-ftp -- with-imap -- with-imap-ssl -- with-kerberos -- with-gettext -- with-xmlrpc -- with-xsl -- enable-opcache -- enable-fpm
Error Message:
Configure: error: Cannot find OpenSSL's libraries
Solution:
Http://mac-dev-env.patrickbougie.com/openssl/
> Wget http://www.openssl.org/source/openssl-1.0.2c.tar.gz
Unzip and try to install that
>./Configure darwin64-x86_64-cc -- prefix =/Users/carl/tool/openssl-1.0.2c
Make and install them
>. /Configure -- prefix =/Users/carl/tool/php-5.6.10 -- with-openssl -- with-iconv-dir =/usr/lib -- with-curl =/opt/local/include/ curl -- with-mysql -- enable-fpm -- with-zlib-dir -- with-freetype-dir -- enable-mbstring -- with-libxml-dir =/usr -- enable-soap -- enable -calendar -- with-mysqli
Make & Install that, php is adding to the path.
> Php -- version
PHP 5.6.10 (cli) (built: Jun 29 2015 17:35:04)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
Command to restart the nginx
> Sudo sbin/nginx-s reload
Check configuration
> Sudo sbin/php-fpm-t
Command to restart the php-fpm
> Sudo sbin/php-fpm
Check the Permission
> Sudo chown-R root: nobody/opt/nginx/html/
> Sudo chmod g + w/opt/nginx/htm
Change the configuration on php-fpm, the configuration file is
/Opt/php/etc/php-fpm.conf
Pid = run/php-fpm.pid
Error_log = log/php-fpm.log
User = nobody
Group = nobody
; Listen = 127.0.0.1: 9000
Listen = var/run/php5-fpm.sock
Another configuration file
/Opt/php/etc/php. ini
Error Message:
Sudo sbin/nginx
Nginx: [warn] 1024 worker_connections exceed open file resource limit: 256
Solution:
Check the Limit
> Ulimit-
Core file size (blocks,-c) 0
Data seg size (kbytes,-d) unlimited
File size (blocks,-f) unlimited
Max locked memory (kbytes,-l) unlimited
Max memory size (kbytes,-m) unlimited
Open file (-n) 256
Pipe size (512 bytes,-p) 1
Stack size (kbytes,-s) 8192
Cpu time (seconds,-t) unlimited
Max user processes (-u) 709
Virtual memory (kbytes,-v) unlimited
Change the limit
> Ulimit-n 1024
Then we can start the php-fpm
> Sudo sbin/php-fpm
Make sure they are running
> Ps-ef | grep fpm
0 98821 1 0 Tue11AM ?? 0: 01. 34 sbin/php-fpm
-2 98822 98821 0 Tue11AM ?? 0: 00. 00 sbin/php-fpm
-2 98823 98821 0 Tue11AM ?? 0: 00. 00 sbin/php-fpm
501 2991 5692 0 PM ttys006. 01 grep fpm
Configuration on NGINX, the configuration file will be/opt/nginx/conf/nginx. conf
Location ~ \. Php $ {
# Root html;
# Fastcgi_pass 127.0.0.1: 9000;
# Fastcgi_index index. php;
# Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
# Include fastcgi_params;
# With php5-fpm
Fastcgi_keep_conn on;
Try_files $ uri = 404;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_intercept_errors on;
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
Fastcgi_hide_header X-Powered-;
# Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_pass unix:/opt/php/var/run/php5-fpm.sock;
}
Place a very simple and hello world page/opt/nginx/html/info. php
> Cat info. php
Phpinfo ();
?>
Visit that page with URL
Http: // localhost/info. php
2. Recall PHP Knowledge
Todo...
3. MySQLi
Todo...
References:
Http://sillycat.iteye.com/blog/2194084
Http://sillycat.iteye.com/blog/2066063
Http://sillycat.iteye.com/blog/1543227
Http://sillycat.iteye.com/blog/769110
Http://sillycat.iteye.com/blog/2149513
Http://sillycat.iteye.com/blog/2078154
Build PHP with fastcgi
Https://www.howtoforge.com/how-to-build-php-5.6-fpm-fastcgi-with-zend-opcache-and-apcu-for-ispconfig-3-on-debian-7-wheezy
Https://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-debian-wheezy
Https://www.zybuluo.com/phper/note/50231
Https://www.zybuluo.com/phper/note/50231
PHP-FPM
Http://php-fpm.org/