专栏首页python33.安装PHP5和PHP7

3.安装PHP5和PHP7

[toc]

安装PHP5

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

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

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

参数说明:

–prefix=/usr/local/php 指定的安装目录; 
–with-apxs2=/usr/local/apache2/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相关的一些模块(通用)。

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

这里注意大小写问题 -i

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

yum install -y opensll-devel

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

继续输入./configure 配置内容

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

3.3 configure: error: jpeglib.h not found.

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

继续输入./configure 配置内容

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

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

因为mcrypt.h这个库在epel-release这个扩展源里面

[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

显示配置成功

4.make && make install 可以分两步查看有无错误

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的模块存在的

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的一个模块存在的

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

里面有很多被#注解的LaodMoudle,需要使用时可将注释去掉.

10. cp php.ini-production /usr/local/php/etc/php.ini

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

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

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加载成功

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.

5.make编译和make install安装

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • python3 selenium + f

    一、 分析: 抓取动态页面js加载的人民日报里面的新闻详情 https://wap.peopleapp.com/news/1 先打开,然后查看网页源码,发现是...

    py3study
  • python爬虫抓取电影天堂最新电影

    py3study
  • linux-php的编译安装3

    环境: Red Hat Enterprise Linux Server release 6.2 (Santiago) 内核: 2.6.32-220.el6.x...

    py3study
  • Linux基础(day41)

    11.10/11.11/11.12 安装PHP5 安装PHP5目录概要 PHP官网www.php.net 当前主流版本为5.6/7.1 cd /usr/loca...

    运维小白
  • 11.10/11.11/11.12 安装PHP5

    安装PHP5目录概要 PHP官网www.php.net 当前主流版本为5.6/7.1 cd /usr/local/src/ wget http://cn2.ph...

    运维小白
  • CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境

    http://www.osyunwei.com/archives/10003.html

    砸漏
  • Apache多虚拟主机多版本PHP(5.3+5.6+N)共存运行配置全过程

    常规的PHP配置方式有很多种,例如CGI、fast-cgi、apache module handle、cli、isapi这些。 CGI (通用网关接口 / Co...

    96php.cn
  • 最新抖音、快手、剪映、tiktok、西瓜、小红书在线去水印,去水印API接口

    Videoparse(https://www.videoparse.cn) 短视频解析接口已支持:抖音、快手、剪映、小红书、Tiktok(抖音国际版)、微博、Q...

    用户6798405
  • 【CentOS】Apache多虚拟主机多版本PHP(5.3+5.6+N)共存运行配置全过程

    Eller
  • 11.14/11.15 Apache和PHP结合

    配置httpd支持php目录概要 httpd主配置文件/usr/local/apache2.4/conf/httpd.conf vim /usr/local/a...

    运维小白

扫码关注云+社区

领取腾讯云代金券