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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市缘回,隨后出現(xiàn)的幾起案子池充,更是在濱河造成了極大的恐慌,老刑警劉巖讽营,帶你破解...
    沈念sama閱讀 207,113評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件亿乳,死亡現(xiàn)場離奇詭異鲫售,居然都是意外死亡共螺,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評論 2 381
  • 文/潘曉璐 我一進店門情竹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來藐不,“玉大人,你說我怎么就攤上這事秦效〕” “怎么了?”我有些...
    開封第一講書人閱讀 153,340評論 0 344
  • 文/不壞的土叔 我叫張陵阱州,是天一觀的道長挑秉。 經(jīng)常有香客問我,道長苔货,這世上最難降的妖魔是什么犀概? 我笑而不...
    開封第一講書人閱讀 55,449評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮夜惭,結(jié)果婚禮上姻灶,老公的妹妹穿的比我還像新娘。我一直安慰自己诈茧,他們只是感情好产喉,可當(dāng)我...
    茶點故事閱讀 64,445評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般曾沈。 火紅的嫁衣襯著肌膚如雪尘颓。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,166評論 1 284
  • 那天晦譬,我揣著相機與錄音,去河邊找鬼互广。 笑死敛腌,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的惫皱。 我是一名探鬼主播像樊,決...
    沈念sama閱讀 38,442評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼旅敷!你這毒婦竟也來了生棍?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,105評論 0 261
  • 序言:老撾萬榮一對情侶失蹤媳谁,失蹤者是張志新(化名)和其女友劉穎涂滴,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體晴音,經(jīng)...
    沈念sama閱讀 43,601評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡柔纵,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,066評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了锤躁。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片搁料。...
    茶點故事閱讀 38,161評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖系羞,靈堂內(nèi)的尸體忽然破棺而出郭计,到底是詐尸還是另有隱情,我是刑警寧澤椒振,帶...
    沈念sama閱讀 33,792評論 4 323
  • 正文 年R本政府宣布昭伸,位于F島的核電站,受9級特大地震影響杠人,放射性物質(zhì)發(fā)生泄漏勋乾。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,351評論 3 307
  • 文/蒙蒙 一嗡善、第九天 我趴在偏房一處隱蔽的房頂上張望辑莫。 院中可真熱鬧,春花似錦罩引、人聲如沸各吨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽揭蜒。三九已至横浑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間屉更,已是汗流浹背徙融。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留瑰谜,地道東北人欺冀。 一個月前我還...
    沈念sama閱讀 45,618評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像萨脑,于是被迫代替她去往敵國和親隐轩。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,916評論 2 344

推薦閱讀更多精彩內(nèi)容