1. 程式人生 > >,2018-2-28 10周1次課 PHP5、PHP7的安裝

,2018-2-28 10周1次課 PHP5、PHP7的安裝

php5 php7

11.10、11.11、1.12 安裝PHP5


[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
(過程省略)
[root@localhost php-5.6.30]# tar jxvf php-5.6.30.tar.bz2
[root@localhost src]# cd php-5.6.30/
[root@localhost src]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs 
--with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql 
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir 
--with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap 
--enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
(過程省略)

技術分享圖片

--prefix

指定安裝目錄


--with-apxs2

apache的工具,能讓不用人工幹涉,自動把擴展模塊放置到apache的module裏,並在配置文件裏加上load modules,httpd-M能把模塊加載


--with-config-file-path

指定配置文件所在路徑,php.ini


--with-mysql

--with-pdo-mysql

--with-mysqli

指定mysql的路徑,三種不同mysql的驅動

(老版本用--with-mysql,新版本用--with-mysqli,作用是一樣的)


--with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2

--with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

指定一些php的模塊(直接復制使用)


[root@localhost php-5.6.30]# make

(過程省略)

技術分享圖片

[root@localhost php-5.6.30]# make install

(過程省略)

技術分享圖片技術分享圖片

[root@localhost php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

二進制文件,/usr/local/php/bin/php


[root@localhost php-5.6.30]# /usr/local/php/bin/php -m(apache -M)
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]


[root@localhost php-5.6.30]# /usr/local/apache2.4/bin/httpd -M

技術分享圖片技術分享圖片

(php是作為httpd的擴展模塊的形式存在的)


·模塊文件:libphp5.so

[root@localhost php-5.6.30]# ll /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x. 1 root root 37752768 2月  28 23:19 /usr/local/apache2.4/modules/libphp5.so


·配置文件:

[root@localhost php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf

技術分享圖片技術分享圖片

配置文件httpd.conf中,可以看到php5模塊,不用則註釋掉,隨用隨取


[root@localhost php-5.6.30]# /usr/local/php/bin/php -i

可以查看配置參數、configuration file的路徑等

技術分享圖片技術分享圖片

[root@localhost php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini

技術分享圖片技術分享圖片



·安裝常見錯誤:

1,解決php編譯報錯configure: error: xml2-config not found. Please check your libxml2 installation

yum install -y libxml2-devel

2,解決php編譯報錯configure: error: Cannot find OpenSSL's <evp.h>

yum install -y openssl-devel

3,解決php編譯報錯configure: error: Please reinstall the BZip2 distribution

yum install -y bzip2-devel

4,解決php編譯報錯configure: error: jpeglib.h not found.

yum install -y libjpeg-devel

5,解決php編譯報錯configure: error: png.h not found.

yum install -y libpng-devel

6,解決php編譯報錯configure: error: freetype-config not found.

yum install -y freetype-devel

7,解決php編譯報錯configure: error: mcrypt.h not found. Please reinstall libmcrypt.

yum install -y epel-release(先安裝擴展源,mcrypt在擴展源中)

yum install -y libmcrypt-devel





11.13 安裝PHP7


[root@localhost php-5.6.30]# cd /usr/local/src/
[root@localhost src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
--2018-02-28 23:52:39--  http://cn2.php.net/distributions/php-7.1.6.tar.bz2
正在解析主機 cn2.php.net (cn2.php.net)... 123.125.23.171, 123.125.23.169, 123.125.23.168, ...
正在連接 cn2.php.net (cn2.php.net)|123.125.23.171|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:15732452 (15M) [application/octet-stream]
正在保存至: “php-7.1.6.tar.bz2”
100%[================================================================================================>] 15,732,452  9.45MB/s 用時 1.6s
2018-02-28 23:52:41 (9.45 MB/s) - 已保存 “php-7.1.6.tar.bz2” [15732452/15732452])
[root@localhost src]# tar jxvf php-7.1.6.tar.bz2
[root@localhost src]# cd php-7.1.6/
[root@localhost php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc  --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

(區別於PHP5:--prefix=/usr/local/php7,--with-config-file-path=/usr/local/php7/etc,沒有--with-mysql)

(過程省略)

技術分享圖片

[root@localhost php-7.1.6]# make && make install

(過程省略)

技術分享圖片


·PHP7模塊文件

[root@localhost php-7.1.6]# ll /usr/local/apache2.4/modules/libphp7.so
-rwxr-xr-x. 1 root root 38369056 3月   1 00:05 /usr/local/apache2.4/modules/libphp7.so


·PHP7加載的模塊:

[root@localhost php-7.1.6]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]


·apache加載了幾個PHP:

[root@localhost php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M

技術分享圖片技術分享圖片


·選擇使用的PHP:

技術分享圖片技術分享圖片

(用哪個就留著,不用哪一個就註釋掉)







,2018-2-28 10周1次課 PHP5、PHP7的安裝