11.13 安装PHP7

时间:2022-04-27
本文章向大家介绍11.13 安装PHP7,主要内容包括安装PHP7目录概要、安装过程php7、小知识(安装两个php)、查看PHP7的文件、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

安装PHP7目录概要

  • cd /usr/local/src/
  • wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
  • tar zxf php-7.1.6.tar.bz2
  • cd 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
  • make && make install
  • ls /usr/local/apache2.4/modules/libphp7.so
  • cp php.ini-production /usr/local/php7/etc/php.ini

安装过程php7

  1. 首先切换到/usr/local/src/目录下
[root@hf-01 php-5.6.30]# cd /usr/local/src/
[root@hf-01 src]# 
  1. 然后下载PHP7.1版本安装包
[root@hf-01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
  1. 查看PHP7安装包,并解压
[root@hf-01 src]# ls
apr-1.6.3               mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-1.6.3.tar.gz        mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
apr-util-1.6.1          php-5.6.30
apr-util-1.6.1.tar.bz2  php-5.6.30.tar.gz
httpd-2.4.29            php-7.1.6.tar.bz2
httpd-2.4.29.tar.gz
[root@hf-01 src]# tar jxvf php-7.1.6.tar.bz2    //解压php7.1版本
  1. 进入到PHP7的源码包目录下/usr/local/src/php-7.1.6/
[root@hf-01 src]# cd php-7.1.6/
[root@hf-01 php-7.1.6]# 
  1. 初始化配置
    • 这里php7和php5的区别
      • --prefix=/usr/local/php7这里定义的目录名字是php7
      • --with-config-file-path=/usr/local/php7/etc这里定义的配置文件路径是php7
      • 这里只有--with-mysqli,没有--with-mysql,而其他的都类似
[root@hf-01 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
  1. 在初始化配置完成后,然后make && make install
[root@hf-01 php-7.1.6]# make && make install
  1. 这样php7.1就安装成功了

小知识(安装两个php)

  • 一台机器上安装两个php,两个PHP是可以同时存,但是Apache调用PHP的时候,需要指定好,在——> vim /usr/local/apache2.4/conf/httpd.conf 里面指定使用哪一个PHP即可

查看PHP7的文件

  • 查看libphp7和5是不同的,/usr/local/apache2.4/modules/libphp7.so
[root@hf-01 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@hf-01 php-7.1.6]# du -sh !$        //查看php7大小
du -sh /usr/local/apache2.4/modules/libphp7.so
37M	/usr/local/apache2.4/modules/libphp7.so
[root@hf-01 php-7.1.6]# 
  1. 查看php7所加载的模块,/usr/local/php7/bin/php -m,和php5基本是一致的
[root@hf-01 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]

[root@hf-01 php-7.1.6]# 
  1. 查看Apache加载了几个php
    • 会看到加载了php5和php7
[root@hf-01 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 192.168.0.104. 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)
 php7_module (shared)
[root@hf-01 php-7.1.6]# 
  1. 若想去使用哪一个PHP,根据自己的实际需求
[root@hf-01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

搜索php5.so,会看到有两行
LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so

想使用哪个php,就在另一个前面加 # 号注释掉,然后保存