一、我们使用源码安装
官网:https://httpd.apache.org/
文档:https://httpd.apache.org/docs/2.4/
下载源码包 httpd-2.4.20.tar.gz
http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.20.tar.gz
下载依赖包 apr apr-util pcre
https://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
https://archive.apache.org/dist/apr/apr-util-1.3.12.tar.bz2
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.zip
分别解压源码包,然后安装,先安装被依赖的,最后安装apache,按照下面顺序安装。
注意要指定安装路径,方便后面安装apache使用。
下面执行 make install的时候需要root权限。
安装 apr
./configure --prefix=/opt/apr
make && make install
安装 apr-util
./configure --prefix=/opt/apr-util --with-apr=/opt/apr/bin/apt-1-config
make && make install
安装 pcre
./configure --prefix=/opt/pcre
make && make install
安装最主要的 apache
./configure --prefix=/opt/apache --with-apr=/opt/apt --with-apr=/opt/apt-util --with-pcre=/opt/pcre
make && makeinstall
修改配置文件 /opt/apache/conf/httpd.conf
启动与关闭
启动 apachectl -k start
立刻停止 apachectl -k stop
立刻重启 apachectl -k restart
安全停止 apachectl -k graceful-stop
安全重启 apachectl -k graceful
说明:
cpache的进程名为 httpd
vi修改后提权保存文件的方法:
:w !sudo tee %
用源码安装的整个软件全部在指定目录下。
需要修改http.conf中的:
ListenPort
ServerName 这两个地方端口写成一样的
系统权限问题:
普通用户不能在apache主目录下写日志,会启动失败。
普通用户不允许使用80端口,会启动失败。
所以我们要用root来启动 httpd 服务。
(如果非要普通用户启动,可以把日志写在别处或者给日志目录赋予权限,并且使用其他端口)
二、从软件仓库安装,直接一句话搞定:
sudo apt-get install apache2
可以使用service开启动关闭,不过apachectl更好。
安装位置一般在 /usr/share下。
查看软件包安装了哪些文件(查看安装位置的方法):
dpkg -L apache2
安装的文件位置不集中,而是按照系统约定分散在各处。