CentOS 6 部署 Nginx + PHP5 Web服务器
在 CetnOS 6 (64位) 操作系统上部署Nginx and PHP5服务器。这个过程通过 yum 命令进行RPM包安装。
可以参考 PHP 官方文档。
安装 一些必要的 YUM 库
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
安装 Nginx
添加 nginx 的 YUM 库配置文件 /etc/yum.repos.d/nginx.repo,
[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1
root 用户执行:
# yum install nginx
安装 PHP 及重要插件 php-fpm
root 用户执行:
# yum install php-fpm
将会安装好 php-fpm 以及 php 本身在内的其他依赖。
配置、启动 php-fpm
配置 /etc/php.ini,设置 cgi.fix_pathinfo=0
启动 php-fpm 并放置后台运行
php-fpm -D
停掉 php-fpm 的方法
root@acx-xiwang:/etc# ps -ef | grep php-fpmroot 31591 1 0 14:09 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)apache 31592 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31593 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31594 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31595 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwapache 31596 31591 0 14:09 ? 00:00:00 php-fpm: pool wwwroot 31914 31878 0 14:32 pts/1 00:00:00 grep --color php-fpmroot@acx-xiwang:/etc# kill -s SIGINT 31591
或者通过 service 命令执行
service php-fpm stopservice php-fpm start
配置、启动 Nginx
直接分享我的配置 /etc/nginx/nginx.conf:
user xiwang;events {}http { include /etc/nginx/mime.types; server { root /home/xiwang/opt/www; location / { index index.html index.htm index.php; } error_page 404 /404.html; location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }}
启动 Nginx 服务器
$ nginx
或者通过 service 命令执行:
service nginx stopservice nginx start
如果运行时修改了配置文件,可以通过 nginx -s reload 来使配置文件生效。
FAQ
如何解决 “NO INPUT FILE SPECIFIED” 的问题,当我们安装 PHP 和 NGINX 的时候
文章: 英文原版
检查 php 文件是否拥有写权限,它的父目录都有执行权限 ?
chmod a+x /home/xiwang/opt #<-- container folder should be granted execute permissionchmod a+x /home/xiwang/opt/www #<-- container folder should be granted execute permissionchmod a+w /home/xiwang/opt/www/*.php #<-- .php file should be granted write permission

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

SublimeText3 Chinese version
Chinese version, very easy to use

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
