ubuntu 安装 apache2 + php5(简短文字版)

图文版查看:https://www.cnblogs.com/amnotgcs/p/14011543.html

一、编译安装 apache

1.1 下载编译前需要的包

# 编译器(有则不需要安装)
sudo apt install gcc g++ make

# apr
wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar zxvf apr-1.7.0.tar.gz | tail
cd apr-1.7.0
su
./configure
make && make install

# apr-util
wget https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
su
./configure --with-apr=/usr/local/apr
make && make install

# pcre
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz
tar zxvf pcre-8.44.tar.gz | tail
su
./configure
make && make install

1.2 下载编译安装 apache2

wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
tar zxvf httpd-2.4.46.tar.gz
cd httpd-2.4.46
su
./configure    # 如果安装apr/apr-util/pcre的时候你指定了prefix,那在些configure的时候带上--with-apr/apr-util/pcre=xxx即可
make && make install

1.3 启动测试

# 启动服务器
cd /usr/local/apache2/
su
bin/apachectl -k start
# 访问服务器主页查看结果
cd
wget localhost
cat index.html

附录:快捷复制:

wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz
wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz

单次复制所有:

wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz  https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz  https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz  https://nchc.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz

附录:报错解决

expat.h not found

sudo apt install libexpat-dev

undefined reference to "XML_xxxxxx"

sudo apt install libxml2-dev    # 需要重新编译 apr-util 才生效

附录:一键安装脚本

ubuntu 20.04.1 一键安装
将上面代码保存到ubuntu上一个文件中,
切换到root用户,执行 bash <文件名>来安装。
安装完成会同时启动,访问主页即可查看是否成功。

原文地址:https://www.cnblogs.com/amnotgcs/p/14018744.html