一、下载所需软件包php
根据官网所示,安装apache2.4.9必须先安装apr、apr-util、pcre包html
The following requirements exist for building Apache httpd: APR and APR-Util Make sure you have APR and APR-Util already installed on your system. If you don't, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/) and use ./configure's --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util. Perl-Compatible Regular Expressions Library (PCRE) This library is required but not longer bundled with httpd. Download the source code from http://www.pcre.org, or install a Port or Package. If your build system can't find the pcre-config script installed by the PCRE build, point to it using the --with-pcre parameter. On some platforms, you may have to install the corresponding -dev package to allow httpd to build against your installed copy of PCRE.
apr-1.5.1.tar.gz apr-util-1.5.3.tar.gz cd.sh httpd-2.4.9.tar.gz pcre-8.33.zip正则表达式
二、安装apache
# 解压缩 tar fvxz apr-1.5.1.tar.gz tar fvxz apr-util-1.5.3.tar.gz tar httpd-2.4.9.tar.gz tar fvxz httpd-2.4.9.tar.gz tar fvxz pcre-8.33.zip unzip pcre-8.33.zip # 编译安装apr cd /data/apr-1.5.1 ./configure --prefix=/usr/local/apr make && make install # 编译安装apr-util cd ../apr-util-1.5.3 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install # 编译安装pcre cd ../pcre-8.33 ./configure --prefix=/usr/local/pcre make && make install # 编译安装apache # 安装以前请确保系统以前预装的httpd已被卸载 cd ../httpd-2.4.9 # 参数依次是: httpd安装路径 httpd配置文件存放路径 启用模块化方式 启用ssl安全链接# 启用cgi脚本功能 启用url重写 启用服务器压缩 启用正则表达式支持 apr安装路径 # apr util安装路径 启用经常使用模块以确保apache正常工做 将多进程模型非静态化 # 启用事件异步模型 ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event make && make install
三、错误提示安全
安装openssl依赖关系 便可解决下面问题bash
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
四、启动&测试服务器
# /usr/local/apache/bin/apachectl startapp
若是成功,能够中止 Apache 服务器并继续安装 PHP:异步
/usr/local/apache2/bin/apachectl stop OR /usr/local/apache/bin/apachectl -k stop(推荐)
五、安装php5.5.12ide
tar fvxz php-5.5.12.tar.gz ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs make && make install
六、配置php.ini
cp php.ini-development /usr/local/lib/php.ini
七、编辑 httpd.conf 文件以调用 PHP 模块。LoadModule 达式右边的路径必须指向系统中的 PHP 模块。以上的 make install 命令可能已经完成了这些,但务必要检查
LoadModule php5_module modules/libphp5.so
八、apache解析php,添加以下内容:
# 让Apache将扩展名.php 解析成 PHP。为了不潜在的危险,例如上传或者建立相似 exploit.php.jpg 的文件并被当作 PHP 执行,咱们再也不使用 Apache 的 AddType 指令来设置。 <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> # 将.php,.php2,.php3,.php4,.php5,.php6,以及.phtml文件都当作PHP来运行 <FilesMatch "\.ph(p[2-6]?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> # .phps 文件由 PHP 源码过滤器处理,使得其在显示时能够高亮源码 <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> # mod_rewrite也有助于将那些不须要运行的.php文件的源码高亮显示,而并不须要将他们改名.phps文件 RewriteEngine On RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]