安裝PHP5和PHP7

[toc]php

安裝PHP5

擴展: php中mysql,mysqli,mysqlnd,pdo究竟是什麼 http://blog.csdn.net/u013785951/article/details/60876816 查看編譯參數 http://ask.apelearn.com/question/1295mysql

11.10~11.2 安裝PHP5

1.下載PHP5安裝包並解壓

[root@xavi ~]#  cd /usr/local/src/
[root@xavi src]# wget http://cn2.php.net/distributions/php-5.6.30.tar
[root@xavi src]# tar -xjf php-5.6.30.tar.bz2

這個路徑解壓處理雖然不報錯,可是沒有解壓過程,echo查看不報錯。==--由於這裏沒有-v==sql

2 配置安裝

[root@xavi src]# cd php-5.6.30/
[root@xavi 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

參數說明:apxs該文件是httpd的一個工具,自動將PHP擴展模塊添加到Httpd的module目錄文件; 這就是說PHP將會以一個模塊的形式和httpd幾個在一塊兒

–prefix=/usr/local/php 指定的安裝目錄; 
–with-apxs2=/usr/local/apache2.4/bin/apxs 該文件是Apache的一個工具,自動將PHP擴展模塊添加到Httpd的module目錄文件; 這就是說PHP將會以一個模塊的形式和httpd幾個在一塊兒
–with-config-file-path=/usr/local/php/etc 指定配置文件所在路徑; 
–with-mysql=/usr/local/mysql 指定mysql的路徑; 
–with-mysqli=/usr/local/mysql/bin/mysql_config 
–with-pdo-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config 上面兩項參數是指定相關mysql庫 
–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相關的一些模塊(通用)。

3 安裝可能會遇到的報錯

3.1 configure: error: Cannot find OpenSSL's <evp.h>

3.2 查看 yum list |grep -i OpenSSL

[root@xavi php-5.6.30]# echo $?
1
[root@xavi php-5.6.30]# yum list |grep OpenSSL

這裏注意大小寫問題 -iapache

[root@xavi php-5.6.30]# yum list |grep -i OpenSSL

mark

yum install -y opensll-devel

[root@xavi php-5.6.30]# yum install -y openssl-devel

繼續輸入./configure 配置內容json

configure: error: Please reinstall the BZip2 distribution
[root@xavi php-5.6.30]# yum install -y bzip2-devel

mark

3.3 configure: error: jpeglib.h not found.

[root@xavi php-5.6.30]# yum install -y libjpeg-devel

mark

繼續輸入./configure 配置內容vim

3.4 configure: error: png.h not found.

[root@xavi php-5.6.30]# yum install -y libpng-devel

3.5 configure: error: freetype-config not found

[root@xavi php-5.6.30]# yum install -y freetype-develsession

3.6 configure: error: mcrypt.h not found. Please reinstall libmcrypt.

由於mcrypt.h這個庫在epel-release這個擴展源裏面php7

[root@xavi php-5.6.30]# yum install epel-release

3.7 configure: error: mcrypt.h not found. Please reinstall libmcrypt.

[root@xavi php-5.6.30]# yum install -y libmcrypt-devel

顯示配置成功 markless

4.make && make install 能夠分兩步查看有無錯誤

mark

mark

5.查看下生產的文件/usr/local/php,其中bin/下的是核心文件

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

6.du-sh來對比php文件和apache文件,libphp5.so文件是鏈接php和apache的重要文件

[root@xavi php-5.6.30]# du -sh /usr/local/php/bin/php
36M	/usr/local/php/bin/php
[root@xavi php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so
37M	/usr/local/apache2.4/modules/libphp5.so

7.查看php加載的模塊有哪些:/usr/local/php/bin/php -m,這些都是靜態的模塊

[root@xavi php-5.6.30]# /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]

7.1 php做爲apache的模塊存在的,所以php 不須要啓動;

mark

8. 查看apache的模塊:/usr/local/apache2.4/bin/httpd -M

[root@xavi php-5.6.30]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::1d7a:ffe8:8235:a2a5. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)

8.1 php做爲apache的一個模塊存在的

mark

8.2 apache中關於php的模塊文件

[root@xavi php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x 1 root root 37752768 3月   2 13:02 /usr/local/apache2.4/modules/libphp

9.打開apache的配置文件,輸入/php5.so找到了增長的一行

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

mark

裏面有不少被#註解的LoadMoudle,須要使用時可將註釋去掉.dom

10.複製配置文件 cp php.ini-production /usr/local/php/etc/php.ini

php的參考配置文件
php.ini-production 生產環境用
php.ini-development 開發環境和測試環境下用

10.1查看php信息:/usr/local/php/bin/php -i |less

[root@xavi php-5.6.30]# /usr/local/php/bin/php -i |less

mark

10.2 查看ls /usr/local/php/etc沒有php.ini文件

[root@xavi php-5.6.30]# ls /usr/local/php/etc
pear.conf

拷貝過來

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

10.3 查看/usr/local/php/bin/php -i |less加載成功

mark

11.2 安裝PHP7

1.下載安裝包

[root@xavi php-5.6.30]# cd ..
[root@xavi src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

2.解壓:tar -jxvf php-7.1.6.tar.bz2

不加V的話不顯示解壓過程.

3.切換到php-7.1.6目錄下

安裝PHP-7

由於在安裝PHP5的時候全部依賴的庫文件以及安裝完,因此這次PHP7能夠直接安裝。

[root@xavi src]#  cd php-7.1.6

4.環境配置

[root@xavi 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

注:次數與PHP-5的主要差別就是沒有「--with-mysql」選項而是with-mysqli.

mark

5.make編譯和make install安裝

mark

6./usr/local/apache2.4/modules/libphp7.so

[root@xavi php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@xavi php-7.1.6]# du -sh !$
du -sh /usr/local/apache2.4/modules/libphp7.so
37M	/usr/local/apache2.4/modules/libphp7.so

7.查看php7的模塊:/usr/local/php7/bin/php -m

[root@xavi php-7.1.6]# /usr/local/php7/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
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]

8. 查看Apache加載的PHP模塊:php5_module (shared) php7_module (shared)

[root@xavi php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::1d7a:ffe8:8235:a2a5. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 .
 .
 .
 php5_module (shared)
 php7_module (shared)

9.此時Apache默認加載兩個PHP模塊,那麼爲了正常使用須要經過編輯Apache的配置文件來指定其工做時默認調用哪一個PHP模塊(註釋掉其中一個調用參數便可):

[root@xavi php-7.1.6]#  vim /usr/local/apache2.4/conf/httpd.conf

mark

相關文章
相關標籤/搜索