Contents
WEBサーバー(Apache)
Apacheのインストール
①システムアップデート
|
1 2 3 |
# slackpkg update # slackpkg upgrade slackpkg # slackpkg new-config |
➁httpdインストール
|
1 |
# slackpkg upgrade httpd |
➂Apacheのバージョン確認
|
1 2 3 |
# httpd -v Server version: Apache/2.4.66 (Unix) Server built: Dec 4 2025 12:46:45 |
④Apacheの有効化と起動
|
1 2 |
# chmod +x /etc/rc.d/rc.httpd # /etc/rc.d/rc.httpd restart |
⑤Webサーバー利用のポート開放
firewall設定ファイルに追記する(http,httpsポートの開放)
|
1 2 3 4 5 6 7 |
# vi /etc/rc.d/rc.firewall # httpd iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --sport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT iptables -A INPUT -p tcp --sport 443 -j ACCEPT |
firewall設定反映
|
1 |
# /etc/rc.d/rc.firewall restart |
任意のブラウザでhttp://サーバーIP/に接続すると下記のようになればOK

Apache設定ファイルの編集
①設定ファイルは/etc/httpd/httpd.conf このファイルを編集する
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# vi /etc/httpd/httpd.conf 216行目管理者メールアドレスに変更 ServerAdmin [管理者メールアドレス] 225行目コメント解除し自ドメイン名[FQDN]に変更 ServerName [ドメイン名:80] 262行目Indexes削除 Options FollowSymLinks 270行目変更 AllowOverride ALL 283行目ディレクトリー名だけでアクセスできるファイルの追加 <IfModule dir_module> DirectoryIndex index.html index.htm index.pl index.php index.cgi </IfModule> 430行目コメント解除 AddHandler cgi-script .cgi 517行目コメント解除 # Various default settings Include /etc/httpd/extra/httpd-default.conf 最終行に追記 ServerTokens Prod |
➁Apache再起動
|
1 |
# /etc/rc.d/rc.httpd restart |
CGIスクリプトの利用確認
①CGIの利用可確認
|
1 2 |
# grep -n "^ *ScriptAlias" /etc/httpd/httpd.conf 366: ScriptAlias /cgi-bin/ "/srv/httpd/cgi-bin/" |
上記が表示され、「/srv/httpd/cgi-bin/」配下で利用可能
➁httpd.conf編集
|
1 2 3 4 5 |
# vi /etc/httpd/httpd.conf 169,172行目コメント解除 LoadModule cgid_module lib64/httpd/modules/mod_cgid.so LoadModule cgi_module lib64/httpd/modules/mod_cgi.so |
➂テストスクリプトを作成し、作動確認
|
1 2 3 4 |
# vi /srv/httpd/cgi-bin/index.cgi #!/usr/bin/python3 print("Content-type: text/html\n") print("CGI Script Test Page") |
|
1 2 3 4 |
# chmod 755 /srv/httpd/cgi-bin/index.cgi # /etc/rc.d/rc.httpd restart # curl localhost/cgi-bin/index.cgi CGI Script Test Page |
PHPインストール
①バージョンチェック
|
1 2 3 4 5 |
# php -v PHP 8.4.17 (cli) (built: Jan 15 2026 20:36:40) (ZTS) Copyright (c) The PHP Group Zend Engine v4.4.17, Copyright (c) Zend Technologies with Zend OPcache v8.4.17, Copyright (c), by Zend Technologies |
➁httpd.confの編集
|
1 2 3 4 |
# vi /etc/httpd/httpd.conf 539行目コメント解除 Include /etc/httpd/mod_php.conf |
➂/etc/php.iniファイルの編集
|
1 2 3 4 5 6 7 8 9 10 |
# vi /etc/php.ini 699行目変更 post_max_size = 300M 851行目変更 upload_max_filesize = 200M 1007行目コメント解除し追加 date.timezone = Asia/Tokyo |
④Apache再起動
|
1 |
# /etc/rc.d/rc.httpd restart |
⑤PHP起動確認のため下記ファイル作成
|
1 2 3 4 5 |
# vi /srv/httpd/htdocs/info.php <?php phpinfo(); ?> |
任意のブラウザでhttp://サーバーIP/info.php にアクセスすると下記理画面になればPHPは正常です

