Nginx、MariaDB、PHP7.2は(LEMP)と呼ばれます。以下は、Ubuntu18.04LTSにLEMPをインストールする手順です。
- Ubuntuパッケージを更新しましょう。
# sudo apt update
# sudo apt upgrade - NginxWebサーバーをインストールします。これは高性能サーバーであり、リバースプロキシとして使用されます。
# sudo apt install Nginx
- Nginxを起動して有効にします。起動時にNginxを自動起動します。
# sudo systemctl start nginx
# sudo systemctl enable nginx - 以下のコマンドでNginxのバージョンを確認できます。
# nginx -v
nginx version: nginx/1.14.0 (Ubuntu)
ブラウザでサーバーのIPアドレスにアクセスすると、デフォルトのNginxページが表示されます。
www-data(Nginxユーザー)をWebディレクトリの所有者として設定できます。
# sudo chown www-data:www-data /usr/share/nginx/html -R
- 以下のコマンドでMariaDBをインストールします。 MariaDBはMySQLの代替品です。
# sudo apt install mariadb-server mariadb-client
- MariaDBを起動して有効にします。起動時にMariaDBを自動起動します。
# sudo systemctl start mariadb
# sudo systemctl enable mariadb - インストール後のセキュリティスクリプトについては、以下のコマンドを実行してください。
# sudo mysql_secure_installation
- MySQLルートパスワードを入力し、パスワードを確認して、必要な構成を設定します。
- 以下のコマンドでMariaDBのバージョンを確認します。
# mariadb --version
以下の出力が得られます。
# mariadb Ver 15.1 Distrib 10.1.43-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
- デフォルトでは、PHP7.2は18.04のデフォルトのUbuntuリポジトリに含まれています。ただし、以下のコマンドを入力して、いくつかの一般的な拡張機能を使用してphp7.2をインストールしてください。
# sudo apt install php7.2 php7.2-fpm php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
- PHP7.2-fpmを起動して有効にする起動時にPHPを自動起動します。
# sudo systemctl start php7.2-fpm
# sudo systemctl enable php7.2-fpm - 以下のコマンドを実行して、sites-enabledディレクトリのデフォルトのシンボリックリンクを削除します。
# sudo rm /etc/nginx/sites-enabled/default
- /etc/nginx/conf.d/ディレクトリ内に新しいサーバーブロックファイルを作成します。
# sudo nano /etc/nginx/conf.d/default.conf
- default.confに以下のテキストを追加します
server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html/; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } # A long browser cache lifetime can speed up repeat visits to your page location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ { access_log off; log_not_found off; expires 360d; } # disable access to hidden files location ~ /\.ht { access_log off; log_not_found off; deny all; } }
- 保存して閉じ、Nginxサービスを再起動します。
# sudo systemctl reload nginx
- PHP-FPMをNGINXWebサーバーでテストします。ルートディレクトリにphpinfo.phpページを作成しましょう。
# sudo nano /usr/share/nginx/html/info.php
- 以下のようにphp情報コードを貼り付けます。
<?php phpinfo();>