下载Apache安装包 httpd-2.4.23.tar.gz

下载地址:http://apache.fayea.com/httpd/


Apache 安装要求

必须安装APR、APR-Util、PCRE,gcc、gcc-c++等包


安装gcc和gcc-c++我采用yum安装的方式

yum-yinstallgccgcc-c++


编译命令:(除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数)

[root@bogonsoftware]#wgethttp://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz[root@bogonsoftware]#tar-zxvfhttpd-2.4.23.tar.gz[root@bogonsoftware]#cdhttpd-2.4.23[root@bogonhttpd-2.4.23]#./configure--prefix=/usr/local/apache2\--with-apr=/usr/local/apr\--with-apr-util=/usr/local/apr-util/\--with-pcre=/usr/local/pcrecheckingforchosenlayout...Apachecheckingforworkingmkdir-p...yescheckingforgrepthathandleslonglinesand-e.../usr/bin/grepcheckingforegrep.../usr/bin/grep-Echeckingbuildsystemtype...x86_64-unknown-linux-gnucheckinghostsystemtype...x86_64-unknown-linux-gnucheckingtargetsystemtype...x86_64-unknown-linux-gnuconfigure:configure:ConfiguringApachePortableRuntimelibrary...configure:checkingforAPR...configure:error:the--with-aprparameterisincorrect.Itmustspecifyaninstallprefix,abuilddirectory,oranapr-configfile.[root@bogonhttpd-2.4.23]#

在编译Apache时出现了上面问题,因为我还没有安装apr、apr-util、pcre,接下来依次安装依赖


http://apr.apache.org/download.cgi 下载apr-1.5.2.tar.gz、apr-util-1.5.4.tar.gz

http://www.pcre.org/ 官网

https://sourceforge.net/projects/pcre/files/pcre/ 选择pcre下载,不用pcre2

下载最新版本pcre-8.39.tar.gz


解决apr问题

[root@bogonsoftware]#wgethttp://archive.apache.org/dist/apr/apr-1.5.2.tar.gz[root@bogonsoftware]#tar-zxvfapr-1.5.2.tar.gz[root@bogonsoftware]#cdapr-1.5.2/[root@bogonapr-1.5.2]#./configure--prefix=/usr/local/apr[root@bogonapr-1.5.2]#make&&makeinstall

解决APR-util问题

[root@bogonsoftware]#wgethttp://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz[root@bogonsoftware]#tar-zxvfapr-util-1.5.4.tar.gz[root@bogonsoftware]#cdapr-util-1.5.4/[root@bogonapr-util-1.5.4]#./configure--prefix=/usr/local/apr-util\-with-apr=/usr/local/apr/bin/apr-1-config[root@bogonapr-util-1.5.4]#make&&makeinstall

make过程如果遇到下面这个错误,可能缺expat的开发库,安装expat库试试。yum install expat-devel

[root@jdu4e00u53f7apr-util-1.6.0]#makemake[1]:Enteringdirectory`/liuzhen/source/apr-util-1.6.0'/bin/sh/liuzhen/apr/build-1/libtool--silent--mode=compilegcc-g-O2-pthread-DHAVE_CONFIG_H-DLINUX-D_REENTRANT-D_GNU_SOURCE-I/liuzhen/source/apr-util-1.6.0/include-I/liuzhen/source/apr-util-1.6.0/include/private-I/liuzhen/apr/include/apr-1-oxml/apr_xml.lo-cxml/apr_xml.c&&touchxml/apr_xml.loxml/apr_xml.c:35:19:fatalerror:expat.h:Nosuchfileordirectory#include<expat.h>^compilationterminated.make[1]:***[xml/apr_xml.lo]Error1make[1]:Leavingdirectory`/liuzhen/source/apr-util-1.6.0'make:***[all-recursive]Error1


解决pcre-config问题

[root@bogonsoftware]#wgethttps://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz[root@bogonsoftware]#tar-zxvfpcre-8.39.tar.gz[root@bogonsoftware]#cdpcre-8.39[root@bogonpcre-8.39]#./configure--prefix=/usr/local/pcre[root@bogonpcre-8.39]#make&&makeinstall

再次编译httpd-2.4.23:

[root@bogonsoftware]#cdhttpd-2.4.23[root@bogonhttpd-2.4.23]#./configure--prefix=/usr/local/apache2\--with-apr=/usr/local/apr\--with-apr-util=/usr/local/apr-util/\--with-pcre=/usr/local/pcre[root@bogonhttpd-2.4.23]#make&&makeinstall

编辑 httpd.conf 文件

[root@localhostliuzhen]#vi/usr/local/apache2/conf/httpd.conf

