本例(ubuntu系統)已經過lnmp
安裝好php7.1了,因此後面手動安裝php5.6.36。可是爲何須要安裝多個版本的PHP?發揮你的小宇宙想象一下吧。php
下載php5.6.36mysql
wget http://cn.php.net/distributions/php-5.6.36.tar.gz
解壓nginx
tar zxvf ./php-5.6.36.tar.gz
配置sql
./configure \ --prefix=/usr/local/php56 \ --with-config-file-path=/usr/local/php56/etc \ --with-config-file-scan-dir=/usr/local/php56/conf.d \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype-dir=/usr/local/freetype \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --with-mcrypt \ --enable-ftp \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --enable-intl \ --with-xsl
若是過程提示錯誤好比:freetype,就解決這些錯誤再從新執行配置shell
先搜索這個名字,看看安裝包的具體名字是什麼,而後再使用apt-get安裝ubuntu
apt-cache search freetype
apt-get install libfreetype6-dev
執行make
api
make
我出現了這種錯誤,recipe for target 'sapi/cli/php' failed,解決方法是直接編輯makefile
文件,搜索EXTRA_LIBS
,在EXTRA_LIBS=
後面添加-liconv
,如:EXTRA_LIBS = ..... -lcrypt -liconv
,而後執行make clean
,再執行一次make
。
最後就是make install了php7
make install
cp /root/php-5.6.36/php.ini-development /usr/local/php56/etc/php.ini
打開並修改/usr/local/php56/etc/php.ini
查找 mysql.default_socket
改爲curl
mysql.default_socket = /tmp/mysql.sock
查找 mysqli.default_socket
改爲socket
mysqli.default_socket = /tmp/mysql.sock
查看php5.6版本
/usr/local/php56/bin/php -v PHP 5.6.36 (cli) (built: May 1 2018 16:03:00) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
由於 PHP 7 的服務文件爲 php-fpm.service 因此這裏用 php56-fpm.service
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php56-fpm.service
編輯php56-fpm.service,修改
PIDFile=${prefix}/var/run/php-fpm.pid ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf
爲
PIDFile=/usr/local/php56/var/run/php-fpm.pid ExecStart=/usr/local/php56/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php56/etc/php-fpm.conf
在/usr/local/php56/etc
下添加文件php-fpm.conf
內容爲
[global] pid = /usr/local/php56/var/run/php-fpm.pid error_log = /usr/local/php56/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php56-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1:9001 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 20 pm.start_servers = 10 pm.min_spare_servers = 10 pm.max_spare_servers = 20 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log
在/usr/local/php56/var/run中添加一個文件php-fpm.pid
,內容爲
3353
由於php7的pid爲3352,因此這裏用3353,這個隨意,不要和別的軟件衝突就行。
從新載入 systemd
systemctl daemon-reload
能夠設置開機啓動:
systemctl enable php56-fpm
當即啓動 php-fpm
systemctl start php56-fpm
查看php5.6的狀態
systemctl status php56-fpm
● php56-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php56-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-05-01 19:21:52 CST; 26s ago Main PID: 3353 (php-fpm) CGroup: /system.slice/php56-fpm.service ├─3353 php-fpm: master process (/usr/local/php56/etc/php-fpm.conf) ├─3373 php-fpm: pool www ├─3374 php-fpm: pool www ├─3375 php-fpm: pool www ├─3376 php-fpm: pool www ├─3377 php-fpm: pool www ├─3378 php-fpm: pool www ├─3379 php-fpm: pool www ├─3380 php-fpm: pool www ├─3381 php-fpm: pool www └─3382 php-fpm: pool www May 01 19:21:52 iZ23mzd9hi4Z systemd[1]: Started The PHP FastCGI Process Manager. May 01 19:22:05 iZ23mzd9hi4Z systemd[1]: Started The PHP FastCGI Process Manager.
查看php7的狀態
systemctl status php-fpm
● php-fpm.service - LSB: starts php-fpm Loaded: loaded (/etc/init.d/php-fpm; bad; vendor preset: enabled) Active: active (exited) since Tue 2018-05-01 14:47:03 CST; 4h 35min ago Docs: man:systemd-sysv-generator(8) May 01 14:47:01 iZ23mzd9hi4Z systemd[1]: Starting LSB: starts php-fpm... May 01 14:47:03 iZ23mzd9hi4Z php-fpm[771]: Starting php-fpm done May 01 14:47:03 iZ23mzd9hi4Z systemd[1]: Started LSB: starts php-fpm.
在/usr/local/nginx/conf
下添加一個文件名爲enable-php56.conf
內容爲
location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php56-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
修改域名配置文件中的include enable-php.conf;
爲include enable-php56.conf;
server { listen 80; ... include enable-php56.conf; ... }
在各域名目錄下添加一個info.php
文件測試一下
<?php phpinfo(); ?>