php7.0的編譯安裝
環境說明:VMware12搭建 centos6.5
已經安裝了nginx1.6和mysql5.7
1 配置編譯環境
https://segmentfault.com/a/1190000009875949
yum -y update && yum -y upgrade
yum groupinstall "Development Tools"
yum -y install gcc gcc-c++ pcre openssl gd-devel* zlib-devel pcre-devel libxml2-devel curl-devel
wget https://svwh.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
編輯 vim /etc/ld.so.conf 末行添加
/usr/local/lib
並執行:ldconfig
1 配置編譯環境(方法二)
https://www.cnblogs.com/da-guang/p/6973868.html
編譯安裝 libmcrypt, mhash, mcrypt 二進制源碼包
這裏之因此編譯安裝libmcrypt,緣由是yum安裝的貌似會報錯,
編譯安裝libmcrypt-2.5.7
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/related/libmcrypt
make && make install
編譯安裝mhash-0.9.9.9
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local/related/mhash
make && make install
編譯安裝mcrypt-2.6.8
tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8
export LD_LIBRARY_PATH=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib
export LDFLAGS="-L/usr/local/related/mhash/lib -I/usr/local/related/mhash/include/"
export CFLAGS="-I/usr/local/related/mhash/include/"
./configure --prefix=/usr/local/related/mcrypt --with-libmcrypt-prefix=/usr/local/related/libmcrypt
make && make install
其餘的yum依賴安裝
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
php7編譯安裝
wget http://cn2.php.net/distributions/php-7.0.14.tar.gz
tar -zxf php-7.0.14.tar.gz
cd php-7.0.14
./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/data/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --enable-sockets --enable-soap --enable-session --with-curl --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --disable-fileinfo
用./configure --help 查看configure的正確語法
make clean &&make && make install
prefix=/usr/local/php7 php7安裝的根目錄
-with-config-file-path=/usr/local/php7/etc php7的配置目錄
--with-mysql-sock=/data/mysql/mysql.sock
--with-mysql=shared,mysqlnd php7依賴的mysql庫
--with-mysqli=shared,mysqlnd
--with-pdo-mysql=shared.mysqlnd
--enable-session [容許php會話session]
--with-curl [容許curl擴展]
--enable-opcache [使用opcache緩存
--with-fpm-user=www php-fpm的用戶
--with-fpm-group=www
編譯時會發生--with-mysql和--enable-fastcgi不能識別,正常
make test時會有一個報錯,正常
須要和MySQL進行通訊,須要特別查看PHP7安裝後的lib擴展庫目錄
usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
確保至少存在mysql.so pdo_mysql.so兩個動態庫文件
ls -lrt /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
方法一編譯安裝後未經處理的配置
cd php-7.0.14
cp php.ini-production /usr/local/php7/etc/php.ini
cp /sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
下面這個能夠不要,在配置文件php-fpm.conf中能夠配置include
方法二:使用https://github.com/lizer2014/mylnmp/tree/master/PHP文中的配置
[root@localhost php-7.0.0]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
[root@localhost php-7.0.0]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
修改php.ini配置中的參數,extension_dir改成本身的
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
在/etc/init.d/php-fpm中在start函數的守護進程前必須有make /var/run/php-fpm命令,不然重啓服務器會致使啓動失敗,nginx中配置也有這個問題
添加php的環境變量
echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile
source /etc/profile
設置php-fpm進程目錄的用戶和用戶組爲nginx,並建立php會話session目錄
groupadd -r www && useradd -r -g www -s /bin/false -M www
mkdir -p /var/log/php-fpm/ &&
mkdir -p /var/run/php-fpm &&
cd /var/run/ &&
chown -R www:www php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
php-fpm -t試PHP的配置文件是否正確合法
service php-fpm start
ps -aux|grep php
配置文件
/usr/local/php7/etc/php.ini
/usr/local/php7/etc/php-fpm.d/www.conf
生產狀況下,能夠直接更改php的配置文件內容
vi /usr/local/php7/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi.sock 此處的配置和nginx中的fastcgi_pass中配置同樣 unix:/tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 300
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 60
request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = var/log/slow.log
pm.status_path = /status
nginx中配置
36 location ~ .*.(php|php7)?$ {
37
38 root /var/www/html/;
39 fastcgi_pass unix:/tmp/php-cgi;
40 fastcgi_index index.php;
41 fastcgi_param HTTPS on;
42 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
43 include fastcgi_params;
44
45 #new line
46 include fastcgi.conf;
47 }
39行和php.conf裏面的配置文件相同
若是重啓的時候報錯:
Starting php-fpm [14-Aug-2015 11:29:31] ERROR: An another FPM instance seems to already listen on /tmp/php-fcgi.sock
[14-Aug-2015 11:29:31] ERROR: FPM initialization failed
failed
檢查是否啓動:ps aux |grep php-fpm
若是有進程就殺死:killall php-fpm
若是沒有進程: 直接刪除/tmp/php-fcgi.sock而後再啓動。
php