search
HomeBackend DevelopmentPHP TutorialLinux下php+mysql+nginx编译搭建(三)

之前一直都是一键搭建的web服务器,但是一键搭建的环境相对来说都是比较老的。如果要用比较新的环境,特别是正式服务器,就必须自己手动编译搭建了(以下搭建基于linux centos6.5 32位服务器)。

三、安装php
进入安装目录:

          <ol>              <li>cd /opt</li>          </ol>

下载并解压:

          <ol>              <li>Wget http://am1.php.net/get/php-5.4.34.tar.gz/from/this/mirror</li>              <li>tar -zxf php-5.4.34.tar.gz</li>          </ol>

进入目录编译:

          <ol>              <li>cd php-5.4.34</li>              <li>./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pear --enable-pdo --with-pdo-mysql --with-gettext --enable-exif --enable-wddx --enable-calendar --enable-ftp --enable-dba --enable-sysvmsg --enable-sysvshm --enable-debug --enable-maintainer-zts --enable-embed --with-pcre-regex --enable-gd-jis-conv --with-fpm-user=www --with-fpm-group=www --enable-sockets</li>          </ol>

报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
在http://sourceforge.net/projects/mcrypt/files/下载libmcrypt和mcrypt编译(其中编译mcrypt需要mhash的支持,所以编译完libmcrypt后需要下载mhash,编译完mhash后才编译mcrypt)

          <ol>              <li>wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download</li>              <li>tar -zxvf libmcrypt-2.5.8.tar.gz </li>              <li>cd libmcrypt-2.5.8</li>              <li>./configure</li>              <li>Make && Make install</li>              <li> </li>              <li>Wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download</li>              <li>tar -zxvf mhash-0.9.9.9.tar.gz</li>              <li>cd mhash-0.9.9.9.tar.gz</li>              <li>./configure</li>              <li>Make && Make install</li>              <li> </li>              <li>wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download</li>              <li>tar -zxvf mcrypt-2.6.8.tar.gz</li>              <li>cd mcrypt-2.6.8</li>              <li>./configure</li>              <li>Make && Make install</li>          </ol>

此时再编译(命令不copy了),报错:mysql_config not found
执行:find / -name mysql_config
发现/opt/mysql-5.5.30/scripts/mysql_config
于是:cp /opt/mysql-5.5.30/scripts/mysql_config /usr/bin/mysql_config
再次编译,通过。

          <ol>              <li>make && make install</li>          </ol>

由于php5.4已经集成了php-fpm,所以我们不需要再额外下载php-fpm。
直接运行:

          <ol>              <li>/usr/local/php/sbin/php-fpm</li>          </ol>

报错:ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

          <ol>              <li>Cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf</li>          </ol>

解决。ps aux | grep php 查看,已经启动。

此时新建一个php文件访问,是不是还不支持?哈[坏笑]。
修改nginx.conf

          <ol>              <li>location ~ \.php$ {</li>              <li> root html;</li>              <li> fastcgi_pass 127.0.0.1:9000;</li>              <li> fastcgi_index index.php;</li>              <li> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</li>              <li> include fastcgi_params;</li>              <li> }</li>          </ol>

重启nginx,至此,所有完结。

然后是不是又有点淡淡的忧伤?觉得/usr/local/php/sbin/php-fpm太长?习惯了/etc/init.d/php-fpm start?
Vim /etc/init.d/php-fpm

          <ol>              <li>#! /bin/sh</li>              <li>### BEGIN INIT INFO</li>              <li># Provides: php-fpm</li>              <li># Required-Start: $remote_fs $network</li>              <li># Required-Stop: $remote_fs $network</li>              <li># Default-Start: 2 3 4 5</li>              <li># Default-Stop: 0 1 6</li>              <li># Short-Description: starts php-fpm</li>              <li># Description: starts the PHP FastCGI Process Manager daemon</li>              <li>### END INIT INFO</li>              <li>prefix=/usr/local/php</li>              <li>exec_prefix=${prefix}</li>              <li> </li>              <li>php_fpm_BIN=${exec_prefix}/sbin/php-fpm</li>              <li>php_fpm_CONF=${prefix}/etc/php-fpm.conf</li>              <li>php_fpm_PID=${prefix}/var/run/php-fpm.pid</li>              <li>php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"</li>              <li>wait_for_pid () {</li>              <li> try=0</li>              <li> while test $try -lt 35 ; do</li>              <li> case "$1" in</li>              <li> 'created')</li>              <li> if [ -f "$2" ] ; then</li>              <li> try=''</li>              <li> break</li>              <li> fi</li>              <li> ;;</li>              <li> 'removed')</li>              <li> if [ ! -f "$2" ] ; then</li>              <li> try=''</li>              <li> break</li>              <li> fi</li>              <li> ;;</li>              <li> esac</li>              <li> echo -n .</li>              <li> try=`expr $try + 1`</li>              <li> sleep 1</li>              <li> done</li>              <li>}</li>              <li>case "$1" in</li>              <li> start)</li>              <li> echo -n "Starting php-fpm "</li>              <li> $php_fpm_BIN --daemonize $php_opts</li>              <li> if [ "$?" != 0 ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> fi</li>              <li> wait_for_pid created $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> stop)</li>              <li> echo -n "Gracefully shutting down php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -QUIT `cat $php_fpm_PID`</li>              <li> wait_for_pid removed $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed. Use force-quit"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> force-quit)</li>              <li> echo -n "Terminating php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -TERM `cat $php_fpm_PID`</li>              <li> wait_for_pid removed $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> restart)</li>              <li> $0 stop</li>              <li> $0 start</li>              <li> ;;</li>              <li> reload)</li>              <li> echo -n "Reload service php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -USR2 `cat $php_fpm_PID`</li>              <li> echo " done"</li>              <li> ;;</li>              <li> *)</li>              <li> echo "Usage: $0 {start|stop|force-quit|restart|reload}"</li>              <li> exit 1</li>              <li> ;;</li>              <li>esac</li>          </ol>

保存,添加x权限。

如需开机启动:chkconfig php-fpm on


更多请支持:http://www.webyang.net/Html/web/article_129.html

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

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

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

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.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

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

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

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

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),