关注小众语言,记录、分享技术点滴!

0%

centos下安装php7

编译安装 php-fpm
1.下载php7

1
2
3
wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.13.tar.gz/from/this/mirror
tar -zxvf php7.tar.gz
cd php-7.0.13

2.安装依赖包

1
yum install gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

3.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

4.正式安装

1
make && make install

5.配置环境变量

1
2
3
cat >> /etc/profile<<EOF
export PATH=$PATH:/usr/local/php/bin
EOF

6.导入环境变量

1
source /etc/profile

7.配置php-fpm

1
2
3
4
5
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

8.启动php-fpm

1
/etc/init.d/php-fpm start

安装完成

ps:
有2种方式可以找到之前的编译参数:
1.在源码 /lamp/php-5.4.11/中找到 config.nice,这个就是之前的编译参数
2.去掉enable-gd-jis-conv编译参数,引起imagettftext()中文乱码问题
3.在php.ini配置文件中找到Configure相关的配置 :

1
/usr/local/php/bin/php -i |grep 'Configure'