全新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閱讀 230,048評論 6 542
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,414評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,169評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,722評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,465評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,823評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,813評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,000評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,554評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,295評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,513評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,035評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,722評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,125評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,430評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,237評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,482評論 2 379

推薦閱讀更多精彩內容