編譯安裝php-fpmphp
安裝前準備
html
yum -y install gcc automake autoconf libtool make yum -y install gcc gcc-c++ glibc yum -y install libmcrypt-devel mhash-devel libxslt-devel \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \ zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \ ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \ krb5 krb5-devel libidn libidn-devel openssl openssl-devel
安裝mcryptmysql
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 mkdir -p /usr/local/libmcrytp ./configure prefix=/usr/local/libmcrytp/ make make install
php-fpm安裝nginx
wget http://cn2.php.net/distributions/php-5.4.7.tar.gz tar zvxf php-5.4.7.tar.gz cd php-5.4.7
./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt=/usr/local/libmcrytp/ --enable-mbstring \
--disable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib \
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip \
--with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir make all install
以上兩種方式均可以安裝php-fpm,安裝後內容放在/usr/local/php目錄下c++
以上就完成了php-fpm的安裝。sql
下面是對php-fpm運行用戶進行設置ubuntu
cd /usr/local/php cp etc/php-fpm.conf.default etc/php-fpm.conf vi etc/php-fpm.conf
修改 user = www-data group = www-data 若是www-data用戶不存在,那麼先添加www-data用戶 groupadd www-data useradd -g www-data www-data
2、編譯安裝nginxcentos
而後按照linxu(centos)安裝nginx 安裝nginx瀏覽器
3、修改nginx配置文件以支持php-fpmbash
nginx安裝完成後,修改nginx配置文件爲,nginx.conf
其中server段增長以下配置,注意標紅內容配置,不然會出現No input file specified.錯誤
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
4、建立測試php文件
建立php文件
在/usr/local/nginx/html下建立index.php文件,輸入以下內容
<?php echo phpinfo(); ?>;
查看phpinfo輸出的php.ini路徑,並把安裝目錄的php.ini-production或 php.ini-development複製到php.ini對應的路徑
cp /usr/local/src/php-5.4.7/php.ini-production /usr/local/php/lib/php.ini
5、啓動服務
啓動php-fpm和nginx
/usr/local/php/sbin/php-fpm (手動打補丁的啓動方式/usr/local/php/sbin/php-fpm start)
sudo /usr/local/nginx/nginx
php-fpm關閉重啓見文章結尾
6、瀏覽器訪問
訪問http://你的服務器ip/index.php,皆能夠見到php信息了。
安裝php-fpm時可能遇到的錯誤:
1. php configure時出錯
configure: error: XML configuration could not be found
apt-get install libxml2 libxml2-dev (ubuntu下)
yum -y install libxml2 libxml2-devel(centos下)
2. Please reinstall the BZip2 distribution
wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
tar -zxvf bzip2-1.0.5.tar.gz
cd bzip2-1.0.5
make
make install
3. php的配置文件中有一行--with-mysql=/usr。安裝的時候提示:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore.
這是因爲安裝mysql時沒有安裝mysql頭文件,或者是路徑指定不正確,php找不到mysql的頭文件引發的錯誤提示。
解決方法。
(1.) 查看你的系統有沒有安裝mysql header
find / -name mysql.h
若是有。請指定--with-mysql=/跟你的正常路徑。
若是沒有。請看下一步。
(2.)redhat安裝
rpm -ivh MySQL-devel-4.1.12-1.i386.rpm
(3.)ubuntu安裝
apt-get install libmysqlclient15-dev
(4.)最後一步php的配置選項添加--with-mysql=/usr便可!
4.No input file specified.
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
5. 若是php configure時缺庫,能夠先安裝庫(ubuntu下)
sudo apt-get install make bison flex gcc patch autoconf subversion locate
sudo apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev
6. mcrypt.h not found. Please reinstall libmcrypt
apt-get install libmcrypt-dev
或者
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
mkdir -p /usr/local/libmcrytp
./configure prefix=/usr/local/libmcrytp/
make
make install
7. php-fpm 5.4.7 如何關閉 重啓?
php 5.4.7 下的php-fpm 再也不支持 php-fpm 之前具備的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,須要使用信號控制:
master進程能夠理解如下信號
INT, TERM 馬上終止 QUIT 平滑終止 USR1 從新打開日誌文件 USR2 平滑重載全部worker進程並從新載入配置和二進制模塊
示例:
php-fpm 關閉:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重啓:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
查看php-fpm進程數:
ps aux | grep -c php-fpm
8.命令行下執行php,提示找不到命令
-bash: /usr/bin/php: No such file or directory
vi /etc/profile
在文件底部增長一行配置
export PATH=/usr/local/php/bin:$PATH
保存退出
source /etc/profile