如何安装特定版本的Apache?


26

由于Ubuntu的更新,我将Apache 2.2升级到2.4时犯了一个错误-许多事情出了问题。

我不知道如何在之后指定版本apt-get remove apache2apt-get install apache2始终安装2.4。

我该怎么做?

Answers:


22

您需要执行以下操作:

apt-cache showpkg <pachagename>

上面的命令将显示此软件包的可用版本列表。然后选择所需的版本并执行以下操作。

apt-get install <packagename>=<complete version name>

例:

apt-cache showpkg apache2
apt-get install apache2=2.2.14-5ubuntu8.7

2
对我显示的唯一版本是Ubuntu 16上的2.4。这是一个大问题,因为2.4的已知问题已完全破坏了我的网站。
felwithe

2
找不到适用于apache2的2.2.14-5ubuntu8.7版本
Braian Mellor

谢谢-这比尝试采用PPA路线更好。
M Thomas Thomas

5

如何在未在存储库中包含Apache 2.2的Ubuntu发行版上安装Apache 2.2。

要求

您需要安装build-essentials软件包才能执行此操作。

~# sudo apt-get install build-essential

为了使Apache能够将输出压缩到支持它的浏览器中,您需要安装zlib。从zlip Hompage(在撰写本文时为zlib-1.2.11.tar.gz)下载当前版本,解压缩,导航到解压缩的文件夹,进行构建和安装。

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure --prefix=/usr/local
make
sudo make install

安装Apache 2.2

Apache下载页面(撰写本文时为httpd-2.2.32.tar.gz)下载当前版本,将其解压缩,导航至解压缩的文件夹,进行构建和安装。

wget http://www-eu.apache.org/dist/httpd/httpd-2.2.32.tar.gz
tar -xvf httpd-2.2.32.tar.gz
cd httpd-2.2.32/
./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-proxy --enable-proxy-balancer --enable-proxy-http
make
sudo make install

启动Apache:

sudo /usr/local/apache2/bin/apachectl start

检查是否一切正常

在浏览器中导航到http:// localhost,您应该在其中看到一条消息,它“有效!”。

或者,您可以通过终端执行此操作:

wget -qO- http://localhost | grep "It works!"

在终端中应该输出如下内容:

<html><body><h1>It works!</h1></body></html>

为Apache2创建“服务”

sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apache22
sudo chmod +x /etc/init.d/apache22

提示:您现在可以使用sudo服务apache22调用apachectl 。

使Apache在启动时启动

sudo sed -i '2i #\n### BEGIN INIT INFO\n# Provides:             apache2\n# Required-Start:       $remote_fs\n# Required-Stop:        $remote_fs\n# Default-Start:        2 3 4 5\n# Default-Stop:         0 1 6\n# Description:          apache2\n# Short-Description:    The Apache webserver\n### END INIT INFO' /etc/init.d/apache22
sudo /usr/sbin/update-rc.d apache22 defaults

安全的Apache

sudo service apache22 stop
sudo adduser --system apache
sed -i -e 's/User daemon/User apache/g' /usr/local/apache2/conf/httpd.conf
sed -i -e 's/Group daemon/Group nogroup/g' /usr/local/apache2/conf/httpd.conf
sudo service apache22 start

检查新设置

ps -aux | grep httpd

如果最后一条命令的终端输出显示一些以“ apache”开头的行,则一切正常。

配置您的网站

如果只想为一个站点配置apache,只需编辑httpd.conf

nano /usr/local/apache2/conf/httpd.conf

您可能需要修改的基本参数是:

ServerName www.example.com:80
DocumentRoot "/usr/local/apache2/htdocs"

<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

如果要配置多个站点,请查看httpd-vhosts.conf

nano /usr/local/apache2/conf/httpd.conf

您必须在<VirtualHost>旁边添加一个<Directory>部分,该部分与上面的类似,但要作为VitualHost的文档根目录。例如:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
    <Directory "/usr/local/apache2/docs/dummy-host.example.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

按照以下说明进行操作:dzenan @ ubuntu16-i386:〜/ httpd-2.2.34 $ sudo /usr/sbin/update-rc.d apachectl默认为insserv:脚本apachectl:服务apache2已提供!insserv:现在退出!更新的rc.d:错误:拒绝insserv时脚本头
Dženan

