首先推薦一篇文章php 7 release date arrived: will developers adopt php 7? - php classes blog。
里面說到是否會(huì)去使用php7,就個(gè)人而言,我是毫不猶豫地使用的,但是生產(chǎn)環(huán)境就不是我說了算,所以只能自己在自己的開發(fā)環(huán)境里更新php的版本。那么,你呢?
筆者使用的是linux的opensuse42.1發(fā)行版,yast里面還沒有php7的安裝包,于是乎只能自己手動(dòng)編譯安裝了。作為一個(gè)php開發(fā)者,我是非常希望能夠?qū)W會(huì)編譯安裝php7的,之前試過幾次,但是每次安裝都要上網(wǎng)找各種資料,于是乎,這次安裝成功后就想把自己的安裝過程以及遇到的問題記錄下來,方便以后查閱和分享給需要的人。
下載源碼并解壓
進(jìn)入正題,要編譯安裝php7,首先當(dāng)然要下載php7的源碼。你可以到github上clone,也可以到php官網(wǎng)下載。下載后解壓到 /usr/local/src 目錄,并將目錄重命名為php7。進(jìn)入目錄。
配置編譯參數(shù)
生成配置文件
./buildconf
配置
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
|
./configure --prefix=/usr/local/php7 -- exec -prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/ include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/ var /run/mysql/mysql.sock --with-mcrypt=/usr/ include --with-mhash --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --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 --disable-cgi --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo |
參數(shù)說明
prefix php7安裝的根目錄
with-config-file-path php7的配置文件目錄
執(zhí)行完上面的配置命令后的結(jié)果如下圖所示:
執(zhí)行上面命令的過程中會(huì)遇到一些依賴缺少的提示,下面列出我遇到的依賴問題:
錯(cuò)誤:
configure: error: xml2-config not found. please check your libxml2 installation.
解決:
zypper install libxml2-devel
錯(cuò)誤:
configure: warning: unrecognized options: --with-mysql
解決:
取消這個(gè)選項(xiàng),這個(gè)選項(xiàng)是不存在的
錯(cuò)誤:
configure: error: jpeglib.h not found.
解決:
zypper install libjpeg-devel
錯(cuò)誤:
configure: error: mcrypt.h not found. please reinstall libmcrypt.
解決:
zypper install libmcrypt-devel
錯(cuò)誤:
checking for recode support... yes
configure: error: can not find recode.h anywhere under /usr /usr/local /usr /opt.
解決:
zypper install librecode-devel
總的來說,在配置的時(shí)候遇到?jīng)]有的就打開yast搜一下,如果有的話就安裝,然后重新編譯看還需要那些,如果在yast找不到,那就上網(wǎng)找一下google。
編譯和安裝php7
make && make install
其中,make之后可以選擇make test。只是一個(gè)可選步驟,不執(zhí)行不知道有什么問題,不過筆者暫時(shí)還沒遇到。
查看安裝成功后的php7目錄
編譯安裝成功后,查看php7的安裝目錄`ls /usr/local/php7`:
設(shè)置php7的配置文件
cp /usr/local/src/php7/php.ini-production /usr/local/php7/etc/php.ini
cp /usr/local/src/sapi/fpm/init.d.php-fpm /etc/init.d/php-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
設(shè)置環(huán)境變量
在/etc/profile 文件的最后一行加上
export path=/usr/local/php7/bin:/usr/local/php7/sbin:$path
然后執(zhí)行 source /etc/profile
設(shè)置php日志目錄和php-fpm進(jìn)程文件(php-fpm.sock)目錄
mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -r nginx:nginx php-fpm
將php設(shè)置為開機(jī)啟動(dòng)
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
可以用chkconfig命令查看開機(jī)啟動(dòng)服務(wù)列表。
啟動(dòng)php服務(wù)
service php-fpm start
通過ps aux | grep 'php'查看php是否啟動(dòng)成功
至此,php7就安裝成功了,你也開始使用php7吧!
以上所述給大家介紹了在opensuse42.1下編譯安裝php7 的方法,希望大家喜歡。