PHP(六)PHP with fpm and NGINX
Jun 13, 2016 pm 12:22 PM
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 should 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 -a
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 files????????????????????? (-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? 2:37PM ttys006??? 0:00.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-By;
??????????? # 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/

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas
