全新CentOS安装 PHP7升级笔记

全新CentOS安装 PHP7升级笔记

PHP7已经到7.0.6版本了,是时候来尝试下小象飞的时候了,哈哈,那么就来配个PHP7的环境来玩玩...

更换时区

$ sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
$ ntpdate time.windows.com && hwclock -w

查看CentOS 版本

$ cat /etc/redhat-release
顺便看看linux环境内核、gcc信息
$ cat /proc/version

更换163 yum 源

  • 登录mirrors.163.com
  • 点击centos后面的“centos使用帮助”
  • $ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  • 下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份),我的是CentOS6
$ cd /etc/yum.repos.d/&&wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
$ yum clean all
$ yum makecache

升级gcc版本

  • 先升级到4.7版本
$ cd /etc/yum.repos.d
$ sudo wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo 
$ sudo yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++
$ mv /usr/bin/gcc /usr/bin/gcc-4.4.7
$ mv /usr/bin/g++ /usr/bin/g++-4.4.7
$ mv /usr/bin/c++ /usr/bin/c++-4.4.7
$ ln -s /opt/centos/devtoolset-1.1/root/usr/bin/gcc /usr/bin/gcc
$ ln -s /opt/centos/devtoolset-1.1/root/usr/bin/c++ /usr/bin/c++
$ ln -s /opt/centos/devtoolset-1.1/root/usr/bin/g++ /usr/bin/g++
$ gcc --version
  • 升级到4.8
$ cd /etc/yum.repos.d
$ wget http://people.centos.org/tru/devtools-2/devtools-2.repo
$ yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
$ mv /usr/bin/gcc /usr/bin/gcc-4.4.7
$ mv /usr/bin/g++ /usr/bin/g++-4.4.7
$ mv /usr/bin/c++ /usr/bin/c++-4.4.7
$ ln -s /opt/rh/devtoolset-2/root/usr/bin/gcc /usr/bin/gcc
$ ln -s /opt/rh/devtoolset-2/root/usr/bin/c++ /usr/bin/c++
$ ln -s /opt/rh/devtoolset-2/root/usr/bin/g++ /usr/bin/g++
$ gcc --version

安装先导库

$ yum install php-mcrypt libmcrypt libmcrypt-devel  libxml2-devel  openssl-devel  libcurl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64  libjpeg-turbo-devel   libmcrypt-devel   mysql-devel  -y

安装php7

  • 下载php7最新源码
$ cd ~&&wget http://cn2.php.net/distributions/php-7.0.6.tar.gz
  • 解压
$ tar zxvf php-7.0.6.tar.gz&&cd cd php-7.0.6
  • 编译安装
$ ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --enable-mysqlnd --with-gd --with-iconv --with-zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --with-curl --with-jpeg-dir --with-freetype-dir --with-mysqli --enable-embedded-mysqli  --with-pdo-mysql --with-config-file-scan-dir=/usr/local/php7/etc/conf.d
$make&&sudo make install
  • 建立软连接到/usr/local/bin/
$ sudo ln -s /usr/local/php7/bin/php* /usr/local/bin/
  • 配置php
    $ cp php.ini-production /usr/local/php7/etc/php.ini
    $ cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
    $ chmod +x /etc/init.d/php7-fpm
    $ cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
    $ cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
  • 加入opcache
 $ sudo vim /usr/local/php7/etc/conf.d/opcache.ini

加入: zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
参考:

[opcache]
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
; Determines if Zend OPCache is enabled 启用opcache
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP 在cli下启用opcache
opcache.enable_cli=1
; The OPcache shared memory storage size. opcache使用的内存,单位MB
opcache.memory_consumption=256
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed. 存储最大的对象数目
opcache.max_accelerated_files=100000
; The maximum percentage of "wasted" memory until a restart is scheduled. 最大浪费内存百分比,超出将会GC
opcache.max_wasted_percentage=5
; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
opcache.use_cwd=1
; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect. 验证文件改动时间错,开启之后将由validate_timestamps来提供刷新频率,对于加载文件很多的程序性能有极大影响,关闭之后将会杜绝验证文件的时候造成的抖动,但是更新文件之后需要手动重启服务或者刷新全部内容
opcache.validate_timestamps=0
; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate) 验证时间间隔,1表示1秒,0表示总是验证
opcache.revalidate_freq=5
; Enables or disables file search in include_path optimization
opcache.revalidate_path=1
; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code. 缓存中保存文档信息
opcache.save_comments=1
; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don't need them anyway. 加载文档信息
opcache.load_comments=1
  • 启动
$ sudo /etc/init.d/php7-fpm start
  • ==为了安全最好是去掉头信息 X-Powered-By: PHP/7.则修改 php.ini 文件 设置 expose_php = Off==
$ vim /usr/local/php7/etc/php.ini

找到 expose_php = On改为 expose_php = Off

安装redis扩展

  • 首先要安装依赖 igbinary
$ cd ~&&wget https://github.com/igbinary/igbinary7/archive/master.zip -O igbinary7.zip&&unzip igbinary7.zip&&cd igbinary7-master
$ phpize
$./configure
$ make&&sudo make install
$ cd /usr/local/php7/etc/conf.d/&&sudo cp opcache.ini igbinary.ini
$ vim igbinary.ini加入:extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/igbinary.so
  • 安装redis
    安装git

    $ sudo yum install git
    
  • 检出redis

$ git clone https://github.com/phpredis/phpredis.git
$ cd phpredis&&git branch -r
$ git branch --track php7 origin/php7
$ git checkout php7
$ phpize&&./configure --enable-redis-igbinary
$ make &&sudo make install
$ cd /usr/local/php7/etc/conf.d&&sudo cp igbinary.ini redis.ini
$ vim redis.ini加入:extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/redis.so

安装mongodb扩展

$ git clone https://github.com/mongodb/mongo-php-driver.git &&cd mongo-php-driver
$ git submodule sync && git submodule update --init
$ phpize
$ ./configure --with-php-config=/usr/local/php7/bin/php-config
$ make all -j 5&& sudo make install
$ cd /usr/local/php7/etc/conf.d&&sudo cp redis.ini mongodb.ini
$ vim  mongodb.ini加入:extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/mongodb.so 

安装mamcache扩展

  • 检出git仓库
$ git clone git clone https://github.com/websupport-sk/pecl-memcache.git
$ cd pecl-memcache&git branch -r
$ git branch --track php7 origin/php7
$ git checkout php7
$ phpize
$ ./configure&&make
$ sudo make install
$ cd /usr/local/php7/etc/conf.d&&sudo cp redis.ini memcache.ini
$ sudo vim  memcache.ini加入:extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/memcache.so 

安装mamcached扩展

  • 源码安装libmemcached
$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz&&tar zxvf libmemcached-1.0.18.tar.gz
$ cd libmemcached-1.0.18
$ ./configure --prefix=/usr/local/libmemcached --enable-sasl
$make && sudo make install
  • 检出git仓库
$ git clone https://github.com/php-memcached-dev/php-memcached.git
$ cd php-memcached&&git checkout php7 orgin/php7&&git pull
$ phpize
$ ./configure --with-libmemcached-dir=/usr/local/libmemcached
$ sudo make &&make install
$ cd /usr/local/php7/etc/conf.d&&sudo cp memcache.ini memcached.ini
$ sudo vim  memcached.ini加入:extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/memcached.so  

安装apcu扩展

$ wget https://github.com/krakjoe/apcu/archive/v5.1.4.zip -O apcu-v5.1.4.zip&&unzip apcu-v5.1.4.zip&& cd apcu-5.1.4/
$ php phpize&& ./configure
$ make&&&&sudo make install
$ cd /usr/local/php7/etc/conf.d&&sudo cp redis.ini apcu.ini
$ sudo vim  apcu.ini
加入:
extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/apcu.so
[apcu]
apc.enabled=1
apc.shm_segments=1
apc.shm_size=64M
apc.ttl=0
apc.enable_cli=1apcu.so  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容