分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

安装PHP5

发布时间:2023-09-06 01:44责任编辑:沈小雨关键词:PHP
11.10-11.12 安装PHP5

PHP(Hypertext Preprocessor)英文超级文本预处理语言。PHP 是一种HTML内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言。官网:www.php.net.

准备工作

准备安装包

下载:
[root@centos-01 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz ?

解压:
[root@centos-01 src]# tar zxvf php-5.6.30.tar.gz
安装PHP-5

[root@centos-01 src]# cd php-5.6.30/
环境配置

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

#参数解析:
--prefix=/usr/local/php 指定安装目录
--with-apxs2=/usr/local/apache2.4/bin/apxs 该文件是Apache的一个工具,可以将扩展模块添加到Apache的module文件。
--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相关的一些模块(通用)。
报错:
错误1:

configure: error: xml2-config not found. Please check your libxml2 installation.
说明:缺少xml2库。
解决办法:

查找相关的库安装包:
[root@centos-01 php-5.6.30]# yum list |grep libxml2

安装库文件:
[root@centos-01 php-5.6.30]# yum install -y libxml2-devel
错误2:

configure: error: Cannot find OpenSSL‘s <evp.h>
说明:缺少OpenSSL‘s。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y openssl-devel
错误3:

configure: error: Please reinstall the BZip2 distribution
说明:重新安装BZip2。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y bzip2-devel
错误4:

configure: error: jpeglib.h not found.
说明:缺少jpeg库。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y libjpeg-devel
错误5:

configure: error: png.h not found.
说明:缺少png库。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y libpng-devel
错误6:

configure: error: freetype-config not found.
说明:缺少freetype库。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y freetype-devel
错误7:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
说明:缺少mcrypt库。
解决办法:

[root@centos-01 php-5.6.30]# yum install -y libmcrypt-devel
+--------------------------------------------------------------------+
| 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.
环境配置完成!

编译和安装

编译:
[root@centos-01 php-5.6.30]# make
[root@centos-01 php-5.6.30]# echo $?
0

安装:
[root@centos-01 php-5.6.30]# make install
[root@centos-01 php-5.6.30]# echo $?
0
安装完成!

PHP工作原理

将PHP的配置文件移动到./configure时指定的目录:

[root@centos-01 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
PHP在系统中是作为Apache的一个模块被调用的,所以不用执行名启动该PHP。

查看Apache的模块:

/usr/local/apache2.4/bin/apachectl -M

……dir_module (shared)
alias_module (shared)
php5_module (shared)
说明: 安装完成PHP后会在Apache中自动添加相应模块,同时在Apache配置文件/usr/local/apache2.4/conf/httpd.conf中也会自动添加相应配置内容。

[root@centos-01 php-5.6.30]# vim /usr/local/apache2.4/conf/httpd.conf
如下图所示:

mark

11.13 安装PHP7

准备工作

安装包

下载:
[root@centos-01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

解压:
[root@centos-01 src]# tar -jxvf php-7.1.6.tar.bz2 ?
安装PHP-7

因为在安装PHP5的时候所有依赖的库文件以及安装完,所以此次PHP7可以直接安装。

切换到目录php-7.1.6:

[root@centos-01 src]# cd php-7.1.6
环境配置

[root@centos-01 src]# ?./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”选项。 ?
编译

[root@centos-01 php-7.1.6]# make
注:编译完成后可以使用“echo $?”或“make test”命令检测编译是否存在错误。

安装

[root@centos-01 php-7.1.6]# make install
工作原理

将PHP的配置文件移动到./configure时指定的目录:

[root@centos-01 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
查看Apache加载的PHP模块:

[root@centos-01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
……
php5_module (shared)
php7_module (shared)
此时Apache默认加载两个PHP模块,那么为了正常使用需要通过编辑Apache的配置文件来指定其工作时默认调用哪个PHP模块(注释掉其中一个调用参数即可):

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

安装PHP5

原文地址:http://blog.51cto.com/13242922/2074134

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved