blog 服务器升级 php7

2016-06-02  本文已影响142人  akay_zhang

本文地址: http://www.akayzhang.com/article/2

转载请注明出处

把博客服务器升级到 php7,享受下 php7 带来的畅快感。

下载

由于php7已合到master,所以直接用主分支即可。

git clone https://github.com/php/php-src.git && cd php-src

生产configure文件

./buildconf

进行配置

./configure

--prefix=/apps/lib/php7 \

--exec-prefix=/apps/lib/php7 \

--bindir=/apps/lib/php7/bin \

--sbindir=/apps/lib/php7/sbin \

--includedir=/apps/lib/php7/include \

--libdir=/apps/lib/php7/lib/php \

--mandir=/apps/lib/php7/php/man \

--with-config-file-path=/apps/conf/php7 \

--with-mysql-sock=/var/lib/mysql/mysql.sock \

--with-mcrypt=/usr/include \

--with-mhash --with-openssl  \

--with-mysqli=/usr/bin/mysql_config \

--with-pdo-mysql=/usr \

--with-gd --with-iconv \

--with-zlib \

--enable-zip \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-soap \

--without-pear \

--with-gettext \

--enable-session \

--with-curl \

--with-jpeg-dir \

--with-freetype-dir \

--enable-opcache \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--without-gdbm \

--disable-fileinfo

/apps/lib/php7是我定义的php7安装路径,正常安装路径可以定义为/usr/local/php7

用--disable-fileinfo 原因是本人服务器内存只有512M,比较小,在编译的过程中内存不够哦用,会报错,如下:

cc: Internal error: Killed (program cc1)

所以添加了--disable-fileinfo,具体原因见https://bugs.php.net/bug.php?id=48809https://bugs.php.net/bug.php?id=48809,

还有一个方法就是增加虚拟内存来加大内存,这样会加大io,但是在解决编译内存过大的情况还是挺好的。

其中configure的各个配置参数的作用可通过

./configure --help

查看,如果要知道你mysql的各个目录来进行配置,可以通过这个命令查看

#如果mysql没有开启的话

mysql.server start

ps -ef | grep mysql

可以看到mysql的basedir,socket等目录,就可以配置--with-mysql-sock, --with-mysqli,--with-mysqli等参数。

root      976    1  0 10:48 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

mysql    1183  976  0 10:48 ?        00:00:19 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

编译安装

make && make install

配置文件

复制php配置文件

开发环境

cp php.ini-development /apps/conf/php7/php.ini

生产环境

cp  php.ini-production /apps/conf/php7/php.ini

添加redis扩展

由于博客用到redis,接下来安装php-redis扩展,redis目前没有官方稳定版,但是我所在的公司已经将开发版用于生产环境,没出现什么大问题。

git clone https://github.com/phpredis/phpredis.git

cd phpredis

git checkout -b php7 origin/php7

/usr/local/php7/bin/phpize

./configure --with-php-config=/usr/local/php7/bin/php-config

make

sudo make install

编辑php.ini 加上

[redis]

extension=redis.so

done

上一篇 下一篇

猜你喜欢

热点阅读