手动编译apache2.2.31+php-5.6.28,解析php代码变成下载的问题

目录:

PS:网上现在很多的教程都很老不详细终极死妈
这里写图片描述

注意:这个教程是centos7编译apache2.2.31+php-5.6.28(apache2.2.x+php5.6.x编译命令应该适用),这里我的mysql是用yum的方式装的,当然你也可以手动编译安装(手动编译安装的mysql在编译php的时候需要改变一些编译参数,不然可能PHP没有mysql的模块,当然我也不太会php所以这里需要备注一下)

开始前需要关闭SELINUX 自行关闭或调试好firewall(Centos7默认使用firewall 不使用iptables)。
我这里使用的是网易的163yum源


检查是否有apache和php

[root@rsync ~]# rpm -qa|grep httpd #查看本机是否有apache
[root@rsync ~]# rpm -qa |grep php  #php
#卸载掉旧版本的apache+php
[root@rsync ~] rpm -e httpd-tools-2.4.6-45.el7.centos.x86_64 --nodeps  
[root@rsync ~] rpm -e httpd-2.4.6-45.el7.centos.x86_64 --nodeps  

#也可以这样卸载你列表出现的apach+php
[root@rsync ~] yum -y remove httpd               #yum -y remove httpd*卸载多个相类似的软件
[root@rsync ~] yum -y remove php                 #同上具体方法可以自行百度 google 

rpm -e [package name] –nodeps #忽略依赖强制卸载


安装apache依赖库

[root@rsync ~] yum install make gcc automake autoconf libtool -y #安装各种apache依赖库

编译apache

[root@rsync ~] wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.31.tar.gz    
[root@rsync ~] tar -zxf httpd-2.2.31.tar.gz     
[root@rsync ~] cd httpd-2.2.31.tar.gz           

[root@rsync httpd-2.2.31] ./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=most
[root@rsync httpd-2.2.31] make -j
[root@rsync httpd-2.2.31] make install

注意:
下面这个编译参数使用了动态编译apache的模块!解决了2.2.x编译后modules没有模块的终极死妈问题,
modules下面没有动态模块的话后面编译编译php就没有libphp5.so导致apache无法解析php。

./configure –prefix=/usr/local/apache #这里是你制定的路径
–enable-so –enable-mods-shared=most #这里是动态编译更多的模块

[root@rsync httpd-2.2.31] echo $?      #返回0表示成功其他数值表示失败,建议每执行一个步骤执行一次查看是否成功

设置apache开机自启动和service方式启动

[root@rsync ~] cd /usr/local/apache/bin/
[root@rsync bin] ./apachectl start       #启动apache
[root@rsync bin] netstat -tlnp           #查看是否启动了80端口

这里写图片描述
成功启动!

服务形式管理脚本 service [服务名] [start stop restart]

#拷贝bin目录下的apachectl到/etc/init.d/目录并且重命名为httpd这样就可以service httpd start了
[root@rsync bin] cp apachectl /etc/init.d/httpd 
[root@rsync bin] chmod +x /etc/init.d/httpd


#在最后一行添加全局环境变量重启后生效
[root@rsync init.d] vi /etc/profile
[root@rsync init.d] PATH=$PATH:/usr/local/apache/bin/

#临时添加环境变量可以直接使用比如httpd -V
[root@rsync init.d] export PATH=$PATH:/usr/local/apache/bin/

设置添加到chkconfig开机自启动里面

[root@rsync init.d] cd /etc/init.d/
[root@rsync init.d] vi httpd

#chkconfig: 2345 80 90
#description: Apache Web Server
:wq!
[root@rsync init.d] chkconfig --add httpd  #添加到开机自启动

在httpd配置文件顶部添加注意是在#!/bin/sh下
这里写图片描述

2345表示系统运行级别是2,3,4或者5时都启动此服务,详细可以去看下这个chkconfig
80 代表 启动等级 (数值越小越优先启动和关闭)
20 代表kill 关闭 等级

chkconfig –list查看一下当前是否开启
这里写图片描述


安装php依赖库

[root@rsync ~]yum install gcc gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel


