lnmp多个php版本并存但是为什么要安装多个版本的PHP呢?用你的小宇宙来想象它。安装PHP5.6.36下载php5.6.36wgethttp://cn.php.net/distributions/php-5.6.36.tar.gz解压tarzxvf./php-5.6.36.tar.gz配置./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,解决这些错误然后重新执行配置首先搜索这个名字,看查看安装包具体名称是什么,然后使用apt-get安装apt-cachesearchfreetypeapt-getinstalllibfreetype6-dev执行makemake。我有这个错误,recipefortarget'sapi/cli/php'failed,解决方法是直接编辑makefile,搜索EXTRA_LIBS,在EXTRA_LIBS=后加上-liconv,如:EXTRA_LIBS=.....-lcrypt-liconv,然后执行makeclean,再执行make最后是makeinstallmakeinstall配置php5.6cp/root/php-5.6.36/php.ini-development/usr/local/php56/etc/php.ini打开修改/usr/local/php56/etc/php.ini找到mysql.default_socket改成mysql.default_socket=/tmp/mysql.sock找到mysqli.default_socket改成mysqli.default_socket=/tmp/mysql.sock查看php5.6版本/usr/local/php56/bin/php-vPHP5.6.36(cli)(built:May1201816:03:00)Copyright(c)1997-2016ThePHPGroupZendEnginev2.6.0,Copyright(c)1998-2016ZendTechnologies为PHP配置php-fpm服务7的服务文件是php-fpm.service,所以使用php56-fpm.servicecpsapi/fpm/php-fpm.service/usr/lib/systemd/system/php56-fpm.service编辑php56-fpm.service和修改PIDFile=${prefix}/var/run/php-fpm.pidExecStart=${exec_prefix}/sbin/php-fpm--nodaemonize--fpm-config${prefix}/etc/php-fpm.conf为PIDFile=/usr/local/php56/var/run/php-fpm.pidExecStart=/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.piderror_log=/usr/local/php56/var/log/php-fpm.loglog_level=notice[www]listen=/tmp/php56-cgi.socklisten.backlog=-1listen.allowed_clients=127.0.0.1:9001listen.owner=wwwlisten.group=wwwlisten.mode=0666user=wwwgroup=wwwpm=dynamynpm.max_children=20pm.start_servers=10pm.min_spare_servers=10pm.max_spare_servers=20request_terminate_timeout=100request_slowlog/log_timeout=0log/varslow添加文件php-fpmusr/local/php56/var/run中的.pid,内容是3353,因为php7的pid是3352,所以这里用3353,这个是可选的,不要和其他软件冲突reloadsystemdsystemctldaemon-reload可以设置开机启动:systemctlenablephp56-fpm立即启动php-fpmsystemctlstartphp56-fpm检查php5.6状态systemctlstatusphp56-fpmphp56-fpm.service-PHPFastCGI进程管理器已加载:已加载(/usr/lib/systemd/system/php56-fpm.service;已启用;供应商预设:已启用)活动:活动(运行)自周二2018-05-0119:21:52CST;26s前MainPID:3353(php-fpm)CGroup:/system.slice/php56-fpm.service├─3353php-fpm:masterprocess(/usr/local/php56/etc/php-fpm.conf)├─3373php-fpm:池www├─3374php-fpm:池www├─3375php-fpm:池www├─3376php-fpm:池www├─3377php-fpm:池www├─3378php-fpm:池www├─3379php-fpm:池www├─3380php-fpm:池www├─3381php-fpm:池www└─3382php-fpm:poolwwwMay0119:21:52iZ23mzd9hi4Zsystemd[1]:StartedThePHPFastCGIProcessManager.May0119:22:05iZ23mzd9hi4Zsystemd[1]:StartedThePHPFastCGIProcessManager.查看php7的状态systemctl状态php-fpm●php-fpm.service-LSB:启动php-fpm已加载:已加载(/etc/init.d/php-fpm;坏;供应商预设:已启用)活动:活动(退出)自星期二2018-05-0114:47:03CST;4小时35分钟前文档:man:systemd-sysv-generator(8)May0114:47:01iZ23mzd9hi4Zsystemd[1]:StartingLSB:startsphp-fpm...May0114:47:03iZ23mzd9hi4Zphp-fpm[771]:启动php-fpmdoneMay0114:47:03iZ23mzd9hi4Zsystemd[1]:启动LSB:启动php-fpm。配置不同如果nginx站点使用不同的PHP版本,在/usr/local/nginx/conf下添加一个名为enable-php56.conf的文件,内容为location~[^/]\.php(/|$){try_files$uri=404;fastcgi_passunix:/tmp/php56-cgi.sock;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;服务器{听80;...包括enable-php56.conf;...}测试在每个域名目录下添加一个info.php文件测试
