文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Fedora による LAMP(Apache, MySQL, PHP) 環境構築 ====== ===== Web サーバーのインストール ===== Apache をインストールするために、以下のコマンドを実行する。 <WRAP color_term> <WRAP color_command><html><pre> $ sudo dnf install httpd httpd-devel </pre></html></WRAP> <WRAP color_result_long><html><pre> メタデータの期限切れの最終確認: 1:43:48 時間前の 2022年09月20日 01時54分49秒 に実施しました。 パッケージ httpd-2.4.54-3.fc36.x86_64 は既にインストールされています。 依存関係が解決しました。 ============================================================================================================== パッケージ アーキテクチャー バージョン リポジトリー サイズ ============================================================================================================== インストール: <b class=GRN>httpd-devel</b> x86_64 2.4.54-3.fc36 updates 191 k 依存関係のインストール: <b class=GRN>apr-devel</b> x86_64 1.7.0-16.fc36 fedora 211 k <b class=GRN>apr-util-devel</b> x86_64 1.6.1-20.fc36 fedora 70 k <b class=GRN>autoconf</b> noarch 2.71-2.fc36 fedora 718 k <b class=GRN>automake</b> noarch 1.16.5-7.fc36 updates 675 k <b class=GRN>cyrus-sasl-devel</b> x86_64 2.1.27-18.fc36 fedora 102 k <b class=GRN>expat-devel</b> x86_64 2.4.7-1.fc36 fedora 52 k <b class=GRN>libdb-devel</b> x86_64 5.3.28-51.fc36 fedora 37 k <b class=GRN>libtool</b> x86_64 2.4.7-1.fc36 updates 593 k <b class=GRN>m4</b> x86_64 1.4.19-3.fc36 fedora 296 k <b class=GRN>openldap-devel</b> x86_64 2.6.2-3.fc36 updates 686 k <b class=GRN>perl-File-Compare</b> noarch 1.100.600-486.fc36 fedora 18 k <b class=GRN>perl-File-Copy</b> noarch 2.35-486.fc36 fedora 25 k <b class=GRN>perl-Thread-Queue</b> noarch 3.14-479.fc36 fedora 21 k <b class=GRN>perl-threads</b> x86_64 1:2.26-449.fc36 fedora 57 k <b class=GRN>perl-threads-shared</b> x86_64 1.62-479.fc36 fedora 44 k トランザクションの概要 ============================================================================================================== インストール 16 パッケージ ダウンロードサイズの合計: 3.7 M インストール後のサイズ: 14 M これでよろしいですか? [y/N]: y パッケージのダウンロード: (1/16): apr-devel-1.7.0-16.fc36.x86_64.rpm 402 kB/s | 211 kB 00:00 (2/16): apr-util-devel-1.6.1-20.fc36.x86_64.rpm 116 kB/s | 70 kB 00:00 (3/16): autoconf-2.71-2.fc36.noarch.rpm 920 kB/s | 718 kB 00:00 (4/16): cyrus-sasl-devel-2.1.27-18.fc36.x86_64.rpm 342 kB/s | 102 kB 00:00 (5/16): expat-devel-2.4.7-1.fc36.x86_64.rpm 195 kB/s | 52 kB 00:00 (6/16): libdb-devel-5.3.28-51.fc36.x86_64.rpm 261 kB/s | 37 kB 00:00 (7/16): perl-File-Copy-2.35-486.fc36.noarch.rpm 175 kB/s | 25 kB 00:00 (8/16): perl-File-Compare-1.100.600-486.fc36.noarch.rpm 75 kB/s | 18 kB 00:00 (9/16): m4-1.4.19-3.fc36.x86_64.rpm 891 kB/s | 296 kB 00:00 (10/16): perl-Thread-Queue-3.14-479.fc36.noarch.rpm 162 kB/s | 21 kB 00:00 (11/16): perl-threads-2.26-449.fc36.x86_64.rpm 433 kB/s | 57 kB 00:00 (12/16): perl-threads-shared-1.62-479.fc36.x86_64.rpm 330 kB/s | 44 kB 00:00 (13/16): httpd-devel-2.4.54-3.fc36.x86_64.rpm 360 kB/s | 191 kB 00:00 (14/16): automake-1.16.5-7.fc36.noarch.rpm 895 kB/s | 675 kB 00:00 (15/16): libtool-2.4.7-1.fc36.x86_64.rpm 594 kB/s | 593 kB 00:00 (16/16): openldap-devel-2.6.2-3.fc36.x86_64.rpm 1.2 MB/s | 686 kB 00:00 -------------------------------------------------------------------------------------------------------------- 合計 1.0 MB/s | 3.7 MB 00:03 トランザクションの確認を実行中 トランザクションの確認に成功しました。 トランザクションのテストを実行中 トランザクションのテストに成功しました。 トランザクションを実行中 準備 : 1/1 インストール中 : perl-threads-1:2.26-449.fc36.x86_64 1/16 インストール中 : apr-devel-1.7.0-16.fc36.x86_64 2/16 インストール中 : perl-threads-shared-1.62-479.fc36.x86_64 3/16 インストール中 : perl-Thread-Queue-3.14-479.fc36.noarch 4/16 インストール中 : perl-File-Copy-2.35-486.fc36.noarch 5/16 インストール中 : perl-File-Compare-1.100.600-486.fc36.noarch 6/16 インストール中 : m4-1.4.19-3.fc36.x86_64 7/16 インストール中 : autoconf-2.71-2.fc36.noarch 8/16 インストール中 : automake-1.16.5-7.fc36.noarch 9/16 インストール中 : libtool-2.4.7-1.fc36.x86_64 10/16 インストール中 : libdb-devel-5.3.28-51.fc36.x86_64 11/16 インストール中 : expat-devel-2.4.7-1.fc36.x86_64 12/16 インストール中 : cyrus-sasl-devel-2.1.27-18.fc36.x86_64 13/16 インストール中 : openldap-devel-2.6.2-3.fc36.x86_64 14/16 インストール中 : apr-util-devel-1.6.1-20.fc36.x86_64 15/16 インストール中 : httpd-devel-2.4.54-3.fc36.x86_64 16/16 scriptletの実行中: httpd-devel-2.4.54-3.fc36.x86_64 16/16 検証 : apr-devel-1.7.0-16.fc36.x86_64 1/16 検証 : apr-util-devel-1.6.1-20.fc36.x86_64 2/16 検証 : autoconf-2.71-2.fc36.noarch 3/16 検証 : cyrus-sasl-devel-2.1.27-18.fc36.x86_64 4/16 検証 : expat-devel-2.4.7-1.fc36.x86_64 5/16 検証 : libdb-devel-5.3.28-51.fc36.x86_64 6/16 検証 : m4-1.4.19-3.fc36.x86_64 7/16 検証 : perl-File-Compare-1.100.600-486.fc36.noarch 8/16 検証 : perl-File-Copy-2.35-486.fc36.noarch 9/16 検証 : perl-Thread-Queue-3.14-479.fc36.noarch 10/16 検証 : perl-threads-1:2.26-449.fc36.x86_64 11/16 検証 : perl-threads-shared-1.62-479.fc36.x86_64 12/16 検証 : automake-1.16.5-7.fc36.noarch 13/16 検証 : httpd-devel-2.4.54-3.fc36.x86_64 14/16 検証 : libtool-2.4.7-1.fc36.x86_64 15/16 検証 : openldap-devel-2.6.2-3.fc36.x86_64 16/16 インストール済み: apr-devel-1.7.0-16.fc36.x86_64 apr-util-devel-1.6.1-20.fc36.x86_64 autoconf-2.71-2.fc36.noarch automake-1.16.5-7.fc36.noarch cyrus-sasl-devel-2.1.27-18.fc36.x86_64 expat-devel-2.4.7-1.fc36.x86_64 httpd-devel-2.4.54-3.fc36.x86_64 libdb-devel-5.3.28-51.fc36.x86_64 libtool-2.4.7-1.fc36.x86_64 m4-1.4.19-3.fc36.x86_64 openldap-devel-2.6.2-3.fc36.x86_64 perl-File-Compare-1.100.600-486.fc36.noarch perl-File-Copy-2.35-486.fc36.noarch perl-Thread-Queue-3.14-479.fc36.noarch perl-threads-1:2.26-449.fc36.x86_64 perl-threads-shared-1.62-479.fc36.x86_64 完了しました! </pre></html></WRAP> </WRAP> ===== Web サーバーの自動起動設定 ===== <WRAP color_term> <WRAP color_command><html><pre> $ sudo systemctl enable httpd.service </pre></html></WRAP> <WRAP color_result><html><pre> Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. </pre></html></WRAP> </WRAP> ===== firewalld の設定 ===== [[linux:commands:network:firewall-cmd|firewalld (Linux)]]\\ ==== ゾーンの変更 (FedoraWorkstation -> FedoraServer) ==== デフォルトゾーンとアクティブゾーンを確認する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --get-zones </pre></html></WRAP> <WRAP color_result><html><pre> FedoraServer FedoraWorkstation block dmz drop external home internal libvirt nm-shared public trusted work </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --get-default-zone FedoraWorkstation </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --get-active-zones </pre></html></WRAP> <WRAP color_result><html><pre> FedoraWorkstation interfaces: wlp2s0 </pre></html></WRAP> </WRAP> デフォルトゾーンとアクティブゾーンを **FedoraServer** へ変更する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> sudo firewall-cmd --set-default-zone=FedoraServer </pre></html></WRAP> <WRAP color_result><html><pre> success </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> sudo firewall-cmd --zone=FedoraServer --change-interface=wlp2s0 </pre></html></WRAP> <WRAP color_result><html><pre> success </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --get-active-zones </pre></html></WRAP> <WRAP color_result><html><pre> FedoraServer interfaces: wlp2s0 </pre></html></WRAP> </WRAP> ==== Web サーバーに必要な http、https のみを許可 ==== ローカルなネットワークではないインターネットのサーバーでは、Web サーバーに必要のないポートは永続的な許可を削除する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --list-services </pre></html></WRAP> <WRAP color_result><html><pre> cockpit dhcpv6-client ssh </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> sudo firewall-cmd --permanent --remove-service={ssh,cockpit} </pre></html></WRAP> <WRAP color_result><html><pre> success </pre></html></WRAP> </WRAP> Web サーバーに必要な http、https プロトコルを永続的に許可する🤤\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> sudo firewall-cmd --permanent --add-service={http,https} && sudo firewall-cmd --reload </pre></html></WRAP> <WRAP color_result><html><pre> success success </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> firewall-cmd --list-services </pre></html></WRAP> <WRAP color_result><html><pre> dhcpv6-client http https </pre></html></WRAP> </WRAP> ファイヤウォール定義の変更は、リロード <html><code>sudo firewall-cmd --reload</code></html> するまで有効になっていない🤔\\ 上記は以下のコマンドを順番に実行したのと同じです🤔 (以下は実行する必要は無い)\\ <WRAP color_term> <WRAP color_result><html><pre> $ sudo firewall-cmd --permanent --add-service=http $ sudo firewall-cmd --permanent --add-service=https $ sudo firewall-cmd --reload </pre></html></WRAP> </WRAP> <html><code>--add-service=http</code></html>、<html><code>--add-service=https</code></html>を一括実行するには、<html><code>--add-service={http,https}</code></html>のように bash のブレース展開が利用できる🤤\\ ブレース展開とは [[linux:fedora:rpmbuild|rpmbuild]] でもディレクトリツリーを作成する例にも見られるが、<html><code>mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}</code></html> と <html><code>rpmdev-setuptree</code></html> は同じである🤔\\ 参考: [[qita>ine1127/items/6e5fe80f4a9c64509558|bashのブレース展開についてまとめ - Qiita]]\\ ===== Web サーバーの起動 ===== <code> $ sudo systemctl start httpd.service </code> ===== データベースサーバーのインストール ===== MySQL をインストールするために、以下のコマンドを実行する。 <code> $ sudo dnf install mariadb mariadb-server </code> [[linux:mysql|MySQL(Linux)]]\\ ===== データベースサーバーの自動起動設定 ===== <code> $ sudo systemctl enable mariadb.service </code> ===== スクリプト言語のインストール ===== ==== RPM Fusion, Remi リポジトリの追加 ==== [[linux:fedora:rpmfusion|Fedora で RPM Fusion, Remi リポジトリを利用する]]\\ PHP をインストールするために、以下のコマンドを実行する。 <code> $ sudo dnf install php php-pear php-common php-gd php-mysqlnd php-mbstring php-mcrypt php-xml php-pecl-apcu php-pecl-apcu-bc php-pecl-zip php-json --enablerepo=remi </code> ==== PHP の設定 ==== <code> $ sudo vi /etc/php.ini </code> <code> ;display_errors = Off display_errors = Off ;enable_dl = Off enable_dl = On ;upload_max_filesize = 2M upload_max_filesize = 32M ;date.timezone = date.timezone = Asia/Tokyo session.cache_limiter = nocache ;session.cache_limiter = public ;mbstring.internal_encoding = EUC-JP mbstring.internal_encoding = UTF-8 ;mbstring.detect_order = auto mbstring.detect_order = auto </code> ※PHP アプリが **Pragma: no-cache** ヘッダーを吐かないように **session.cache_limiter = public** とする事もできる。\\ ただし、DokuWiki などの **?do=edit (編集ページ)** もキャッシュされて動作不良の原因となる。\\ 以下のようにメディア配信に限定してキャッシュをオンにする事ができる。\\ <file autoconf dokuwiki/.htaccess> ... RewriteRule lib/exe/fetch\.php - [E=X_CACHE_HEADER] RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L] RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L] RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L] RewriteRule ^$ doku.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) doku.php?id=$1 [QSA,L] RewriteRule ^index.php$ doku.php Header always set Pragma cache env=X_CACHE_HEADER ... </file> **lib/exe/fetch.php** への要求に対して環境変数 **X_CACHE_HEADER** をセットして、メディア配信要求に限定して **Pragma** ヘッダの **cache** を **set** する。\\ ===== Web サーバーの再起動 ===== <code> $ sudo systemctl restart httpd.service $ sudo systemctl restart php-fpm.service </code> ===== PHP の mail 機能を利用する場合 ===== sendmail をインストールする。\\ <code> $ sudo dnf install sendmail $ sudo systemctl enable sendmail $ sudo systemctl start sendmail </code> ===== 参考文献 ===== [[http://www.mysql-apache-php.com/centos-lamp-server.htm|Quick 'n' Easy LAMP Server for Centos/RHEL]]\\ [[https://www.atmarkit.co.jp/ait/articles/1602/25/news017.html|CentOS 7の標準環境だけですぐできる、WordPress「5.4倍高速化」テクニック 前編:とにかく速いWordPress(3)(1/3 ページ) - @IT]]\\ [[qita>nnmr/items/a521fb4e18931cc647d6|php-fpmのエラーにぶつかりながら設定の最適化を図る - Qiita]]\\ [[https://spot13.com/pmcalculator/|PHP-FPM Process Caluculator]]\\ ==== 付録 ==== [[tw>tomoyan596/status/1368578023558057999|「ApacheのMPMって2.4からデフォルトが変わってるんですねぇ🤔ずっとpreforkだと思ってテキトーに設定していました😅💦 テキトーな人で困りますねぇ🤤」 / Twitter]]\\ [[tw>tomoyan596sp/status/1512944842099535872|😍これが欲しかったです😊👍]]\\ linux/fedora/install_lamp.txt 最終更新: 2024/04/18 15:52by 非ログインユーザー