实际上,在Ubuntu 16.04上,已经存在/etc/init.d/apache2内容完全不同的文件。
Dženan

删除有问题的文件会使我们步入正轨,但sudo service apachectl stop不会停止服务。
Dženan

如果您不按照使Apache在启动时启动的步骤进行操作,则“ sudo service apachectl stop”将仅不起作用。看完我的答案后,我决定更改它……首先,apachectl确实是“服务”的坏名字,并且很难在该部分中创建它。因此,现在您可以按照为Apache2创建“服务”下的步骤执行sudo service apache22 start / stop
Johano Fierra

我决定放弃这种方法,并更新我的配置文件以与apache 2.4兼容。这样可以减少头痛。但是,谢谢您的详细回答!
Dženan

4

请参阅ubuntu 软件包固定方法

编辑档案 /etc/apt/preferences

“首选项”文件是实际固定的地方。要固定包装,请将其Pin-Priority设置为更高的数字。这是一个例子:

Package: apache2
Pin: release n=raring
Pin-Priority: 1000

运行前测试apt-get updateapt-get installapt-cache policy apache2

有关man apt_preferences详细信息,请参见。我选择钉销raring的release,因为这样您仍然可以在2.2.x分支上获得更新。不要忘记,您必须通过添加raring的存储库URL 使该包可用于APT 。

更新

raringEOL一样,您可以使用http://old-releases.ubuntu.com上仍受支持precise或已归档的raring软件包。

使用as /etc/apt/sources.list.d/raring.list可以安装较旧的软件包:

deb http://old-releases.ubuntu.com/ubuntu/ raring main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-updates main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse

你好 这似乎正是我想要的。您还可以添加用于添加稀有资源库URL的命令吗?我似乎找不到合适的。
Ravish Bhagdev

我已经更新了答案。
fuero

不错,我已将APT镜像列表更正为raring。当然,如果要使用precise版本,也/etc/apt/preferences必须相应地进行更改。
fuero

非常感谢。无论如何,结果证明是蠕虫病毒……在执行指定的步骤(并同时尝试install -f选项和clean)之后,必须采用VM路线作为跟随对象。以下软件包具有未满足的依赖性。apache2:取决于:apache2-mpm-worker(= 2.2.22-1ubuntu1.7)但不会被安装,或者apache2-mpm-prefork(= 2.2.22-1ubuntu1.7)但不会被安装已安装或....等等等
Ravish Bhagdev

2

要安装apache2.2,请使用以下过程:

在以后的发行版中(例如16.04),我从Apache站点下载了2.2.31。

我使用以下配置构建它:

./configure --enable-so --enable-ssl --with-included-apr --enable-mods-shared=all --enable-load-all-modules --enable-rewrite --enable-proxy --enable-proxy_connect --enable-proxy_http --enable-proxy_ajp --enable-authn_alias --with-npm=prefork --enable-proxy_balancer --enable-proxy_ftp --enable-cache --enable-suexec --enable-disk_cache  > conf.txt

然后当然要调整httpd.conf和ssl.conf文件。

之后,我只需运行./httpd -k start

而且有效!

请注意,我通过apt-get添加了apache2.4,但从未将其删除。这意味着在系统启动后,我需要终止apache2进程。然后,我可以启动apache2.2。我必须安装apache2.4才能使用apachectl,但后来由于我使用./httpd而将其解散了。


看看我关于为Apache 2.2使用apachectl的回答,尽管您可能必须先删除2.4版本(/usr/sbin/update-rc.d -f apachectl remove)。
约翰·费拉

1

您从Ubuntu 13.04升级到13.10?如果不离开Ubuntu软件包存储库,就无法取回Apache 2.2。最好只修复您的Apache配置,使其与2.4兼容。


1
不完全是,请看我的回答
Coen Damen

@CoenDamen实际上,您的回答是“走出Ubuntu软件包存储库”。另外,对于任何全新的Ubuntu安装,您的答案都将“按原样”运行,因为它将缺少很多依赖项。
约翰·费拉
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.