LoginSignup
2
2

More than 3 years have passed since last update.

apache2 入門

Last updated at Posted at 2020-05-24

official page

apache2 official page

how to install

$ sudo apt update
$ sudo apt install apache2

how to start

$ sudo service apache2 start

comand line option

Usage: apache2 [-D name] [-d directory] [-f file]
            [-C "directive"] [-c "directive"]
            [-k start|restart|graceful|graceful-stop|stop]
            [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
-D name            : define a name for use in <IfDefine name> directives
-d directory       : specify an alternate initial ServerRoot
-f file            : specify an alternate ServerConfigFile
-C "directive"     : process directive before reading config files
-c "directive"     : process directive after reading config files
-e level           : show startup errors of level (see LogLevel)
-E file            : log startup errors to file
-v                 : show version number
-V                 : show compile settings
-h                 : list available command line options (this page)
-l                 : list compiled in modules
-L                 : list available configuration directives
-t -D DUMP_VHOSTS  : show parsed vhost settings
-t -D DUMP_RUN_CFG : show parsed run settings
-S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
-t -D DUMP_MODULES : show all loaded modules 
-M                 : a synonym for -t -D DUMP_MODULES
-t                 : run syntax check for config files
-T                 : start without DocumentRoot(s) check
-X                 : debug mode (only one worker, do not detach)

引用) https://httpd.apache.org/

check for config files

# run syntax check for config files
$ apache2 -t

/var/www/html

apache2が動いていることを確認する。

$ curl localhost && echo success || echo failed

Apacheがブラウザに送ってくれているhtmlは /var/www/html/ となっている。

ここを ドキュメントルート という。

ここにファイルを配置する事でApache経由で参照する事ができるようになる。

ドキュメントルートに移動する

$ cd /var/www/html
$ touch test.html
$ echo "Hello World!" > ./test.html

ブラウザを起動し、下記のように入力する。
[IPアドレス]/test.html

ドキュメントルートの変更

/etc/apahce2/apache2.conf

を変更する。

<Directory /var/www/> 
</Directory>

となっている部分を以下のように変更する。

<Directory /home/ubuntu/www>    
</Directory>

その後、apache2を再起動する。

$ sudo service apache2 restart 
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2