Linux下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

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

AI Hentai Generator
Generate AI Hentai for free.

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
