Contents
1. Apache2
1.1 インストール
1 2 |
# cd /usr/ports/www/apache24 # make config |
たくさんのオプションがありますが、デフォルトのまま進めます
確認が終わったら、インストールします。
1 |
# make |
IPv6だけチェックを外し、その他はデフォルトでよい
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# make install clean ===> Installing for apache24-2.4.62 ===> Checking if apache24 is already installed ===> Registering installation for apache24-2.4.62 Installing apache24-2.4.62... ===> Creating groups Using existing group 'www' ===> Creating users Using existing user 'www' To run apache www server from startup, add apache24_enable="yes" in your /etc/rc.conf. Extra options can be found in startup script. Your hostname must be resolvable using at least 1 mechanism in /etc/nsswitch.conf typically DNS or /etc/hosts or apache might have issues starting depending on the modules you are using. - apache24 default build changed from static MPM to modular MPM - more modules are now enabled per default in the port - icons and error pages moved from WWWDIR to DATADIR If build with modular MPM and no MPM is activated in httpd.conf, then mpm_prefork will be activated as default MPM in etc/apache24/modules.d to keep compatibility with existing php/perl/python modules! Please compare the existing httpd.conf with httpd.conf.sample and merge missing modules/instructions into httpd.conf! ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/apache24/mod_cgid.so If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports included in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern. For more information, and contact details about the security status of this software, see the following webpage: https://httpd.apache.org/ ===> Cleaning for apr-1.7.5.1.6.3_3 ===> Cleaning for gdbm-1.24 ===> Cleaning for jansson-2.14 ===> Cleaning for apache24-2.4.62 |
1.2 apache24 - 初期設定
①extra/httpd-default.conf 編集
1 2 3 4 5 6 7 8 |
# vi /usr/local/etc/apache24/extra/httpd-default.conf セキュリティ対策のために以下のように設定を変更します。 55行目 : 「ProductOnly」に変更 ServerTokens ProductOnly 75行目 : 「On」に変更 HostnameLookups On |
➁httpd.conf 編集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# vi /usr/local/etc/apache24/httpd.conf 160行目 : コメント解除 LoadModule dav_module libexec/apache24/mod_dav.so 217行目 : 管理者のメールアドレスに変更 ServerAdmin [管理者メールアドレス] 226行目 : サーバのドメイン名に変更する ServerName [ドメイン名] 264行目 : 「Indexes」削除 Options FollowSymLinks 前項で設定した、「/usr/local/etc/apache24/extra/httpd-default.conf」への設定を有効にするために、下記の先頭の「#」を削除して、「Include」を有効にします。 518行目 : コメント解除 Include etc/apache24/extra/httpd-default.conf |
1.3 apache の起動
apacheの起動を有効化
1 2 |
# service apache24 enable apache24 enabled in /etc/rc.conf |
起動停止用のスクリプトは/usr/local/etc/rc.d/apache24
設定ファイルのチェック
記述が正しければ、Syntax OK と出力される
1 2 3 |
# service apache24 configtest Performing sanity check on apache24 configuration: Syntax OK |
Apache起動
1 2 3 4 |
# service apache24 start Performing sanity check on apache24 configuration: Syntax OK Starting apache24. |
クライアントから、サーバにアクセス(http://サーバーIPアドレス[またはドメイン名])すると下記のような表示が出れば正常です
1.4 バーチャルホストの設定
ドキュメントルート : /usr/local/www/apache24/data/[FQDN]/
ドメイン : [FQDN]
としてバーチャルホストを設定します
1 2 3 |
# vi /usr/local/etc/apache24/httpd.conf 最後のほうに下記を記入 Include etc/apache24/extra/bsd-vhost.conf |
/usr/local/etc/apache24/extra配下にbsd-vhost.conf新規作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# cd /usr/local/etc/apache24/extra # vi bsd-vhost.conf 下記内容で作成 <VirtualHost *:80> ServerAdmin 管理者メールアドレス DocumentRoot "/usr/local/www/apache24/data/[FQDN]" ServerName [FQDN] ErrorLog "/var/log/httpd/[FQDN].error_log" CustomLog "/var/log/httpd/[FQDN].access_log" common </VirtualHost> <Directory /usr/local/www/apache24/data/[FQDN]> AddHandler cgi-script .cgi Options FollowSymlinks Includes AllowOverride All Require all granted </Directory> |
ディレクトリー作成
1 2 3 4 5 |
# mkdir /var/log/httpd # mkdir /usr/local/www/apache24/data/[FQDN] # chown -R www:www /usr/local/www/apache24/data/[FQDN] |
Apache再起動
1 2 3 4 5 6 7 8 |
# service apache24 restart Performing sanity check on apache24 configuration: Syntax OK Stopping apache24. Waiting for PIDS: 56749. Performing sanity check on apache24 configuration: Syntax OK Starting apache24. |
1.5 apache24 - cgi を動作
インストール時のオプションの確認
以下のコマンドでインストール時のオプションを確認します。
1 2 |
# cd /usr/ports/www/apache24 # make config |
デフォルトで「CGI」もしくは「CGID」のどちらかもしくは両方にチェックが入っていますのですでにインストールされています。
もしチェックがはいっていなければ、チェックをいれて「make clean」「make」「make reinstall」します。
「The default MPM Module」のどれにチェックが入っているかを確認しておきます。外れていればチェックして再インストール。3 つの中は択一ですのでどれかひとつしかチェックできません
p5-CGI インストール
下記コマンドでインストールされているか確認
(portversionを利用するにはportupgradeを事前にインストール済であること)
1 2 3 |
# portversion -v | grep p5-CGI [Reading data from pkg(8) ... - 156 packages found - done] p5-CGI-4.66 = up-to-date with port |
もし、インストールされていなければ下記コマンドでインストールする
1 2 3 |
# cd /usr/ports/www/p5-CGI # make # make install |
httpd.conf の編集
1 2 3 4 5 6 7 8 9 10 11 12 |
# vi /usr/local/etc/apache24/httpd.conf 166、169行のコメント解除 <IfModule !mpm_prefork_module> LoadModule cgid_module libexec/apache24/mod_cgid.so </IfModule> <IfModule mpm_prefork_module> LoadModule cgi_module libexec/apache24/mod_cgi.so </IfModule> 431行目 : コメント解除 AddHandler cgi-script .cgi |
Apache再起動
1 2 3 4 5 6 7 8 |
# service apache24 restart Performing sanity check on apache24 configuration: Syntax OK Stopping apache24. Waiting for PIDS: 56818. Performing sanity check on apache24 configuration: Syntax OK Starting apache24. |
2. MySQLインストール
PHPをインストールする前にMySQLをインストールしておきます。
1 |
# pkg install -y mysql80-client mysql80-server |
バージョンを確認
1 2 |
# mysql --version mysql Ver 8.0.39 for FreeBSD14.1 on amd64 (Source distribution) |
MySQL を有効にして起動
1 2 3 4 |
# sysrc mysql_enable=yes mysql_enable: -> yes # service mysql-server start Starting mysql. |
MySQL 起動確認
1 2 |
# service mysql-server status mysql is running as pid 59141. |
セキュリティ スクリプトの実行
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# mysql_secure_installation mysql_secure_installation: [ERROR] unknown variable 'prompt=\u@\h [\d]>\_'. Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! |
以降mysqlサーバーにログインするには
mysql -u root -p
Enter password: 上記で設定したパスワード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# mysql -u root -p Enter password: 上記で設定したパスワード Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.33 Source distribution Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. root@localhost [(none)]> |
3. apache24 - PHP 8.3
3.1 PHPインストール
1 2 |
# cd /usr/ports/lang/php83 # make config |
スレッドセーフに動作させるには「ZTS」のオプションが必須になります。
あとは、デフォルトのまま
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# make install clean Installing php83-8.3.14... ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/lib/libphp.so /usr/local/bin/php /usr/local/bin/php-cgi /usr/local/sbin/php-fpm If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports included in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern. For more information, and contact details about the security status of this software, see the following webpage: https://www.php.net/ ===> Cleaning for re2c-3.0 ===> Cleaning for py311-docutils-0.21.2,1 ===> Cleaning for libargon2-20190702_1 ===> Cleaning for php83-8.3.14 |
3.2 php83-extensionsインストール
1 2 |
# cd /usr/ports/lang/php83-extensions # make config |
デフォルトでチェックされているものは、チェックをはずさないように。
「WordPress」をインストールする予定があれば、更新のために「CURL」は、必須でチェックします。
「GD」「GETTEXT」も他のモジュールで使うことがあるのでチェックしておいた方がよい。
日本語を使用するのであれば「MBSTRING」は、必須でチェック
「MySQL」を使用するのであれば「MYSQLI」は、必須でチェック
「WordPress」をインストールする予定があれば「ZLIB」は、必須でチェック
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 29 30 31 |
いろいろ問い合わせ画面が出るがすべてデフォルトでEnter # make install clean ---------------------------------------------------------------------- --- all --- Build complete. Don't forget to run 'make test'. ===> Staging for php83-zlib-8.3.14 ===> php83-zlib-8.3.14 depends on file: /usr/local/include/php/main/php.h - found ===> Generating temporary packing list ====> Compressing man pages (compress-man) ===> Installing for php83-zlib-8.3.14 ===> Checking if php83-zlib is already installed ===> Registering installation for php83-zlib-8.3.14 as automatic Installing php83-zlib-8.3.14... This file has been added to automatically load the installed extension: /usr/local/etc/php/ext-20-zlib.ini.sample ===> php83-extensions-1.0 depends on file: /usr/local/lib/php/20230831-zts/zlib.so - found ===> Returning to build of php83-extensions-1.0 ===> Generating temporary packing list ====> Compressing man pages (compress-man) ===> Installing for php83-extensions-1.0 ===> Checking if php83-extensions is already installed ===> Registering installation for php83-extensions-1.0 Installing php83-extensions-1.0... ===> Cleaning for php83-ctype-8.3.14 . . . |
3.3 mod_php83 インストール
1 2 |
# cd /usr/ports/www/mod_php83 # make config |
前項までと同様、「ZTS」オプションにチェックをいれます。
ほかは、デフォルトのままにしておきます
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# make install clean Installing mod_php83-8.3.7... [activating module `php' in /usr/local/etc/apache24/httpd.conf] ****************************************************************************** Consider switching to php-fpm and mod_fast_cgi as per Apache httpd project recommendation. See https://cwiki.apache.org/confluence/display/HTTPD/PHP-FPM ****************************************************************************** If you are building PHP-based ports in poudriere(8) or Synth with ZTS enabled, add WITH_MPM=event to /etc/make.conf to prevent build failures. ****************************************************************************** Make sure index.php is part of your DirectoryIndex. You should add the following to your Apache configuration file: <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> ****************************************************************************** ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/apache24/libphp.so If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports included in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern. For more information, and contact details about the security status of this software, see the following webpage: https://www.php.net/ ===> Cleaning for mod_php83-8.3.7 |
3.4 PHP - 初期設定
①コンフィグレーションファイル「php.ini」の設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# cd /usr/local/etc/ # cp php.ini-production php.ini # vi /usr/local/etc/php.ini 713行目 post_max_size = 300M 865行目 upload_max_filesize = 200M 989行目タイムゾーンの設定、コメント解除し"Asia/Tokyo"追記 [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = "Asia/Tokyo" |
➁httpd.conf の編集
1 2 3 4 5 6 7 8 9 10 11 |
# vi /usr/local/etc/apache24/httpd.conf 284行目 ディレクトリのインデックスとして「index.php index.cgi」を使う <IfModule dir_module> DirectoryIndex index.html index.php index.cgi ←追記 </IfModule> 423行目当たりに 以下の2行を追記。 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps |
Apache設定チェック
Syntax OKと表示されれば正常
1 2 3 |
# service apache24 configtest Performing sanity check on apache24 configuration: Syntax OK |
Apache再起動
1 2 3 4 5 6 7 8 |
# service apache24 restart Performing sanity check on apache24 configuration: Syntax OK Stopping apache24. Waiting for PIDS: 57824. Performing sanity check on apache24 configuration: Syntax OK Starting apache24. |
3.5 PHP動作確認
ウェブサーバのドキュメントルートに「info.php」を作成
1 2 3 4 |
# vi /usr/local/www/apache24/data/[FQDN]/info.php <?php phpinfo(); ?> |
ブラウザで「http://[FQDN]/info.php」にアクセスすると下記のように表示されればOK