Answers:
您需要执行以下操作:
apt-cache showpkg <pachagename>
上面的命令将显示此软件包的可用版本列表。然后选择所需的版本并执行以下操作。
apt-get install <packagename>=<complete version name>
例:
apt-cache showpkg apache2
apt-get install apache2=2.2.14-5ubuntu8.7
如何在未在存储库中包含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>
/etc/init.d/apache2
内容完全不同的文件。
sudo service apachectl stop
不会停止服务。
请参阅ubuntu 软件包固定方法:
编辑档案 /etc/apt/preferences
“首选项”文件是实际固定的地方。要固定包装,请将其Pin-Priority设置为更高的数字。这是一个例子:
Package: apache2
Pin: release n=raring
Pin-Priority: 1000
运行前测试apt-get update
或apt-get install
与apt-cache policy apache2
有关man apt_preferences
详细信息,请参见。我选择钉销raring
的release,因为这样您仍然可以在2.2.x分支上获得更新。不要忘记,您必须通过添加raring
的存储库URL 使该包可用于APT 。
更新:
与raring
EOL一样,您可以使用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
raring
。当然,如果要使用precise
版本,也/etc/apt/preferences
必须相应地进行更改。
要安装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而将其解散了。
您从Ubuntu 13.04升级到13.10?如果不离开Ubuntu软件包存储库,就无法取回Apache 2.2。最好只修复您的Apache配置,使其与2.4兼容。