PHP生成环境编译、安装及配置

文章目录
  1. 1. PHP源码及扩展编译
    1. 1.1. php 7.0.9源码下载
    2. 1.2. configure
    3. 1.3. make&make install
    4. 1.4. 修改环境变量
  2. 2. yac
  3. 3. memcached
    1. 3.1. memcached安装
    2. 3.2. libmemcache: 本地memecached客户端
    3. 3.3. igbinary: 序列化扩展
    4. 3.4. php-memcached扩展
  4. 4. Redis
    1. 4.1. 安装Redis服务
    2. 4.2. php-redis扩展
  5. 5. Nginx/openrest

新部署腾讯云开发环境, 记录分享。
PHP生产环境配置:PHP7, Openresty, Memcached, Redis

PHP源码及扩展编译

php 7.0.9源码下载

请自行前往php.net/downloads下载。

configure

编译安装错误及解决参考:
PHP编辑错误
PHP编译过程中常见错误信息的解决方法
配置命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
./configure --prefix=/home/work/php70 --with-curl=shared \
--with-fpm-user=work --with-fpm-group=work \
--with-pdo-mysql=shared --with-mysqli=shared \
--with-mcrypt=shared --with-mhash=shared \
--enable-gd-native-ttf=shared --with-gd=shared \
--with-zlib=shared --with-pcre-regex --with-openssl=shared \
--with-enchant=shared --with-recode=shared --with-snmp=shared \
--with-tidy=shared --with-libxml-dir=shared --with-xmlrpc=shared \
--with-xsl=shared --enable-wddx=shared --enable-pcntl \
--enable-bcmath=shared --enable-fpm -enable-zip=shared \
--enable-mysqlnd=shared --enable-soap=shared \
--enable-embedded-mysqli=shared --enable-mbstring=shared \
--enable-intl=shared --enable-dtrace --enable-phar \
--enable-zip=shared --enable-mbstring=shared \
--enable-soap=shared --enable-intl=shared

编译过程中错误信息如下,汇总需要安装的devel包:

1
2
3
4
5
6
7
# 添加epel
sudo yum install epel-release
sudo yum update
# 添加依赖包
sudo yum -y install systemtap-sdt-devel libxml2 libxml2-devel openssl-devel libcurl-devel \
enchant-devel libpng-devel libicu-devel libmcrypt-devel recode-devel net-snmp-devel \
libtidy-devel libxslt-devel autoconf

以下将可能出现错误及解决方案列述说明

  • 开启DTrace需要安装systemtap-sdt-devel
    错误信息:
    1
    2
    3
    4
    5
    checking whether to enable DTrace support... yes
    checking sys/sdt.h usability... no
    checking sys/sdt.h presence... no
    checking for sys/sdt.h... no
    configure: error: Cannot find sys/sdt.h which is required for DTrace support

解决方法:sudo yum install systemtap-sdt-devel
参考:PHP DTrace

  • 需要安装libxml2, libxml2-devel
    错误信息:
    1
    2
    checking for xml2-config path...
    configure: error: xml2-config not found. Please check your libxml2 installation.

解决方法:sudo yum install libxml2; sudo yum install libxml2-devel

  • 需要安装openssl-devel
    错误信息:
    1
    2
    3
    4
    5
    checking for Kerberos support... no
    checking whether to use system default cipher list instead of hardcoded value... no
    checking for RAND_egd... no
    checking for pkg-config... /usr/bin/pkg-config
    configure: error: Cannot find OpenSSL's <evp.h>

解决方法:sudo yum install openssl-devel

  • 需要安装libcurl-devel
    错误信息:
    1
    2
    3
    checking for cURL in default path... not found
    configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

解决方法:sudo yum install libcurl-devel

  • 需要安装enchant-devel
    错误信息:
    1
    2
    checking for ENCHANT support... yes, shared
    configure: error: Cannot find enchant

解决方法:sudo yum install enchant-devel

  • 需要安装libpng-devel
    错误信息:
    1
    2
    3
    4
    checking whether to enable JIS-mapped Japanese font support in GD... no
    If configure fails try --with-webp-dir=<DIR>
    If configure fails try --with-jpeg-dir=<DIR>
    configure: error: png.h not found.

