CentOS6.5 安装apache2.4及PHP5.6

卸载原有Apache

查看linux下是否有apache的rpm包命令:

rpm -qa|grep httpd

如果不存在则执行完命令后不会有任何的显示,如果存在则会显示相关的包名(如:httpd-2.2.4-11.el5_2.centos.5)

卸载rpm包命令:

rpm –e httpd-2.2.4-11.el5_2.centos.5

编译安装apache2.4

参考这篇文章:http://www.884358.com/centos7-apache/

这篇文章中,将添加httpd服务开启启动里面的systemctl enable httpd |去掉。

配置httpd.conf
去掉LoadModule rewrite_module modules/mod_rewrite.so前面的注释符号

PHP依赖包安装

yum -y install libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-develbzip2bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-devel libpng-devel

编译安装php

cd /usr/local/src

wget https://www.php.net/distributions/php-5.6.36.tar.gz

tar -zvxf php-5.6.36.tar.gz

cd php-5.6.36

mkdir -p /usr/local/php5

./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml2 --with-config-file-path=/usr/local/apache/conf --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-gd --enable-gd-native-ttf --with-zlib --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring  --with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp --with-jpeg-dir=/usr/local/jpeg6 --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-mcrypt=/usr/local/libmcrypt --disable-fileinfo

make && make install

配置httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so下面添加一行:

LoadModule php5_module modules/libphp5.so

配置php.ini

查找apahe调用的php.ini的路径:

/usr/local/php5/bin/php --ini

可以在编译的时候使用--with-config-file-path参数来修改php.ini的存放位置。

例如:

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

把php.ini存放到/etc下面,然后可以从源码包中拷贝php.ini-development到/etc/php.ini。

重启apache

编译安装php7.3

./configure --prefix=/usr/local/php73 --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php73/etc --with-iconv=/usr/local/libiconv --with-pdo-mysql=/usr/local/mysql --enable-bcmath --with-gd --enable-mbregex --enable-mbstring --with-curl --with-zlib --with-openssl --enable-fileinfo --enable-zip
make && make install

php.ini拷贝进入/usr/local/php73/etc目录。

编辑httpd.conf
AddType application/x-gzip .gz .tgz下方添加:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

搜索以下代码是否已自动添加,如已自动添加则不用添加

LoadModule php7_module        modules/libphp7.so

重启apache

获取php编译时的参数

/usr/local/php73/bin/php -i | grep Command

查看php扩展包安装路径

php -i |grep 'extension_dir'

发表评论

邮箱地址不会被公开。 必填项已用*标注