找到:

#ServerName www.example.com:80

修改为:

ServerName 127.0.0.1:80或者ServerName localhost:80

记得要去掉前面的“#”


启动Apache

[root@localhostliuzhen]#/usr/local/apache2/bin/apachectlstart

停止Apache

[root@localhostliuzhen]#/usr/local/apache2/bin/apachectlstop

重启Apache

[root@localhostliuzhen]#/usr/local/apache2/bin/apachectlrestart

在浏览器中通过http://localhost:80,如果看到页面中显示“It works!”字样,则代表Apache验证通过。


接下来是PHP相关配置


编辑 httpd.conf 文件

[root@localhostliuzhen]#vi/usr/local/apache2/conf/httpd.conf

找到:

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

添加:

<IfModule dir_module>

DirectoryIndexindex.php index.html

</IfModule>

找到:

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

在后面添加(使Apcche支持PHP):

AddType application/x-httpd-php .php

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


修改默认的Web站点目录


默认的目录为 "/usr/local/apache2/htdocs",修改apache的配置文件httpd.conf,比如在新建一个 /home/gyw/WebSite的目录作为apache的站点目录


找到DocumentRoot这一行修改为:DocumentRoot "/home/gyw/WebSite"


找到 <Directory> 这一行修改为:<Directory "/home/gyw/WebSite">


测试:修改到文件夹出现错误:

“You don't have permission to access /index.html on this server.”


解决方法:

更改文件权限;chmod 755 index.html


打开apache配置文件httpd.conf,找到这么一段:

<Directory />

Options FollowSymLinks

AllowOverride None

Order deny,allow

deny from all

Satisfy all

</Directory>


安装PHP

我在php开发过程中需要使用gd2,所以顺便把安装gd2安装上

[root@localhostliuzhen]#yum-yinstalllibpnglibpng-develphp-gd

PHP下载地址:http://www.php.net/downloads.php

[root@localhostliuzhen]#wget-O./php-5.6.30.tar.gzhttp://hk1.php.net/get/php-5.6.30.tar.gz/from/this/mirror[root@localhostliuzhen]#tar-zxvfphp-5.6.30.tar.gz[root@localhostliuzhen]#cdphp-5.6.30[root@localhostphp-5.6.30]#./configure--prefix=/usr/local/php\--with-apxs2=/usr/local/apache2/bin/apxs\--with-mysql=mysqlnd\--with-gd

出现下面错误

Sorry,Icannotrunapxs.Possiblereasonsfollow:1.Perlisnotinstalled2.apxswasnotfound.Trytopassthepathusing--with-apxs2=/path/to/apxs3.Apachewasnotbuiltusing--enable-so(theapxsusagepageisdisplayed)Theoutputof/liuzhen/apache2/bin/apxsfollows:./configure:/liuzhen/apache2/bin/apxs:/replace/with/path/to/perl/interpreter:badinterpreter:Nosuchfileordirectoryconfigure:error:Aborting

解决步骤:

1、根据不能run apxs 。cd 到apache的bin目录下运行./apxs 运行结果

----------------------------------------------------

bash: ./apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory

---------------------------------------------------------

2、vim apxs文件 找“/replace/with/path/to/perl/interpreter”关键字

在第一个行 :#!/replace/with/path/to/perl/interpreter -w

根据perl的安装目录 /usr/bin/perl

修改为:#! /usr/bin/perl -w


重新执行phpconfigure

[root@localhostphp-5.6.30]#./configure--prefix=/usr/local/php\--with-apxs2=/usr/local/apache2/bin/apxs\--with-mysql=mysqlnd\--with-gd

出现错误:configure: error: xml2-config not found. Please check your libxml2 installation.

安装libxml2和libxml2-devel

[root@localhostphp-5.6.30]#yum-yinstalllibxml2libxml2-devel

再次执行./configure命令有可能还会出现下面这个错误

PEARpackagePHP_Archivenotinstalled:generatedpharwillrequirePHP'spharextensionbeenabled.clicommand.incdirectorytreeiterator.incinvertedregexiterator.incdirectorygraphiterator.incpharcommand.incphar.incBuildcomplete.Don'tforgettorun'maketest'.-bash:$'\343\200\200make':commandnotfound

php 的编译时需要依赖pear package ,目前的问题错误"PEAR package PHP_Archive not installed",已经明显报出这个问题。
因此编译使用参数 --without-pear 将pear 屏蔽掉编译安装后,再进行安装;同时因为phar 属于pear的一个库 ,所以不将phar关闭掉,同时还会报这个错误,
同时需要使用 --disable-phar 编译参数.

./configure--without-pear--disable-pharmakemakeinstall

