linux:fedora:install_lamp

Fedora による LAMP(Apache, MySQL, PHP) 環境構築

Apache をインストールするために、以下のコマンドを実行する。

$ sudo dnf install httpd httpd-devel

メタデータの期限切れの最終確認: 1:43:48 時間前の 2022年09月20日 01時54分49秒 に実施しました。
パッケージ httpd-2.4.54-3.fc36.x86_64 は既にインストールされています。
依存関係が解決しました。
==============================================================================================================
 パッケージ                      アーキテクチャー   バージョン                      リポジトリー        サイズ
==============================================================================================================
インストール:
 httpd-devel                     x86_64             2.4.54-3.fc36                   updates             191 k
依存関係のインストール:
 apr-devel                       x86_64             1.7.0-16.fc36                   fedora              211 k
 apr-util-devel                  x86_64             1.6.1-20.fc36                   fedora               70 k
 autoconf                        noarch             2.71-2.fc36                     fedora              718 k
 automake                        noarch             1.16.5-7.fc36                   updates             675 k
 cyrus-sasl-devel                x86_64             2.1.27-18.fc36                  fedora              102 k
 expat-devel                     x86_64             2.4.7-1.fc36                    fedora               52 k
 libdb-devel                     x86_64             5.3.28-51.fc36                  fedora               37 k
 libtool                         x86_64             2.4.7-1.fc36                    updates             593 k
 m4                              x86_64             1.4.19-3.fc36                   fedora              296 k
 openldap-devel                  x86_64             2.6.2-3.fc36                    updates             686 k
 perl-File-Compare               noarch             1.100.600-486.fc36              fedora               18 k
 perl-File-Copy                  noarch             2.35-486.fc36                   fedora               25 k
 perl-Thread-Queue               noarch             3.14-479.fc36                   fedora               21 k
 perl-threads                    x86_64             1:2.26-449.fc36                 fedora               57 k
 perl-threads-shared             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                

完了しました!

$ sudo systemctl enable httpd.service

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

デフォルトゾーンとアクティブゾーンを確認する🤔

$ firewall-cmd --get-zones

FedoraServer FedoraWorkstation block dmz drop external home internal libvirt nm-shared public trusted work

$ firewall-cmd --get-default-zone
FedoraWorkstation

$ firewall-cmd --get-active-zones

FedoraWorkstation
  interfaces: wlp2s0

デフォルトゾーンとアクティブゾーンを FedoraServer へ変更する🤔

$ sudo firewall-cmd --set-default-zone=FedoraServer

success

$ sudo firewall-cmd --zone=FedoraServer --change-interface=wlp2s0

success

$ firewall-cmd --get-active-zones

FedoraServer
  interfaces: wlp2s0

ローカルなネットワークではないインターネットのサーバーでは、Web サーバーに必要のないポートは永続的な許可を削除する🤔

$ firewall-cmd --list-services

cockpit dhcpv6-client ssh

$ sudo firewall-cmd --permanent --remove-service={ssh,cockpit}

success

Web サーバーに必要な http、https プロトコルを永続的に許可する🤤

$ sudo firewall-cmd --permanent --add-service={http,https} && sudo firewall-cmd --reload

success
success

$ firewall-cmd --list-services

dhcpv6-client http https

ファイヤウォール定義の変更は、リロード sudo firewall-cmd --reload するまで有効になっていない🤔
上記は以下のコマンドを順番に実行したのと同じです🤔 (以下は実行する必要は無い)

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
$ sudo firewall-cmd --reload

--add-service=http--add-service=httpsを一括実行するには、--add-service={http,https}のように bash のブレース展開が利用できる🤤
ブレース展開とは rpmbuild でもディレクトリツリーを作成する例にも見られるが、mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}rpmdev-setuptree は同じである🤔
参考: bashのブレース展開についてまとめ - Qiita

$ sudo systemctl start httpd.service

MySQL をインストールするために、以下のコマンドを実行する。

$ sudo dnf install mariadb mariadb-server

MySQL(Linux)

$ sudo systemctl enable mariadb.service

Fedora で RPM Fusion, Remi リポジトリを利用する

PHP をインストールするために、以下のコマンドを実行する。

$ 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
$ sudo vi /etc/php.ini
;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

※PHP アプリが Pragma: no-cache ヘッダーを吐かないように session.cache_limiter = public とする事もできる。
 ただし、DokuWiki などの ?do=edit (編集ページ) もキャッシュされて動作不良の原因となる。
 以下のようにメディア配信に限定してキャッシュをオンにする事ができる。

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
...

lib/exe/fetch.php への要求に対して環境変数 X_CACHE_HEADER をセットして、メディア配信要求に限定して Pragma ヘッダの cacheset する。

$ sudo systemctl restart httpd.service
$ sudo systemctl restart php-fpm.service

sendmail をインストールする。

$ sudo dnf install sendmail
$ sudo systemctl enable sendmail
$ sudo systemctl start sendmail
  • linux/fedora/install_lamp.txt
  • 最終更新: 2024/04/18 15:52
  • by 非ログインユーザー