1. 程式人生 > >LAMP-安裝PHP 5/7

LAMP-安裝PHP 5/7

php

目前主流的php版本是5.6和7.1。和php 5相比,php 7對於性能的提升的很大的,對於自身的處理速度優化了很多,同時也改變了一些語法的使用。但由於很多軟件都是基於php 5的,因此php 5和7的安裝和配置都要熟練掌握。


安裝PHP 5

1、下載安裝包

[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
--2017-07-21 07:39:35--  http://cn2.php.net/distributions/php-5.6.30.tar.gz
正在解析主機 cn2.php.net (cn2.php.net)... 220.181.136.41, 220.181.136.30, 220.181.136.55, ...
正在連接 cn2.php.net (cn2.php.net)|220.181.136.41|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:19274631 (18M) [application/x-gzip]
正在保存至: “php-5.6.30.tar.gz”

100%[==============================================>] 19,274,631   518KB/s 用時 34s    

2017-07-21 07:40:10 (552 KB/s) - 已保存 “php-5.6.30.tar.gz” [19274631/19274631])

2、解壓壓縮包

[[email protected] src]# tar zxf php-5.6.30.tar.gz

3、配置php

[[email protected] src]# cd php-5.6.30
[[email protected] php-5.6.30]# ./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

在配置過程中,會遇到一個接一個的配置失敗,這裏需要耐心處理。

問題1:configure: error: xml2-config not found. Please check your libxml2 installation.

[[email protected] php-5.6.30]# yum install -y libxml2-devel

問題2:configure: error: Cannot find OpenSSL‘s <evp.h>

[[email protected] php-5.6.30]# yum install -y openssl-devel

問題3:configure: error: Please reinstall the BZip2 distribution

[[email protected] php-5.6.30]# yum install -y bzip2-devel

問題4:configure: error: jpeglib.h not found.

[[email protected] php-5.6.30]# yum install -y libjpeg-turbo-devel

問題5:configure: error: png.h not found.

[[email protected] php-5.6.30]# yum install -y libpng-devel

問題6:configure: error: freetype-config not found.

[[email protected] php-5.6.30]# yum install -y freetype-devel

問題7:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

[[email protected] php-5.6.30]# yum install -y libmcrypt-devel

處理完以上問題後,重新配置出現以下文本:

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

以上文本內容表示配置成功,如果不放心可以用“echo $?”確認下。

4、編譯與安裝

[[email protected] php-5.6.30]# make &&make install
[[email protected] php-5.6.30]# echo $?
0
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini

5、查看與驗證

[[email protected] php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 
37M	/usr/local/apache2.4/modules/libphp5.so
[[email protected] php-5.6.30]# cat /usr/local/apache2.4/conf/httpd.conf | grep -i php
LoadModule php5_module        modules/libphp5.so
[[email protected] php-5.6.30]# /usr/local/apache2.4/bin/httpd -M | tail -1
 php5_module (shared)

前幾章說過,php在LAMP架構裏的作用只是Apache用於與mysql之間通訊的橋梁。因此,只要apache2.4的modules文件裏有libphp5.so文件,且在配置文件裏有相應的配置即可。即使刪除php的安裝目錄也不會有太大的影響。


安裝PHP 7

1、下載安裝包

[[email protected] php-5.6.30]# cd /usr/local/src
[[email protected] src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

2、解壓壓縮包

[[email protected] src]# tar jxf php-7.1.6.tar.bz2 
tar (child): bzip2:無法 exec: 沒有那個文件或目錄
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[[email protected] src]# yum install -y bzip2
[[email protected] src]# tar jxf php-7.1.6.tar.bz2

3、配置php

[[email protected] src]# cd php-7.1.6
[[email protected] 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
[[email protected] php-7.1.6]# echo $?
0

4、編譯與安裝

[[email protected] php-7.1.6]# make &&make install
[[email protected] php-7.1.6]# echo $?
0

5、查看與驗證

[[email protected] php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so 
/usr/local/apache2.4/modules/libphp7.so
[[email protected] php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini
[[email protected] php-7.1.6]# cat /usr/local/apache2.4/conf/httpd.conf | grep -i php
LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so
[[email protected] php-7.1.6]# /usr/local/apache2.4/bin/httpd -M | tail -2
 php5_module (shared)
 php7_module (shared)


本文出自 “A man & A computer” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1951599

LAMP-安裝PHP 5/7