安装依赖包
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
下载安装包
cd /usr/local/src wget https://www.php.net/distributions/php-7.1.22.tar.gz
解压
cd /usr/local/src tar -zxvf php-7.1.22.tar.gz
检查当前的环境是否满足要安装软件的依赖关系
cd cd /usr/local/src/php-7.1.31 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear --disable-phar --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl
—prefix=安装目录
—with-使用包名称[=包目录]
—enable-需要激活的功能编译安装
make make install
php.ini:php配置文件
cp php.ini-production /usr/local/php/etc/php.ini
php-fpm.conf:php-fpm配置文件
cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf
www.conf:配置用户文件
cd /usr/local/php/etc/php-fpm.d cp www.conf.default www.conf
启动php
/uer/local/php/sbin/php-fpm start #php-fpm启动命令 /uer/local/php/sbin/php-fpm stop #php-fpm停止命令 /uer/local/php/sbin/php-fpm restart #php-fpm重启命令 #查看是否已经成功启动PHP ps aux | grep php ps -ef | grep php ps -A | grep -i php
10.配置环境变量
vim /etc/profile #在文件最后添加一行内容:export PATH=$PATH:/usr/local/php/bin export PATH=$PATH:/usr/local/php/bin #保存并退出编辑器,然后执行source /etc/profile source /etc/profile #php命令查看php版本信息,如果有显示版本,说明配置成功 php -v
11.PHP扩展
扩展包可以先去php的ext文件夹中找 tar -xzvf 扩展包 cd 扩展包 phpize ./configure --with-php-config=/usr/local/php/bin/php-config