实验环境
操作系统:Ubuntu 16.04.1 LTS
在安装PHP之前先确保系统是否安装了make和gcc两个编译工具
apt-get install make
apt-get install gcc
apt-get install autoconf
参考文章
https://www.cnblogs.com/rnckty/p/5741859.html
先安装函数库
apt-get install libxml2-dev
apt-get install build-essential
apt-get install openssl
apt-get install libssl-dev
apt-get install curl
apt-get install libcurl4-gnutls-dev
apt-get install libjpeg-dev
apt-get install libpng-dev
apt-get install libmcrypt-dev
apt-get install libreadline6 libreadline6-dev
apt-get-y install libfreetype6-dev
查看
find / -name libssl.so
输出
/usr/lib/x86_64-linux-gnu/libssl.so
然后重新连接一下,可以避免错误 configure: error: Cannot find OpenSSL's libraries
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
PHP安装
根目录下新建文件夹 tools,在其中下载PHP的源文件
wget http://cn2.php.net/distributions/php-7.2.10.tar.gz
解压源文件
tar -xvf php-7.2.10.tar.gz
进入php文件夹
cd php-7.2.10
配置PHP安装参数
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --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 --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
执行make 和 sudo make install 安装
make && sudo make install
复制 php.ini 文件
cp php.ini-development /usr/local/php/etc/php.ini
验证php
/usr/local/php/bin/php -v
环境变量
sudo vim /etc/profile
添加路径
export PATH=/usr/local/php/bin:$PATH
使添加的环境变量马上生效
source /etc/profile
--------------------------------------------------------------------------------------------
配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
user = www
group = www
如果www用户不存在,那么先添加www用户
groupadd www
useradd -g www www
启动php-fpm
sudo /usr/local/php/sbin/php-fpm