解决方法:sudo yum install libpng-devel

  • 需要安装libicu-devel
    错误信息:
    1
    2
    3
    4
    checking for icu-config... no
    checking for location of ICU headers and libraries... not found
    configure: error: Unable to detect ICU prefix or no failed.
    Please verify ICU install prefix and make sure icu-config works.

解决方法:sudo yum install libicu-devel

  • 需要安装libmcrypt-devel
    错误信息:
    1
    2
    checking for mcrypt support... yes, shared
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:sudo yum install libmcrypt-devel

  • 需要安装recode-devel
    错误信息:
    1
    2
    checking for recode support... yes, shared
    configure: error: Can not find recode.h anywhere under yes /usr/local /usr /opt.

解决方法:sudo yum install recode-devel

  • 需要安装net-snmp-devel
    错误信息:
    1
    2
    3
    4
    checking for SNMP support... yes, shared
    checking OpenSSL dir for SNMP... no
    checking for net-snmp-config... no
    configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

解决方法:sudo yum install net-snmp-devel

  • 需要安装libtidy-devel
    错误信息:
    1
    2
    checking for TIDY support... yes, shared
    configure: error: Cannot find libtidy

解决方法:sudo yum install libtidy-devel

  • 需要安装libxslt-devel
    错误信息:
    1
    2
    checking for XSL support... yes, shared
    configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

解决方法:sudo yum install libxslt-devel

  • 需要安装autoconf
    错误信息:
    1
    2
    3
    4
    5
    6
    7
     work@VM_0_182_centos  ~/opt/yac > phpize
    Configuring for:
    PHP Api Version: 20151012
    Zend Module Api No: 20151012
    Zend Extension Api No: 320151012
    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

解决方法:sudo yum install autoconf

make&make install

修改环境变量

1
2
PATH=/home/work/bin/:$PATH
export PATH

yac

1
2
3
$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

memcached

memcached安装

1
2
3
4
5
wget https://memcached.org/files/memcached-1.4.29.tar.gz
sudo yum -y install libevent-devel
./configure --prefix=/usr/local/memcached
make
sudo make install

或者直接用yum方式安装

1
2
3
sudo yum -y install memcached
sudo service start memcached 启动服务
sudo systemctl enable memcached 设置开启启动服务

测试:telnet 127.0.0.1 11211,执行命令:stats

libmemcache: 本地memecached客户端

1
2
3
4
5
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
sudo yum install cyrus-sasl-devel
./configure prefix=/usr/local/libmemcached --enable-sasl
make
sudo make install

igbinary: 序列化扩展

1
2
3
4
5
6
git clone git@github.com:igbinary/igbinary.git
git checkout -b php7-dev-playground2 origin/php7-dev-playground2
phpize
./configure CFLAGS="-O2 -g" --enable-igbinary --with-php-config=/home/work/bin/php-config
make
sudo make install

php-memcached扩展

PHP使用memcached的扩展。

1
2
3
4
5
6
7
git clone git@github.com:php-memcached-dev/php-memcached.git
git checkout -b php7 origin/php7 拉取远程的origin/php7分支到本地Php7分支
phpize
./configure --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl \
--enable-memcached-igbinary --with-php-config=/home/work/bin/php-config
make
make install

Redis

安装Redis服务

1
2
3
sudo yum -y install redis
sudo systemctl start redis
sudo systemctl enable redis

php-redis扩展

php-redis是C开发的用于php访问redis的高效扩展,效率比predis更高。

1
2
3
4
5
git clone git@github.com:phpredis/phpredis.git
git co -b php7 origin/php7
phpize
./configure [--enable-redis-igbinary]
make && make install

Nginx/openrest

1
2
3
4
5
6
7
wget https://openresty.org/download/openresty-1.9.15.1.tar.gz
./configure --prefix=/home/work/nginx/\
--with-luajit\
--without-http_redis2_module \
--with-http_iconv_module
make
make install

配置nginx.conf和conf.d目录
web/op项目的config目录有nginx.conf和conf.d,以及php相关配置
注意:php.ini中yac内存分配大小不能超过物理内存大小。