从源代码安装 Apache 2.4.2

然后在我国家的一个镜像上使用 wget 从 httpd.apache.org/download 下载 Apache,然后提取。

wget http://apache.mirror.uber.com.au//httpd/httpd-2.4.2.tar.gz
tar xf httpd-2.4.2.tar.gz
cd httpd-2.4.2/
./configure --enable-so
...
Configuring Apache Portable Runtime library ...
checking for APR... no
configure: error: APR not found.  Please read the documentation.

PHP 稍后需要 --enable-so 。

此时我使用 wget 从 apr.apache.org/download 下载了 APR 1.4.6,然后将其解压缩。

cd ..
wget http://apache.mirror.uber.com.au//apr/apr-1.4.6.tar.gz
tar xf apr-1.4.6.tar.gz
cd apr-1.4.6/
./configure
make
make install

Apache 还需要安装 APR-util,它也可以从 apr.apache.org/download 页面下载。
当我们运行 configure 时,我们必须指定 apr 配置的位置,在完成上述 apr 后,我们应该在 make install 的输出中看到此位置。

cd ..
wget http://apache.mirror.uber.com.au//apr/apr-util-1.4.1.tar.gz
tar xf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1/
./configure --with-apr=/usr/local/apr/bin/apr-1-config
make
make install

现在完成了,我们可以再次尝试 Apache。

cd ../httpd-2.4.2/
./configure --enable-so
...
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

pcre-8.30.tar.gz 然后从 http://pcre.org 下载,为了不同的东西,我用 SFTP 将它上传到服务器到根目录。

cd ..
tar xf pcre-8.30.tar.gz
cd pcre-8.30/
./configure
make
make install

现在再次尝试Apache...

cd ../httpd-2.4.2/
./configure --enable-so
make
make install

就是这样,Apache 现在应该准备好了,让我们进入默认安装并启动它。

cd /usr/local/apache2/bin/
./apachectl start
/usr/local/apache2/bin/httpd: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
ldconfig
./apachectl start
./apachectl -v
Server version: Apache/2.4.2 (Unix)
Server built:   Jan 26 2012 20:51:23

与共享库相关的错误已通过运行 ldconfig 解决,有关详细信息,请参阅该手册页。

现在在我的 Web 浏览器中浏览 IP 地址会显示 Apache 默认页面。
由于默认情况下启用了 ServerSignature,因此使用 FireFox 的 Firebug 我可以看到“Apache/2.4.2 (Unix)”作为响应标头中的服务器标头,确认新安装的 Apache 已为我的页面提供服务。

从源代码安装 PHP 5.4.5

PHP 是从 http://au.php.net/get/php-5.4.5.tar.gz/from/a/mirror 下载的,然后使用 SFTP 上传到服务器上的根目录。

我正在使用 apxs 配置 PHP,除非使用 --enable-so 配置了 Apache,否则这对我不起作用。
我是在 MySQL 支持之后,随时离开 --with-mysql 关闭。

cd /root
tar xf php-5.4.5.tar.gz
cd php-5.4.5/
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=mysqlnd
...
configure: error: xml2-config not found. Please check your libxml2 installation.
apt-get install libxml2-dev
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=mysqlnd
make
make install
php -v
PHP 5.4.5 (cli) (built: Jan 26 2012 21:18:58)

准备工作

在开始之前,我们需要安装 make、gcc 和 g++。

apt-get install make gcc g++

我还安装了最新版本的 MySQL (5.5.25a),因为我想稍后使用它。
最新版本是从 Dotdeb 仓库下载的

如何从源代码安装 Apache 2.4 和 PHP 5.4

首先我们将安装 Apache,然后是 PHP。

配置

一旦我们安装并运行了 Apache 和 PHP,就需要进行一些配置,以便 Apache 知道如何使用 PHP。
我在这里创建了一个 phpinfo 文件 /usr/local/apache2/htdocs/phpinfo.php 并且它不会在配置之前显示在浏览器中。

首先,让我们将库文件复制到 Apache。

cp /root/php-5.4.5/libs/libphp5.so /usr/local/apache2/modules/

接下来,我们将要编辑 /usr/local/apache2/conf/httpd.conf 中的 Apache 配置文件,并将以下几行添加到其中。

AddType text/html .php
AddHandler php5-script	.php

这一行应该已经在那里了,指的是之前复制的 .so 文件。

LoadModule php5_module modules/libphp5.so

我们可能想要编辑 DirectoryIndex index.html 并在此之后包含 index.php。

完成后,重新启动Apache。

cd /usr/local/apache2/bin/
./apachectl restart
日期:2020-07-07 20:56:41 来源:oir作者:oir