阿里云美国centos7 编译安装php 5.6.30
浏览数 187318
赞
(0)
centos系统版本如下:
# cat /proc/version
Linux version 3.10.0-693.2.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Sep 12 22:26:13 UTC 2017
# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
同样的系统,同样是阿里云的服务器,昨天在美国的服务器上安装PHP5.6.30使用这个方法,今天用在香港的服务器上用此方法安装就不行,安装到拷贝php-fpm和php-fpm.conf文件时找不到源文件,只能在网上找到另外一种方法安装php5.6.31,笔记在这里:http://www.weinidai.com/index.php/News/detail/id/179
在本教程中创建了用户组www 和用户www,我在实践中使用默认的用户组nobody也是可以的,没有创建用户和用户组,也不需要在php-fpm.conf中配置运行的用户。
环境准备
编译安装
##编译参数如下,如果使用默认的nobody运行,则把红色部分去掉
继续安装
##参数解释
""" 安装路径 """
--prefix=/usr/local/php56 \
""" php.ini 配置文件路径 """
--with-config-file-path=/usr/local/php56/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """
--with-readline
配置服务
环境变量
php-fpm sock文件权限设置
在编译php-fpm时,若没有指定fpm用户,在配置文件中也没有指定用户,则sock文件会由root(启动php-fpm的用户)创建,其权限是srw-rw----。
而nginx一般由nginx用户启动,会导致无法读取sock文件,造成nginx返回502错误。
nginx日志会记录错误如下:
[crit] 1663#0: *40 connect() to unix:/tmp/php-fpm.sock failed (13: Permission denied) while connecting to upstream
解决办法是在配置文件中指定listen用户。
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0666
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
改完后重启php-fpm即可。
# cat /proc/version
Linux version 3.10.0-693.2.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Sep 12 22:26:13 UTC 2017
# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
同样的系统,同样是阿里云的服务器,昨天在美国的服务器上安装PHP5.6.30使用这个方法,今天用在香港的服务器上用此方法安装就不行,安装到拷贝php-fpm和php-fpm.conf文件时找不到源文件,只能在网上找到另外一种方法安装php5.6.31,笔记在这里:http://www.weinidai.com/index.php/News/detail/id/179
在本教程中创建了用户组www 和用户www,我在实践中使用默认的用户组nobody也是可以的,没有创建用户和用户组,也不需要在php-fpm.conf中配置运行的用户。
环境准备
# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel # cd / # mkdir software # cd /software # wget http://cn2.php.net/distributions/php-5.6.30.tar.gz # tar zvxf php-5.6.30.tar.gz # cd php-5.6.30 # groupadd www # useradd -g www -s /sbin/nologin www |
编译安装
##编译参数如下,如果使用默认的nobody运行,则把红色部分去掉
./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-inline-optimization --disable-debug \ --disable-rpath --enable-shared --enable-opcache \ --enable-fpm --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-gettext \ --enable-mbstring \ --with-iconv \ --with-mcrypt \ --with-mhash \ --with-openssl \ --enable-bcmath \ --enable-soap \ --with-libxml-dir \ --enable-pcntl \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-sockets \ --with-curl --with-zlib \ --enable-zip \ --with-bz2 \ --with-readline |
继续安装
# make && make install ##如果需要重新安装 # make clean # make clean all # ./configure # make && make install |
##参数解释
""" 安装路径 """
--prefix=/usr/local/php56 \
""" php.ini 配置文件路径 """
--with-config-file-path=/usr/local/php56/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """
--with-readline
配置服务
#配置文件 # cp php.ini-development /usr/local/php/etc/php.ini #php-fpm 服务 # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm # chkconfig --add php-fpm # chkconfig php-fpm on # service php-fpm start |
环境变量
# vim /etc/profile PATH=$PATH:/usr/local/php/bin export PATH # source /etc/profile |
php-fpm sock文件权限设置
在编译php-fpm时,若没有指定fpm用户,在配置文件中也没有指定用户,则sock文件会由root(启动php-fpm的用户)创建,其权限是srw-rw----。
而nginx一般由nginx用户启动,会导致无法读取sock文件,造成nginx返回502错误。
nginx日志会记录错误如下:
[crit] 1663#0: *40 connect() to unix:/tmp/php-fpm.sock failed (13: Permission denied) while connecting to upstream
解决办法是在配置文件中指定listen用户。
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0666
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
改完后重启php-fpm即可。