How To Install the Apache Web Server on Ubuntu

Step 1: Install Apache

      sudo apt-get update

      sudo apt-get install apache2

Step 2: Adjust the Firewall

    efore we can test Apache, we need to modify our firewall to allow outside access to the default web ports.  Assuming that you followed the instructions in the prerequisites, you should have a UFW firewall configured to restrict access to your server. During installation, Apache registers itself with UFW to provide a few application profiles.  We can use these profiles to simplify the process of enabling or disabling access to Apache through our firewall. We can list theufwapplication profiles by typing:

    sudo ufw app list

You should get a listing of the application profiles:

  Available applications:

  Apache

  Apache Full

  Apache Secure

  OpenSSH

As you can see, there are three profiles available for Apache:

Apache: This profile opens only port 80 (normal, unencrypted web traffic)

Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)

Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)

For our purposes, we will allow incoming traffic for theApache Fullprofile by typing:

  sudo ufw allow 'Apache Full'

You can verify the change by typing:

  sudo ufw status

You should see HTTP traffic allowed in the displayed output:

Output

Status: activeTo                        Action      From--                        ------      ----OpenSSH                    ALLOW      Anywhere                  Apache Full                ALLOW      Anywhere                  OpenSSH (v6)              ALLOW      Anywhere (v6)            Apache Full (v6)          ALLOW      Anywhere (v6)

As you can see, the profile has been activated to allow access to the web server.

Step 3: Check your Web Server

At the end of the installation process, Ubuntu 16.04 starts Apache.  The web server should already be up and running.

We can check with thesystemdinit system to make sure the service is running by typing:

  sudo systemctl status apache2

As you can see above, the service appears to have started

successfully.  However, the best way to test this is to actually request

a page from Apache.

You can access the default Apache landing page to confirm that the

software is running properly.  You can access this through your server's

domain name or IP address.

If you are using DigitalOcean and do not have a domain name set up for your server, you can follow our guidehow to set up a domain with DigitalOceanto set one up.

If you do not want to set up a domain name for your server, you can

use your server's public IP address.  If you do not know your server's

IP address, you can get it a few different ways from the command line.

Try typing this at your server's command prompt:

  hostname -I


Step 4: Manage the Apache Process

To stop your web server, you can type:

    sudo systemctl stop apache2

Now that you have your web server up and running, we can go over some basic management commands.

o start the web server when it is stopped, type:

   sudo systemctl start apache2

To stop and then start the service again, type:

  sudo systemctl restart apache2

If you are simply making configuration changes, Apache can often

reload without dropping connections.  To do this, you can use this

command:

sudo systemctl reload apache2

By default, Apache is configured to start automatically when the

server boots.  If this is not what you want, you can disable this

behavior by typing:

sudo systemctl disable apache2

To re-enable the service to start up at boot, you can type:

sudo systemctl enable apache2

Apache should now start automatically when the server boots again.

Step 5: Get Familiar with Important Apache Files and Directories

Now that you know how to manage the service itself, you should take a few minutes to familiarize yourself with a few important directories and files.

Directories

Now that you know how to manage the service itself, you should take a

few minutes to familiarize yourself with a few important directories

and files.

Content

/var/www/html: The actual web content, which by default only consists of the default Apache page you saw earlier, is served out of the/var/www/htmldirectory.  This can be changed by altering Apache configuration files.

Server Configuration

/etc/apache2: The Apache configuration directory.  All of the Apache configuration files reside here.

/etc/apache2/apache2.conf: The main Apache configuration file.  This can be modified to make changes to the Apache global configuration.  This file is responsible for loading many of the other files in the configuration directory.

/etc/apache2/ports.conf: This file specifies the ports that Apache will listen on.  By default, Apache listens on port 80 and additionally listens on port 443 when a module providing SSL capabilities is enabled.

/etc/apache2/sites-available/: The directory where per-site "Virtual Hosts" can be stored.  Apache will not use the configuration files found in this directory unless they are linked to thesites-enableddirectory (see below).  Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory with thea2ensitecommand.

/etc/apache2/sites-enabled/: The directory where enabled per-site "Virtual Hosts" are stored.  Typically, these are created by linking to configuration files found in thesites-availabledirectory with thea2ensite.  Apache reads the configuration files and links found in this directory when it starts or reloads to compile a complete configuration.

/etc/apache2/conf-available/,/etc/apache2/conf-enabled/: These directories have the same relationship as thesites-availableandsites-enableddirectories, but are used to store configuration fragments that do not belong in a Virtual Host.  Files in theconf-availabledirectory can be enabled with thea2enconfcommand and disabled with thea2disconfcommand.

/etc/apache2/mods-available/,/etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively.  Files in ending in.loadcontain fragments to load specific modules, while files ending in.confcontain the configuration for those modules.  Modules can be enabled and disabled using thea2enmodanda2dismodcommand.

Server Logs

/var/log/apache2/access.log: By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise.

/var/log/apache2/error.log: By default, all errors are recorded in this file.  TheLogLeveldirective in the Apache configuration specifies how much detail the error logs will contain.

Conclusion

Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容