成功编译安装完成后,再安装pear

wgethttp://pear.php.net/go-pear.phar/usr/local/bin/phpgo-pear.phar

重新运行上面的./configure命令

[root@localhostphp-5.6.30]#./configure--prefix=/usr/local/php\--with-apxs2=/usr/local/apache2/bin/apxs\--with-mysql=mysqlnd\--with-gd[root@localhostphp-5.6.30]#make&& makeinstall

--with-mysql=mysqlnd 加上此参数支持mysql

--with-gd 支持gd

注意这里有一个-with-apxs2=/usr/local/apache2/bin/apxs选项,其中apxs是在安装Apache时产生的,apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。我的理解是通过这个工具把PHP模块动态加载到Apache中


把原来位于源代码里面的php.ini-development拷贝到/usr/local/php/lib/php.ini下,并且重命名为php.ini

[root@localhostliuzhen]#cp/liuzhen/php-5.3.29/php.ini-development/usr/local/php/lib/php.ini

编辑/usr/local/php/lib/php.ini文件,找到;extension=php_gd2.dll将前面分号去掉


先停止apache后重启apache

[root@localhostliuzhen]#/usr/local/apache2/bin/apachectlstop[root@localhostliuzhen]#/usr/local/apache2/bin/apachectlrestart

测试

在apache的htdocs下建立一个php文件test.php,里面的内容如下:

<?php

phpinfo();

?>

然后在浏览器里输入http://127.0.0.1/test.php

如果出现php的相关配置,成功,如果什么都没有输入,说明失败,重新以上步骤或者查找原因


如果决定在安装后改变配置选项,只需重复最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效。Apache不需要重新编译。


下面是我留的笔记就不用看了

==========================

安装gd2,安装gd2的时候顺带安装了jpeg,png,zlib


1、安装zlib


http://www.zlib.net/

http://www.zlib.net/zlib-1.2.11.tar.gz


tar xf zlib-1.2.7.tar.gz


cd zlib-1.2.7

./configure

make

make install



2、安装 jpeg

https://jpeg.org/

http://www.ijg.org/

http://www.ijg.org/files/jpegsrc.v9b.tar.gz


tar xf jpegsrc.v9a.tar.gz

cd jpeg-9a

./configure --prefix=/usr/local/jpeg --enable-shared --enable-static

make

make install



3、安装 libpng

http://www.libpng.org/pub/png/libpng.html

http://download.sourceforge.net/libpng/libpng-1.6.28.tar.gz


http://blog.csdn.net/wang02011/article/details/7066361


tar xf libpng-1.6.12.tar.gz

cd libpng-1.6.12

./configure --prefix=/usr/local/libpng

make

make install



4、安装freetype

https://www.freetype.org/download.html

http://download.savannah.gnu.org/releases/freetype/

http://download.savannah.gnu.org/releases/freetype/freetype-2.7.1.tar.gz


tar xf freetype-2.5.3.tar.gz

cd freetype-2.5.3

./configure --prefix=/usr/local/freetype

make

make install


5、安装gd2

yum install php-gd

https://libgd.github.io/

https://github.com/libgd/libgd/archive/gd-2.2.4.tar.gz


tar xf libgd-2.1.0.gz

cd libgd-2.1.0

./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/png/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/

make

make install

(注,版本这里必须>=2.1.0,否则用php-5.6.0会报错,可能老版本的php不会报错)


安装php是参数调整

[root@localhostphp-5.6.30]#./configure--prefix=/usr/local/php\--with-apxs2=/usr/local/apache2/bin/apxs\--with-php-config=/usr/local/php/bin/php-config\--with-jpeg-dir=/usr/local/jpeg\--with-png-dir=/usr/local/libpng\--with-freetype-dir=/usr/local/freetype\--with-mysql=mysqlnd\--with-gd[root@localhostphp-5.6.30]#make&& makeinstall


安装curl

官网地址:https://curl.haxx.se/

下载地址:https://curl.haxx.se/download/curl-7.53.1.tar.gz

[root@bogonliuzhen]#wgethttps://curl.haxx.se/download/curl-7.53.1.tar.gz[root@bogonliuzhen]#tar-zxvfcurl-7.53.1.tar.gz[root@bogonliuzhen]#cdcurl-7.53.1[root@bogoncurl-7.53.1]#./configure--prefix=/usr/local/curl[root@bogoncurl-7.53.1]#make&&makeinstall

#vim /usr/local/php/lib/php.ini

添加如下一行:

extension=curl.so

安装php 只要打开开关 --with-curl=/usr/local/curl 就可以了。


-------------------------------------------------------------------------------------