安装PHP5

安装PHP5

下载PHP5.6的压缩包(下载到/usr/local/src/)

[root@shuai-01 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2

解压缩:

[root@shuai-01 src]# tar -jxvf php-5.6.30.tar.bz2

编译PHP5:

 ./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=/usr/local/php 指定安装目录 
–with-apxs2=/usr/local/apache2.4/bin/apxs apache的工具,作用:不用人工去写,自动的把扩展模块放到Apache的modules下,并且在配置文件写东西,自动配置上 
–with-config-file-path=/usr/local/php/etc 指定配置文件(php.ini)所在路径 
–with-mysql=/usr/local/mysql –with-pdo-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config 三种不同MySQL的驱动或者库(PHP5 用–with-mysql PHP7 用 –with-mysqli )

在编译的过程中,可能会出现很多错误,错误主要是没安装一些库,少啥装啥

当看到这个时,说明编译已经完成

+--------------------------------------------------------------------+
| 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

[root@shuai-01 php-5.6.30]# echo $?
0

接着就是make

[root@shuai-01 php-5.6.30]# make
[root@shuai-01 php-5.6.30]# echo $?
0

再接着就是make install

[root@shuai-01 php-5.6.30]# make install

把配置文件拷贝到自己编译时定义的配置文件路径中

查看PHP的配置信息,编译参数,配置文件的环境,配置文件路径。

/usr/local/php/bin/php -i

phpinfo()
PHP Version => 5.6.30

System => Linux shuai-01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Dec 18 2017 19:28:42
Configure Command =>  './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'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc

Loaded Configuration File => (none)

Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20131106

拷贝php.ini到指定的路径(/usr/local/php/etc):

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

接着在查看PHP配置信息:

phpinfo()
PHP Version => 5.6.30

System => Linux shuai-01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Dec 18 2017 19:28:42
Configure Command =>  './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'
Server API => Command Line Interface
Virtual Directory Support => enabled

Loaded Configuration File => /usr/local/php/etc/php.ini

Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20131106

规定的配置文件有两个,php.ini-production(生产环境),php.ini-development(测试或开发环境)

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

PHP和Apache结合是通过/usr/local/apache2.4/modules/libphp5.so这个文件,也就是说我们安装编译了半天就是为了得到libphp5.so这个模块

查看PHP加载的模块(全部都是静态的):

[root@shuai-01 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]

PHP不需要启动,因为它就是Apache的模块。

[root@shuai-01 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::4f59:7251:18f1:8716. 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)

出现了php5_module

查看Apache的配置文件(/usr/local/apache2.4/conf/httpd.conf),有一个php5_module

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

#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so

问题1:

checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

这个是缺少libxml2-devel

[root@shuai-01 php-5.6.30]# yum install -y libxml2-devel

安装完后再编译

问题2:

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

这个是缺少openssl-devel

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

问题3 :

configure: error: Please reinstall the BZip2 distribution

少了bzip2-devel

[root@shuai-01 php-5.6.30]# yum install -y bzip2-devel

问题4:

If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

少了libjpeg-turbo-devel

[root@shuai-01 php-5.6.30]# yum install -y libjpeg-turbo-devel

问题5 :

checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

少了libpng-devel

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

问题6 :

If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

少了freetype-devel

问题6 :

checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

少了libmcrypt-devel, 这个包是在epel-release 扩展源里,先安装扩展源

[root@shuai-01 php-5.6.30]# yum install epel-release
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
软件包 epel-release-7-11.noarch 已安装并且是最新版本
无须任何处理
[root@shuai-01 php-5.6.30]# yum install -y libmcrypt-devel
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值