首页 > 编程知识 正文

Ubuntu 中 Apache2 安装配置卸载,vmware安装配置ubuntu20.04

时间:2023-05-05 08:27:29 阅读:220233 作者:661

Ubuntu 中 Apache2 安装、配置、卸载 两种安装方法 软件包安装源码安装 一、软件包安装 安装

命令:
sudo apt-get update
sudo apt-get install apache2

配置

(1)apache2 默认的几个配置文件:

/etc/apache2/apache2.conf 是主要配置文件(这个文件的末尾可以看到,include了其它所有的配置文件)。/etc/apache2/ports.conf 始终包含在主配置文件中。它用于确定传入连接的侦听端口,默认为80,我们一般都会重新配置新的端口。其它配置文件在 /etc/apache2/sites-enabled,/etc/apache2/conf-enabled,/etc/apache2/mods-enabled 目录下。apache2的默认web目录:/var/www/html。(在/etc/apache2/sites-enabled/000-default.conf 里可以看到这个 DocumentRoot /var/www/html 配置)apache2 的默认用户是 www-data,定义在 /etc/apache2/envvars 文件中。设置默认主页的配置文件/etc/apache2/mods-enabled/dir.conf

(2)修改端口,这里我修改为8099

修改它的监听端口
sudo vim /etc/apache2/ports.conf

修改它的主机端口
sudo vim /etc/apache2/sites-available/000-default.conf

(3)apache2 的几个简单命令:启动、停止、重启、状态
sudo /etc/init.d/apache2 [ start | stop | restart | status ]
service apache2 [ start | stop | restart | status ]

(4)重启apache2 并查看状态
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 status

访问测试

(1)测试apache2主页

使用浏览器输入IP地址加端口号8099
二、源码安装 检查编译环境

首先查看系统有木有安装gcc/gcc-c++(要确保系统上有编译环境 C ),没有安装的话必须先安装:
apt-get install gcc-c++

下载下面几依赖包

apr
apr-util
pcre
httpd

解压下载的压缩包

(1) 在 /usr/local/下新建几个文件夹
sudo mkdir /usr/local/apr
sudo mkdir /usr/local/apr-util
sudo mkdir /usr/local/pcre
sudo mkdir /usr/local/httpd

(2) 将下载的依赖包分别解压到其中:
tar -zxvf apr-1.6.3.tar.gz -C /usr/local/apr
tar -zxvf apr-util-1.6.1.tar.gz -C /usr/local/apr-util
tar -zxvf pcre-8.32.tar.gz -C /usr/local/pcre
tar -zxvf httpd-2.4.29.tar.gz -C /usr/local/httpd

依次安装

(1) apr:

cd apr-1.6.3./configure –prefix=/usr/local/aprmakemake install

(2) apr-util:

cd /usr/local/apr-util-1.6.1./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/jqdyx/apr-1-configmakemake install

(3) pcre:

cd /usr/local/pcre-8.32./configure –prefix=/usr/local/pcre –with-apr=/usr/local/apr/jqdyx/apr-1-configmakemake install

(4)httpd:

cd /usr/local/httpd-2.4.29–prefix=/usr/local/apache2 –sysconfdir=/etc/httpd –enable-so –enable-rewirte –enable-ssl –enable-cgi –enable-cgid –enable-modules=most –enable-mods-shared=most –enable-mpms-shared=all –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-utilmakemake install

这里是把配置文件httpd.conf放在/etc/httpd下面的。
启动:/usr/local/apache2/jqdyx/apachectl start
停止:/usr/local/apache2/jqdyx/apachectl stop
重启:/usr/local/apache2/jqdyx/apachectl restart

测试

浏览器访问 localhost:80,出现 It works! ,表示启动成功

配置多域名、端口映射 Listen 80Listen 8080<VirtualHost *:80>DocumentRoot /var/www/html/项目1ServerName http://www.域名1.com </Virtualhost><Directory "/var/www/html/项目1">Options Indexes FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory><VirtualHost *:80>DocumentRoot /var/www/html/项目2ServerName http://www.域名2.com </Virtualhost><Directory "/var/www/html/项目2">Options Indexes FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory><VirtualHost Ip:8080> DocumentRoot /var/www/html/项目3 ServerName Ip:8080</VirtualHost><Directory "/var/www/html/项目3"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all</Directory> 卸载

sudo apt-get –purge remove apache2
sudo apt-get –purge remove apache2-common
sudo apt-get –purge remove apache2-utils
sudo apt-get autoremove apache2
–purge 是不保留配置文件的意思

删掉/etc/apache2文件夹:
sudo rm -rf /etc/apache2

删掉/var/www文件夹:
sudo rm -rf /var/www

删掉/etc/init.d/apache2文件:
sudo rm -rf /etc/init.d/apache2

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。