[LAMP]安装PHP 5/7

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

       目前主流的php版本是5.6和7.1。和php 5相比,php 7对于性能的提升的很大的,对于自身的处理速度优化了很多,同时也改变了一些语法的使用。但由于很多软件都是基于php 5的,因此php 5和7的安装和配置都要熟练掌握。


安装PHP 5

1、下载安装包

1
2
3
4
5
6
7
8
9
10
11
[root@juispan src] # wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
--2017-07-21 07:39:35--  http: //cn2 .php.net /distributions/php-5 .6.30. tar .gz
正在解析主机 cn2.php.net (cn2.php.net)... 220.181.136.41, 220.181.136.30, 220.181.136.55, ...
正在连接 cn2.php.net (cn2.php.net)|220.181.136.41|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:19274631 (18M) [application /x-gzip ]
正在保存至: “php-5.6.30. tar .gz”
 
100%[==============================================>] 19,274,631   518KB /s  用时 34s    
 
2017-07-21 07:40:10 (552 KB /s ) - 已保存 “php-5.6.30. tar .gz” [19274631 /19274631 ])

2、解压压缩包

1
[root@juispan src] # tar zxf php-5.6.30.tar.gz

3、配置php

1
2
[root@juispan src] # cd php-5.6.30
[root@juispan 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

在配置过程中,会遇到一个接一个的配置失败,这里需要耐心处理。

问题1:configure: error: xml2-config not found. Please check your libxml2 installation.

1
[root@juispan php-5.6.30] # yum install -y libxml2-devel

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

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

问题3:configure: error: Please reinstall the BZip2 distribution

1
[root@juispan php-5.6.30] # yum install -y bzip2-devel

问题4:configure: error: jpeglib.h not found.

1
[root@juispan php-5.6.30] # yum install -y libjpeg-turbo-devel

问题5:configure: error: png.h not found.

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

问题6:configure: error: freetype-config not found.

1
[root@juispan php-5.6.30] # yum install -y freetype-devel

问题7:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

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

处理完以上问题后,重新配置出现以下文本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Generating files
configure: creating . /config .status
creating main /internal_functions .c
creating main /internal_functions_cli .c
+--------------------------------------------------------------------+
| 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

以上文本内容表示配置成功,如果不放心可以用“echo $?”确认下。

4、编译与安装

1
2
3
4
[root@juispan php-5.6.30] # make &&make install
[root@juispan php-5.6.30] # echo $?
0
[root@juispan php-5.6.30] # cp php.ini-production /usr/local/php/etc/php.ini

5、查看与验证

1
2
3
4
5
6
[root@juispan php-5.6.30] # du -sh /usr/local/apache2.4/modules/libphp5.so 
37M  /usr/local/apache2 .4 /modules/libphp5 .so
[root@juispan php-5.6.30] # cat /usr/local/apache2.4/conf/httpd.conf | grep -i php
LoadModule php5_module        modules /libphp5 .so
[root@juispan php-5.6.30] # /usr/local/apache2.4/bin/httpd -M | tail -1
  php5_module (shared)

前几章说过,php在LAMP架构里的作用只是Apache用于与mysql之间通讯的桥梁。因此,只要apache2.4的modules文件里有libphp5.so文件,且在配置文件里有相应的配置即可。即使删除php的安装目录也不会有太大的影响。


安装PHP 7

1、下载安装包

1
2
[root@juispan php-5.6.30] # cd /usr/local/src
[root@juispan src] # wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

2、解压压缩包

1
2
3
4
5
6
7
[root@juispan src] # tar jxf php-7.1.6.tar.bz2 
tar  (child):  bzip2 :无法  exec : 没有那个文件或目录
tar  (child): Error is not recoverable: exiting now
tar : Child returned status 2
tar : Error is not recoverable: exiting now
[root@juispan src] # yum install -y bzip2
[root@juispan src] # tar jxf php-7.1.6.tar.bz2

3、配置php

1
2
3
4
[root@juispan src] # cd php-7.1.6
[root@juispan 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
[root@juispan php-7.1.6] # echo $?
0

4、编译与安装

1
2
3
[root@juispan php-7.1.6] # make &&make install
[root@juispan php-7.1.6] # echo $?
0

5、查看与验证

1
2
3
4
5
6
7
8
9
[root@juispan php-7.1.6] # ls /usr/local/apache2.4/modules/libphp7.so 
/usr/local/apache2 .4 /modules/libphp7 .so
[root@juispan php-7.1.6] # cp php.ini-production /usr/local/php7/etc/php.ini
[root@juispan php-7.1.6] # cat /usr/local/apache2.4/conf/httpd.conf | grep -i php
LoadModule php5_module        modules /libphp5 .so
LoadModule php7_module        modules /libphp7 .so
[root@juispan php-7.1.6] # /usr/local/apache2.4/bin/httpd -M | tail -2
  php5_module (shared)
  php7_module (shared)














本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1951599 ,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
运维 Unix Linux
Linux系统 PHP安装expect扩展详解
Linux系统 PHP安装expect扩展详解
39 5
|
4月前
|
应用服务中间件 PHP nginx
|
7月前
|
Apache PHP 数据安全/隐私保护
(MAC)PHP Apache 安装与配置
(MAC)PHP Apache 安装与配置
220 0
|
7月前
|
关系型数据库 MySQL Unix
PHP MySql 安装与连接
PHP MySql 安装与连接
125 0
|
7月前
|
算法 PHP 数据安全/隐私保护
【实战】php goto解密工具,无需安装php环境,直接解密
php goto解密方法,php解密工具,goto解密,php微擎解密,代码可读性,代码可维护性
385 1
|
8月前
|
关系型数据库 MySQL PHP
PHP服务环境配置之 WampServer的安装与环境配置
PHP服务环境配置之 WampServer的安装与环境配置
322 0
|
4月前
|
Linux 应用服务中间件 PHP
Linux下搭建PHP环境-源码编译安装PHP7.2
Linux下搭建PHP环境-源码编译安装PHP7.2
148 0
|
25天前
|
运维 Linux Apache
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
197 2
|
8月前
|
IDE NoSQL 关系型数据库
开发php,需要安装哪些工具
开发php,需要安装哪些工具
|
8月前
|
消息中间件 NoSQL 关系型数据库
Linux安装 OpenResty、Nginx、PHP、Mysql、Redis、Lua、Node、Golang、MongoDB、Kafka等
Linux安装 OpenResty、Nginx、PHP、Mysql、Redis、Lua、Node、Golang、MongoDB、Kafka等
103 0