LAMP-安装PHP 5/7

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

安装PHP 5

1、下载安装包

[[email protected] 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、解压压缩包

[[email protected] src]# tar zxf php-5.6.30.tar.gz

3、配置php

[[email protected] src]# cd php-5.6.30
[[email protected] 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.

[[email protected] php-5.6.30]# yum install -y libxml2-devel

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

[[email protected] php-5.6.30]# yum install -y openssl-devel

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

[[email protected] php-5.6.30]# yum install -y bzip2-devel

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

[[email protected] php-5.6.30]# yum install -y libjpeg-turbo-devel

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

[[email protected] php-5.6.30]# yum install -y libpng-devel

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

[[email protected] php-5.6.30]# yum install -y freetype-devel

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

[[email protected] php-5.6.30]# yum install -y libmcrypt-devel

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

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、编译与安装

[[email protected] php-5.6.30]# make &&make install
[[email protected] php-5.6.30]# echo $?
0
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini

5、查看与验证

[[email protected] php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 
37M	/usr/local/apache2.4/modules/libphp5.so
[[email protected] php-5.6.30]# cat /usr/local/apache2.4/conf/httpd.conf | grep -i php
LoadModule php5_module        modules/libphp5.so
[[email protected] 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、下载安装包

[[email protected] php-5.6.30]# cd /usr/local/src
[[email protected] src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

2、解压压缩包

[[email protected] 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
[[email protected] src]# yum install -y bzip2
[[email protected] src]# tar jxf php-7.1.6.tar.bz2

3、配置php

[[email protected] src]# cd php-7.1.6
[[email protected] 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
[[email protected] php-7.1.6]# echo $?
0

4、编译与安装

[[email protected] php-7.1.6]# make &&make install
[[email protected] php-7.1.6]# echo $?
0

5、查看与验证

[[email protected] php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so 
/usr/local/apache2.4/modules/libphp7.so
[[email protected] php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini
[[email protected] 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
[[email protected] php-7.1.6]# /usr/local/apache2.4/bin/httpd -M | tail -2
 php5_module (shared)
 php7_module (shared)
时间: 2025-02-01 12:03:16

LAMP-安装PHP 5/7的相关文章

HHvm建站环境搭建方法:Nginx,Mariadb,hhvm及lnmp/lamp安装部署 | 免费资源部落

HHvm建站环境搭建方法:Nginx,Mariadb,hhvm及lnmp/lamp安装部署 | 免费资源部落 nginx对redis取数据的不同方式 - 守望

LAMP安装各种问题解决方案

LAMP环境配置安装注意安装步骤及说明事项. LAMP安装各种问题解决 1. 访问ftp报错 解决: 关闭selinux vi /etc/selinux/config 内容修改为: selinux=disable 之后重启reboot. 下图分别为selinux关闭前 和 关闭后: 2. 依赖软件查询 http://rpmfind.net 一.安装gcc gcc cloog-ppl ppl(libppl.so.7/libppl_c.so.2) cpp mpfr(libmpfr.so.1) gcc

DigitalOcean 推荐的ubuntu16下LAMP安装过程

LAMP安装过程: How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04 安装 PHPMyAdmin过程: 如何在Ubuntu 16.04上安装和安装phpMyAdmin

lamp安装(centos 64位)安装Discuz!论坛

lamp安装步骤 一.安装Discuz! 1.新建目录来存放网页等 [[email protected] ~]# mkdir /data/www [[email protected] ~]# cd /data/www [[email protected] www]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip 2.解压 [[email protected] www]# unzip Discuz_X3.2_

CentOS7 lamp安装 centoOS6 lamp

快速lamp安装 How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7 Introduction A "LAMP" stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is

Ubuntu 12.04下LAMP安装配置

我是一个Linux新手,想要安装一台Ubuntu 12.04版的Linux服务器,用这台服务器上的LAMP套件来运行我自己的个人网站.LAMP套件就是“Linux+Apache+Mysql+PHP这四款软件组成了一个可以使网站运行的套装工具软件.”通过安装尝试,我获得了一些成功的安装配置经验,通过本文提供给Linux网站服务器系统的入门者学习.本次安装的网站软件环境中将使用Apache2网页服务软件.MySQL5网站后台数据库软件.以及PHP5角本解释语言软件,配置成的系统也可提供FTP服务.

LAMP 安装详解

1. LAMP 的安装 sudo apt-get install apache2 mysql-server mysql-client php5 php5-gd php5-mysql 2. 由于LAMP大部分操作与/var/www目录相关,为了方便,修改该目录的权限为普通用户可访问. sudo chmod 777 /var/www/ 3. Apache 配置 (1)启用 mod_rewrite 模块 终端命令:sudo a2enmod rewrite (2)重启Apache服务器:sudo /et

&#8203;lamp安装于一台虚拟机实现过程

lamp安装于一台虚拟机实现过程

LINUX下 lamp安装及配置

环境 CenterOS 下载lamp:地址 https://lamp.sh/download.html 事先安装 wget, screen ,git,unzip 按照网站上的说明,逐步执行. 注意: 1.lamp安装mysql时时间会比较久,不要打断安装 在安装lamp时,会有一些默认的设置选项,一般选择默认即可.但是在一个 HTTP,HTTPS的选项时,选择N,这个配置选项是询问是否设置HTTP自动转换成HTTPS,因为本地并没有HTTPS的证书,所以本地网址访问为HTTP,如果设置为Y,会自

Zabbix&LAMP安装配置

监控端操作 基于LAMP架构部署Zabbix #!/bin/bash #基于LAMP架构安装Zabbix # lamp(){ #关闭防火墙&核心安全功能systemctl stop firewalld.servicesystemctl disable firewalld.service &> /dev/nullsetenforce 0sed -i "7cSELINUX=disabled" /etc/sysconfig/selinux #下载安装必要组件yum in