CentOS6.5下安装Apache2.4+PHP7

http://blog.csdn.net/along602/article/details/42695779

http://www.th7.cn/Program/php/201511/691594.shtml

http://jingyan.baidu.com/article/d2b1d10299bda55c7f37d466.html

1,准备工作,首先要下载所需软件的源码包,有如下这些:

apr-1.5.1.tar.bz2

apr-util-1.5.4.tar.bz2

pcre-8.36.tar.bz2

httpd-2.4.10.tar.bz2

php-7.0.20.tar.gz
 
把所有的源码包上传到服务器上/var/lamp目录下

cd /var/lamp

首先要安装Apache的依赖库

tar jxvf apr-1.5.1.tar.bz2

tar jxvf apr-util-1.5.4.tar.bz2

tar jxvf pcre-8.36.tar.bz2

tar jxvf httpd-2.4.10.tar.bz2

tar zxvf php-7.0.20.tar.gz

cd apr-1.5.1
./configure --prefix=/usr/local/apr
make && make install

cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

cd pcre-8.36
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

2,安装Apache2.4
 
首先要安装Apache的依赖库
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
pcre-8.36.tar.gz
 
tar zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install
 
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
 
tar zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
 
安装PCRE的时候遇到如下错误:
You need a C++ compiler for C++ support
解决方案是:
yum install -y gcc gcc-c++
注意:这个-y千万不能少。
 
 
可以开始安装Apache了,
解压缩
cd httpd-2.4.17
./configure  --prefix=/usr/local/apache2  --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util  -with-pcre=/usr/local/pcre  --enable-so--enable-rewrite
make && make install

注意:--enable-so--enable-rewrite 中间不能有空格

cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

service httpd start

cd /usr/local/apache2/bin

./httpd -v 出现版本号

http://www.xxx.com 访问出现

It works!

测试是否安装成功

2,安装PHP7
cd /var/lamp/php-7.0.20

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/apache2/conf --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

make && make install

错误1 如果你在执行./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli --with-pdo-mysql --enable-mbstring时,出现这样的错误

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

说明需要libxml2,用yum装一下:yum -y install libxml2 libxml2-devel

装完libxml2后,就可以正常地进行php的源码安装了

错误2 解决 Cannot find OpenSSL's <evp.h>

yum install openssl openssl-devel

错误3 Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/

其实就是curl的dev包没有安装, 解决方案:yum -y install curl-devel

错误4 error: png.h not found.

yum install libpng libpng-devel

错误5 error: freetype-config not found.

yum install freetype-devel

错误6 error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install libxslt-devel

出现

Thank you for using PHP.

config.status: creating php7.spec

就代表安装成功了。

1,在Vim中搜索”DirectoryIndex“字符串,大家可以看到已经有index.html了,在index.html后面添加你想让apache识别的DirectoryIndex

在/user/local/apache2/conf/httpd.conf配置文件中再添加一段指令:

<FilesMatch "\.ph(p[2-6]?|tml)$">

SetHandler application/x-httpd-php

</FilesMatch>

这段指令告诉apache,碰到文件名以

.php, .php2, .php3, .php4, .php5, .php6或phtml结尾的文件使用

libphp7.so模块进行解析。

其中"\.ph(p[2-6]?|tml)$"为正则表达式,你可以随意更改,只要符合PCRE正则表达式语法,都可以。

2,接下来,在Vim中搜索”DirectoryIndex“字符串,大家可以看到已经有index.html了,在index.html后面添加你想让apache识别的DirectoryIndex

<IfModule dir_module>
DirectoryIndex index.html index.php index.phtml
</IfModule>

3,修改PHP的配置文件php.ini
进入php源码目录,选择php.ini-development复制一份到/usr/local/apache2/conf,并改名为php.ini使用vi打开,查找extension_dir,修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226",读者根据自己的PHP安装目录结构配置,目的是找到PHP的扩展库。 
查找extension=php_,去掉extension=php_curl.dll,extension=php_gd2.dll,extension=php_mbstring.dll,extension=php_mysql.dll,extension=php_mysqli.dll,extension=php_pdo_mysql.dll,extension=php_xmlrpc.dll前面 的分号。查找short_open_tag = Off把它修改成short_open_tag = On,让其支持短标签(我看注释这个默认是打开的)。
 
 
从别人的服务器上我还拷贝了如下文件放到
/usr/local/php/lib/php/extensions/no-debug-zts-20131226目录,
文件如下:
Imap.so
Mcrypt.so
Memcache.so
Openssl.so
Zip.so
 
然后在php.ini的最后增加如下配置文字:
extension=memcache.so
extension=openssl.so
extension=mcrypt.so
extension=zip.so
   
 
 
 
4,修改Apache配置文件httpd.conf相关修改以支持PHP
vi /usr/local/apache/conf/httpd.conf

Ø  添加php支持。
【添加字段一】
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
 
【添加字段二】
<FilesMatch /.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Ø  添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php

Ø  3. 不显示目录结构,找到“OptionsIndexes FollowSymLinks”,修改为
Options FollowSymLinks

Ø  4. 开启Apache支持伪静态,找到“AllowOverride None”,修改为
AllowOverride All
 
重启Apache
service httpd restart
 
