怎样在Ubuntu上安装PHP5.6.*

2020年2月10日 | 分类: 【技术】

【安装】

依赖:

sudo apt-get update && sudo apt-get -y install openssl libssl-dev curl libbz2-dev libzip-dev libxpm-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libmcrypt-dev libmysql++-dev libxslt1-dev libc-client-dev libkrb5-dev libsodium-dev

安装:

参考:https://blog.csdn.net/a1010256340/article/details/79727323
参考:https://blog.csdn.net/moxioakong788/article/details/81744738

sudo apt-add-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php5.6-fpm -y

报错: add-apt-repository: command not found

sudo apt-get install software-properties-common -y

参考:https://askubuntu.com/questions/422975/e-package-python-software-properties-has-no-installation-candidate

安装扩展:

sudo apt-get install php5.6-common php5.6-mysql php5.6-sqlite3 php5.6-xml php5.6-imap php5.6-xmlrpc php5.6-mysql php5.6-pdo php5.6-phar php5.6-simplexml php5.6-curl php5.6-gd php5.6-intl php5.6-mbstring php5.6-zip php5.6-soap php5.6-mcrypt

【版本】

输入:

php -v

输出:

PHP 5.6.40-24+ubuntu18.04.1+deb.sury.org+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

【配置】

/etc/php/5.6/fpm/php.ini
/etc/php/5.6/fpm/php-fpm.conf
/etc/php/5.6/fpm/pool.d/www.conf

/run/php/php5.6-fpm.pid
/run/php/php5.6-fpm.sock

listen = /run/php/php5.6-fpm.sock
【备注】此处直接关联 nginx.conf

查看PHP安装路径:

find / -name php 

输出:

/run/php
/etc/php
/etc/cron.d/php
/etc/alternatives/php
/usr/lib/php
/usr/share/php
/usr/bin/php
/var/lib/php
/var/lib/dpkg/alternatives/php

查看PHP-fpm安装路径:

find / -name php-fpm

输出:

/var/opt/remi/php56/run/php-fpm
/var/opt/remi/php56/log/php-fpm
/opt/remi/php56/root/usr/sbin/php-fpm

查看 php.ini 路径:

find / -name php.ini

输出:

/etc/php/5.6/cli/php.ini
/etc/php/5.6/fpm/php.ini

【排错】

报错:502

编辑:/etc/php/5.6/fpm/pool.d/www.conf

listen.mode = 0666

修改权限:

chmod 0666 /etc/php/5.6/fpm/pool.d/www.conf

重启 php-fpm :

sudo service php5.6-fpm restart

报错:mysqli_real_connect(): (HY000/2002): No such file or directory

搜索 my.cnf :

find / -name my.cnf

输出:

/etc/my.cnf
/etc/mysql/my.cnf
/etc/alternatives/my.cnf
...

搜索 mysql.sock :

find / -name mysql.sock

输出:

/etc/my.cnf
/etc/mysql/my.cnf
/etc/alternatives/my.cnf
...

报错:session

编辑:/etc/php/5.6/fpm/php.ini

session.save_path = "/var/lib/php/sessions"

修改权限:

chown -R nginx:nginx /var/lib/php/sessions

修改 Nginx 下server参数:

参考 /etc/php/5.6/fpm/pool.d/www.conf

listen = /run/php/php5.6-fpm.sock

在 nginx.conf 中设置:

fastcgi_pass unix:/run/php/php5.6-fpm.sock;