本文系我的"Web Server & Web Technology (WSWT)系列博客之一,主要讲解Linux系统的Apache配置和使用,以及如何使用apache搭建自己的个人网站".该系列博客的总目录参见这里http://blog.csdn.net/u014303046/article/details/73694983。
Docker是一种虚拟化技术,可以创建轻量、易于分发的应用。如果你不打算使用Docker的话你可以跳过本节,直接看后面的教程。如果你想顺便学习一下Docker的话,我也写过一个简单的Docker系列教程。Docker学习起来比较简单,一个小时之内应该就可以学会基本应用了。
首先pull一个ubuntu 16.04的镜像:
sudo docker pull ubuntu:16.04运行一个容器:
sudo docker run -ti --name web -p 80:80 -p 443:443 -p 8080:8080 ubuntu:16.04 bash安装一些依赖项:
apt update apt-get install vim apt-get install net-tools apt install iputils-ping apt install openssh-server apt install openssh-client apt install gcc apt install libpcre3 libpcre3-dev apt install make apt install openssl libssl-dev apt install libxml2 libxml2-dev apt install zip unzip apt install libexpat1-dev apt install libnghttp2-dev首先建立相应的安装目录:
mkdir /etc/apache2 mkdir /etc/apache2/src cd /etc/apache2/src下载源码并解压:
注意:下面的链接以后时间长了可能会失效,因此你可能需要搜索apache apr, apr-util, httpd等找到对应的链接替换掉下面命令中的下载链接。
wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz wget http://apache.mirrors.lucidnetworks.net//httpd/httpd-2.4.27.tar.gz wget http://cn2.php.net/distributions/php-7.1.8.tar.gz tar -xvf apr-1.5.2.tar.gz tar -xvf apr-util-1.5.4.tar.gz tar -xvf httpd-2.4.27.tar.gz tar -xvf php-7.1.8.tar.gz mv -f apr-1.5.2 httpd-2.4.27/srclib/apr mv -f apr-util-1.5.4 httpd-2.4.27/srclib/apr-util现在开始编译:
cd /etc/apache2 mkdir server_root cd src/httpd-2.4.27 ./configure --prefix=/etc/apache2/server_root --with-included-apr --with-mpm=worker --enable-so --enable-nonportable-atomics=yes --enable-ssl --enable-include --enable-cgi --enable-expires --enable-status --enable-info --enable-rewrite --enable-speling make make install mkdir /etc/apache2/php7 cd /etc/apache2/src/php-7.1.8 ./configure --with-apxs2=/etc/apache2/server_root/bin/apxs --prefix=/etc/apache2/php7 make make test make install修改httpd.conf文件:
vim /etc/apache2/server_root/conf/httpd.conf在httpd.conf文件中添加:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
去掉httpd.conf里ServerName前面的注释:
将容器commit成一个镜像保存,方便日后使用。
在终端进入bin,然后start服务:
cd /etc/apache2/server_root/bin ./apachectl start在浏览器输入Docker容器的地址: 172.17.0.2