提醒:实在不知道怎么配置,就找个已经搭建成功的服务器把配置文件弄过来对比一下。

此时还会遇到如下报错:

httpd: Could not reliably determine the server's fully qualified domain name

解决办法:

linux : /usr/local/apache/conf

用记事本打开httpd.conf

将里面的#ServerName localhost:80注释去掉即可。

启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name
[root@server httpd-2.2.4]# /usr/local/apache/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
1)进入apache的安装目录:(视个人安装情况而不同) [root@server ~]# cd /usr/local/apache/conf
2)编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80

到此,整个Apache+PHP5.6的环境搭建完毕。

CentOS6.5下安装Apache2.4+PHP7的更多相关文章

  1. CentOS6.5下安装apache2.2和PHP 5.5.28

    CentOS6.5下安装apache2.2 1. 准备程序 :httpd-2.2.27.tar.gz 下载地址:http://httpd.apache.org/download.cgi#apache2 ...

  2. Windows10 下安装 Apache2.4+PHP7.1+MySQL5.7

    这个教程主要是分享如何快速组建WAMP开发环境,对于软件的详细配置,自行参考文档或搜索. Visual C++ Redistributable for Visual Studio 2015 下载地址: ...

  3. Centos7 下安装Apache2 + MySQL + PHP7

    Apache 1.安装Apache yum install httpd 2.设置服务器开机自动启动Apache systemctl enable httpd.service 若要验证是否自动启动可在重 ...

  4. CentOS6.4 下安装 Apache2.4.16

    1.准备工作 1.1.yum安装部分工具 1)yum -y install vim 2)yum -y install wget 3)yum -y install gcc 4)yum -y instal ...

  5. centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8

    以虚拟机VirtualBox 版本是4.1.20(内存设置为512M,centos安装是文本模式下安装),全新以最小化包安装了32位的 CentOS6.3系统,作为本地web环境,上次讲了在windo ...

  6. 【转载】CentOS6.5_X64下安装配置MongoDB数据库

    [转载]CentOS6.5_X64下安装配置MongoDB数据库 2014-05-16 10:07:09|  分类: 默认分类|举报|字号 订阅      下载LOFTER客户端 本文转载自zhm&l ...

  7. CentOS6.5下安装配置MySQL

    CentOS6.5下安装配置MySQL,配置方法如下: 安装mysql数据库:# yum install -y mysql-server mysql mysql-deve 查看mysql-server ...

  8. 在CentOS6.8下安装Docker

    在CentOS6.8下安装Docker 一.查看系统版本 [root@localhost opt]# uname -a Linux localhost.localdomain -.el6.x86_64 ...

  9. coreseek/sphinx CentOS6.4下安装

    一.在CentOS6.4下安装coreseek之前需要预先安装以下软件 1.打开终端 输入 su 获取管理员权限 2.输入命令 yum install make gcc g++ gcc-c++ lib ...

随机推荐

  1. java泛型讲解

    原文: https://blog.csdn.net/briblue/article/details/76736356 泛型,一个孤独的守门者. 大家可能会有疑问,我为什么叫做泛型是一个守门者.这其实是 ...

  2. system的消息队列实例

    1\创建或打开消息队列函数原型:int msgget(key_t key, int msgflg)参数第一个参数为ftok方法创建的一个kety_t或者为一个整数值第二个参数为逻辑控制,IPC_CRE ...

  3. 扩展HtmlHelper类实现Mvc4分页

    1.扩展HtmlHelper类方法Pager public static HtmlString Pager(this HtmlHelper htmlHelper, int currentPage, i ...

  4. apache rewrite 规则

    啥是虚拟主机呢?就是说把你自己的本地的开发的机子变成一个虚拟域名,比如:你在开发pptv下面的一个项目 127.0.0.1/pptv_trunk,你想把自己的机器域名变成www.pptv.com.那么 ...

  5. usort 函数

    function getNameFromNumber($num){ // Used to figure out what the Excel column name would be for a gi ...

  6. SSH连接虚拟机中的Ubuntu(转)

    摘要:主要是解决不能使用ssh远程Ubuntu的问题.使用的远程工具是putty.也可以使用xshell.ubunut12.0.4是装在虚拟机中的.不过这个应该没有什么影响. 一:问题的出现 前两天使 ...

  7. JAVA按顺序播放多个wav音频

    用Java按顺序播放多个音频部件,不是同时播放.代码如下: List<String> files = new ArrayList<String>(); files.add(&q ...

  8. KB/MB/GB。。单位换算

    今天遇到一个需求,需要把数据单位进行换算,记录一下.写的不好请勿见怪. function bytesToSize( bytes ) {//单位转化         var k = 1024,      ...

  9. 在使用MyCat和MySqL时的错误总结

    在mysql中,无法连接虚拟机中的mysql. 原因:防火墙没有关闭 解决方案:service iptables stop 在mycat中,无法打开数据库的表, 原因:mycat在配置文件中设置的是自 ...

  10. sql查询未走索引问题分析之查询数据量过大

    前因: 客户咨询,有一个业务sql(代表经常被执行且重要),全表扫描在系统占用资源很高(通过ash报告查询得到信息) 思路: 1.找到sql_text,sql_id 2.查看执行计划 3.查询sql涉 ...