バーチャルホストの設定
バーチャルホストで運用するドメイン名 [slack.korodes.com] を、ドキュメントルート[/srv/httpd/htdocs/slack.korodes.com] ディレクトリに割り当てて設定します
slack-vhosts.confを新規作成
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# cd /etc/httpd/extra/ # vi slack-vhosts.conf <VirtualHost *:80> ServerAdmin [管理者メールアドレス] DocumentRoot "/srv/httpd/htdocs/slack.korodes.com" ServerName slack.korodes.com ErrorLog "/var/log/httpd/slack.korodes.com-error_log" CustomLog "/var/log/httpd/slack.korodes.com-access_log" common <Directory "/srv/httpd/htdocs/slack.korodes.com/"> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost> |
httpd.confファイルの編集
|
1 2 3 4 |
# vi /etc/httpd/httpd.conf 508行目に追加 Include /etc/httpd/extra/slack-vhosts.conf |
ドキュメントルートディレクトリー作成
|
1 |
# mkdir /srv/httpd/htdocs/slack.korodes.com |
Apache再起動
|
1 |
# /etc/rc.d/rc.httpd restart |
WEBサーバーSSL化
Let's Encrypt のSSL証明書を取得し、WEBサーバーをSSL化します。
今回はpythonの仮想環境を作成して、letsencryptの証明書を取得します
pythonの仮想環境ではプロジェクトごとに独立した環境になり、依存関係の管理や互換性やセキュリティの面でメリットがあります。
SSL証明書取得
1. python仮想環境作成
|
1 |
# python3 -m venv /opt/certbot |
2. 仮想環境内のpipを最新版にアップグレード
|
1 2 3 4 5 6 7 8 9 10 11 |
# /opt/certbot/bin/pip install --upgrade pip Requirement already satisfied: pip in /opt/certbot/lib64/python3.12/site-packages (25.0.1) Collecting pip Using cached pip-26.0-py3-none-any.whl.metadata (4.7 kB) Using cached pip-26.0-py3-none-any.whl (1.8 MB) Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 25.0.1 Uninstalling pip-25.0.1: Successfully uninstalled pip-25.0.1 Successfully installed pip-26.0 |
3.仮想環境内にCertbotをインストール
|
1 |
# /opt/certbot/bin/pip install certbot |
4.リンク作成
実行する際に絶対パスを記述しなくてよくなる
|
1 |
# ln -s /opt/certbot/bin/certbot /usr/bin/certbot |
5.apacheを停止する
|
1 |
# /etc/rc.d/rc.httpd stop |
6.証明書取得--対象ドメインをslack.korodes.comとする
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# certbot certonly --standalone -d slack.korodes.com Saving debug log to /var/log/letsencrypt/letsencrypt.log Requesting a certificate for slack.korodes.com Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/slack.korodes.com/fullchain.pem Key is saved at: /etc/letsencrypt/live/slack.korodes.com/privkey.pem This certificate expires on 2026-05-05. These files will be updated when the certificate renews. NEXT STEPS: - The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If you like Certbot, please consider supporting our work by: * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate * Donating to EFF: https://eff.org/donate-le - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
apache設定ファイルの編集
デフォルトのhttpd-ssl.conf をコピーして名称をslack-ssl.confにし、編集する
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# cd /etc/httpd/extra/ # cp httpd-ssl.conf slack-ssl.conf # vi slack-ssl.conf 124-128行目当たり : 下記のとおり変更 DocumentRoot "/srv/httpd/htdocs/slack.korodes.com" ServerName slack.korodes.com:443 ServerAdmin [mail address] ErrorLog "/var/log/httpd/slack.korodes.com.error_log" TransferLog "/var/log/httpd/slack.korodes.com.access_log" #144行目 : コメントにしてその下に追記 #SSLCertificateFile "/etc/httpd/server.crt" SSLCertificateFile "/etc/letsencrypt/live/slack.korodes.com/cert.pem" #155行目 : コメントにしてその下に追記 #SSLCertificateKeyFile "/etc/httpd/server.key" SSLCertificateKeyFile "/etc/letsencrypt/live/slack.korodes.com/privkey.pem" #168行目 : 追記 #SSLCertificateChainFile "/etc/httpd/server-ca.crt" SSLCertificateChainFile "/etc/letsencrypt/live/slack.korodes.com/chain.pem" |
apacheのメイン設定ファイルhttpd.confの編集
|
1 2 3 4 5 6 7 8 9 10 |
# cd /etc/httpd/ # vi httpd.conf # 92行目 : コメント解除 LoadModule socache_shmcb_module lib64/httpd/modules/mod_socache_shmcb.so # 151行目 : コメント解除 LoadModule ssl_module lib64/httpd/modules/mod_ssl.so # 526行目当たり : 追記 Include /etc/httpd/extra/slack-ssl.conf |
apache再起動
|
1 |
# /etc/rc.d/rc.httpd restart |
httpからhttpsリダイレクト
バーチャルホスト設定ファイルの編集
|
1 2 3 4 5 6 |
# cd /etc/httpd/extra # vi slack-vhosts.conf 下記を<VirtualHost *:80>~</VirtualHost>の中に追記する RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
apacheのメイン設定ファイルhttpd.confの編集
|
1 2 3 4 |
# cd /etc/httpd/ # vi httpd.conf #183行目当たり : コメント解除 LoadModule rewrite_module lib64/httpd/modules/mod_rewrite.so |
apache再起動
|
1 |
# /etc/rc.d/rc.httpd restart |
