php 7.0.29,Apache2.4.29加php7.2.0的编译安装

前言:

安装系统环境CentOS 6.8mini,用RPM安装了MySQL 5.7.20,接下来用tar源码包安装Apache2.4.29和PHP7.2.0,目前使用的都是最新的软件版本

1.下载安装包[root@XiaoFeng opt]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.29.tar.gz

[root@XiaoFeng opt]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.3.tar.gz

[root@XiaoFeng opt]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

[root@XiaoFeng opt]# wget http://cn2.php.net/distributions/php-7.2.0.tar.gz

2.安装依赖包[root@XiaoFeng opt]# yum install -y zlib zlib-devel pcre pcre-devel openssl openssl-devel expat-devel

[root@XiaoFeng opt]# tar -zxvf httpd-2.4.29.tar.gz

[root@XiaoFeng opt]# tar -zxvf apr-1.6.3.tar.gz

[root@XiaoFeng opt]# tar -zxvf apr-util-1.6.1.tar.gz

[root@XiaoFeng opt]# tar -zxvf php-7.2.0.tar.gz

[root@XiaoFeng opt]# cd apr-1.6.3

[root@XiaoFeng apr-1.6.3]# ./configure --prefix=/usr/local/apr

[root@XiaoFeng apr-1.6.3]# make && make install

[root@XiaoFeng apr-1.6.3]# cd ../apr-util-1.6.1

[root@XiaoFeng apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

[root@XiaoFeng apr-util-1.6.1]# make && make install

3.安装Apache2.4.29[root@XiaoFeng apr-util-1.6.1]# cd ../httpd-2.4.29

[root@XiaoFeng httpd-2.4.29]# cp -r ../apr-1.6.3 ./srclib/apr

[root@XiaoFeng httpd-2.4.29]# cp -r ../apr-util-1.6.1 ./srclib/apr-util

编译配置./configure \

--prefix=/usr/local/apache2 \

--with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-included-apr \

--with-pcre \

--with-zlib \

--enable-so \

--enable-rewrite \

--enable-ssl \

--enable-deflate=shared \

--enable-expires=shared \

--enable-rewrite=shared \

--enable-static-support[root@XiaoFeng httpd-2.4.29]# make && make install

加入系统服务,设为开机启动[root@XiaoFeng opt]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

[root@XiaoFeng opt]#  chmod 755 /etc/init.d/httpd

[root@XiaoFeng opt]# vim /etc/init.d/httpd

添加下面内容,不然不能添加到系统服务里

# chkconfig: 345 85 15

# description: Activates/Deactivates Apache Web Server

[root@XiaoFeng opt]# chkconfig --add httpd

[root@XiaoFeng opt]# chkconfig httpd on

路径加入系统环境变量、设置ServerName[root@XiaoFeng opt]# vim /etc/profile

export PATH=$PATH:/usr/local/apache2/bin

[root@XiaoFeng opt]# vim /usr/local/apache2/conf/httpd.conf

ServerName localhost:80

[root@XiaoFeng opt]# service httpd start

[root@XiaoFeng opt]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

[root@XiaoFeng opt]# /etc/init.d/iptables save

4.安装PHP7.2.0

安装依赖包[root@XiaoFeng opt]# yum install -y curl curl-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel php-mcrypt libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib

[root@XiaoFeng opt]# tar -zxvf php-7.2.0.tar.gz

[root@XiaoFeng opt]# cd php-7.2.0

[root@XiaoFeng php-7.2.0]#./configure \

--prefix=/usr/local/php \

--exec-prefix=/usr/local/php \

--bindir=/usr/local/php/bin \

--sbindir=/usr/local/php/sbin \

--with-apxs2=/usr/local/apache2/bin/apxs \

--with-libdir=/usr/lib64 \

--enable-fpm \

--with-config-file-path=/etc \

--with-libxml-dir \

--with-openssl \

--with-mysqli \

--with-zlib \

--enable-bcmath \

--with-bz2 \

--enable-calendar \

--with-curl \

--enable-exif \

--with-pcre-dir \

--enable-ftp \

--with-openssl-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--enable-gd-jis-conv \

--with-gettext \

--with-gmp \

--with-mhash \

--enable-mbstring \

--with-libmbfl \

--with-onig \

--with-pdo-mysql \

--with-readline \

--enable-shmop \

--enable-soap \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvsem \

--enable-sysvshm \

--enable-wddx \

--with-xmlrpc \

--with-xsl \

--enable-zip \

--with-pear \

--enable-mysqlnd \

--enable-shared \

--enable-inline-optimization \

--disable-debug \

--enable-xml \

--with-sqlite3 \

--with-iconv \

--with-cdb \

--enable-dom \

--enable-fileinfo \

--enable-filter \

--enable-json \

--enable-mbregex \

--enable-mbregex-backtrack \

--enable-pdo \

--with-pdo-sqlite \

--enable-session \

--enable-simplexml \

--enable-opcache[root@XiaoFeng php-7.2.0]# make && make install

[root@XiaoFeng php-7.2.0]# cp /opt/php-7.2.0/php.ini-development /etc/php.ini

[root@XiaoFeng php-7.2.0]# vim /usr/local/apache2/conf/httpd.conf

Apache与PHP的关联

PHP安装成功后会在apache的modules目录下生成一个libphp.so动态库文件,在apache的配置文件httpd.conf里找到下面位置,增加下面的最后一行# Example:

# LoadModule foo_module modules/mod_foo.so

#

LoadModule php7_module        modules/libphp7.so

配置欢迎页(首页)

DirectoryIndex index.php index.html index.htm

在Apache的配置文件httpd.conf的块里增加一行Addtype application/x-httpd-php .php

在网站目录里写个测试php文件[root@XiaoFeng php-7.2.0]# vim /usr/local/apache2/htdocs/index.php

phpinfo();

在重起Apache,能访问到显示PHP Version 7.2.0  就OK了

6d281ea9a5101b58bf92ab3a0efcfadb.png

Apache 开启rewrite  支持.htaccess

修改配置文件 httpd.conf

152行去掉#: LoadModule rewrite_module modules/mod_rewrite.so

241行改成: AllowOverride All

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值