#如果编译出现mcrypt.h not found. Please reinstall libmcrypt这个提示说明yum源没有装libmcrypt-devel
[root@rsync ~]yum install epel-release     #更新yum源的扩展包我这里用的是163的yum源
[root@rsync ~]yum update                   #更新yum包 后面如果出现太多的更新几百M的看情况更新一下吧,怕装不上 
[root@rsync ~]yum install php-mcrypt libmcrypt libmcrypt-devel 
#CentOS源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包。

编译php

[root@rsync ~] wget http://cn2.php.net/get/php-5.6.28.tar.gz/from/this/mirror
[root@rsync ~] tar -zxf php-5.6.28.tar.gz 
[root@rsync ~] cd php-5.6.28/

#编译php
[root@rsync php-5.6.28]
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-mysqlnd \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--enable-fpm \
--enable-pcntl \
--enable-opcache \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--enable-zip \
--enable-ftp \
--enable-soap \
--enable-xml \
--enable-mbstring \
--disable-rpath \
--disable-debug \
--disable-fileinfo \
--with-pcre-regex \
--with-iconv \
--with-zlib \
--with-mcrypt \
--with-gd \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-curl \
--with-imap-ssl \
--with-config-file-path=/usr/local/php/etc

[root@rsync php-5.6.28] make -j
[root@rsync php-5.6.28] make install

容易出现的错误

如果编译出现mcrypt.h not found. Please reinstall libmcrypt这个提示说明yum源没有装libmcrypt-devel
CentOS源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包。
[root@rsync ~]yum install epel-release #更新yum源的扩展包我这里用的是163的yum源
[root@rsync ~]yum update #更新yum包 后面如果出现太多的更新几百M的看情况更新一下吧,怕装不上
[root@rsync ~]yum install php-mcrypt libmcrypt libmcrypt-devel

注意重点来了!!!这里我的mysql是yum方式安装的,如果你是需要手动编译mysql需要先编译mysql再编译php,不然php的mysql库装不上很麻烦!!!-with-mysql是mysql的安装目录,由于我是用yum装的,所以不需要写-with-mysql=位置
也可以看下php编译参数或者自行百度 php编译参数

这里我说一下如果你是手动编译mysql编译参数需要修改的地方和重点
–with-apxs2=/usr/local/apache/bin/apxs \ 这个地方很重要直接关系到你是否能够整合php这里是你apache编译路径
–with-mysql=/usr/local/mysql 手动编译mysql的这里写你编译mysql的位置
–with-mysql=mysqlnd
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd


各种文件设置整合配置

这里是搞定php-fpm如果你要用到nginx+php这个一定要配置好

[root@rsync php-5.6.28] cp php.ini-production /usr/local/php/etc/php.ini​ #没有自动生成php.ini需要自己手动拷贝过去
[root@rsync php-5.6.28] cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  #以服务形式管理脚本
[root@rsync php-5.6.28] chmod +x /etc/init.d/php-fpm 
[root@rsync php-5.6.28] cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #上面这里是改php-fpm的配置文件名字
[root@rsync php-5.6.28] cd /usr/local/php/bin/
[root@rsync bin] ./php -v      #查看php启动版本到这一步基本就说明搞定php了

[root@rsync bin] vi /etc/profile
[root@rsync bin] PATH=$PATH:/usr/local/php/bin/
[root@rsync bin] export PATH=$PATH:/usr/local/php/bin

开启apache解析php

[root@rsync bin] vi /usr/local/apache/conf/httpd.conf

#最好先备份一下httpd.conf然后最后加上这一段代码解析php
<FilesMatch \.php$> 
SetHandler application/x-httpd-php 
</FilesMatch> 

<FilesMatch "\.ph(p[2-6]?|tml)$"> 
SetHandler application/x-httpd-php 
</FilesMatch> 

<FilesMatch "\.phps$"> 
SetHandler application/x-httpd-php-source 
</FilesMatch> 

[root@rsync bin] echo '<?phpphpinfo();?>' > /usr/local/apache/htdocs/test2.php
[root@rsync bin] service httpd restart

OK启动成功apache+php整合成功
这里写图片描述

#去掉启动的时候主机名提示
 sed -i 's/#ServerName www\.example\.com:80/ServerName www\.example\.com:80/g' /usr/local/apache/conf/httpd.conf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值