LEMPスタックは、Linux、Nginx、MariaDB、およびPHPスタックの略です。ウェブサイトやブログをホストするために広く使用されている技術スタックです。
このチュートリアルでは、Ubuntu 16.04でPHPサポート(PHP-FPMを介して)およびMySQLサポートを使用してNginxをインストールする方法を示します。
LEMPスタックのインストール
Nginxをインストール
公式ウェブサイトから署名キーをダウンロードします。
wget http://nginx.org/keys/nginx_signing.key
nginxのインストール中の警告を回避するために追加してください。
sudo apt-key add nginx_signing.key
次の情報を配置して、Nginxリポジトリを追加します。
echo "deb http://nginx.org/packages/mainline/ubuntu xenial nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
リポジトリを更新します。
sudo apt-get update
次のコマンドを使用してNginxをインストールします。
sudo apt-get install -y nginx
インストール後にNginxサービスを開始します。
sudo systemctl start nginx
Webブラウザーを開き、http://your-ip-add-ressにアクセスします。
次のページが表示されます。このページでは、Nginxがサーバーに正常にインストールされていることを確認しています。

Ubuntu16.04のデフォルトのnginxドキュメントルートは/usr/ share / nginx /html/です。構成ファイルは/etc/nginxディレクトリにあります。
MariaDBのインストール
Ubuntu 16.04には、すでにサポートが終了しているMariaDBv10.0が同梱されています。そのため、公式リポジトリからMariaDBv10.4をインストールします。
システムにMariaDBリポジトリを追加します。
sudo apt-get install -y software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu xenial main' sudo apt-get update
以下のコマンドを使用してMariaDBをインストールします。
sudo apt-get install -y mariadb-server mariadb-client
次に、mysql_secure_installationコマンドを使用してMariaDBのインストールを保護します。
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): << No Password - Press Enter OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] N << Disabling Unix Socket login and enabling password Login ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y << Change MariaDB root password New password: << Enter Password Re-enter new password: << Re-Enter Password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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? [Y/n] Y << Remove Anonymous users ... 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? [Y/n] Y << Disallow root login remotely ... Success! By default, MariaDB 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? [Y/n] Y << Remove test database - 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? [Y/n] Y << Reload privilege ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
PHPのインストール
次に、PHP-FPM(PHP-FPM(FastCGI Process Manager)を介してPHPをインストールします。これは代替のPHP FastCGI実装です。あらゆるサイズのサイト、特に忙しいサイトに役立ついくつかの追加機能があります)。
Ubuntu 16.04には、すでにサポートが終了しているPHP-FPMv7.0が同梱されています。そのため、OndřejSurýリポジトリからPHP-FPMv7.3をインストールします。
読む: Ubuntu16.04にPHP7.3/ 7.2/7.1をインストールする方法
リポジトリを追加します。
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
次のコマンドを使用して、PHP-FPMv7.3をインストールします。
sudo apt-get install -y php7.3-fpm php7.3-mysql php7.3-cli
以下のファイルを編集して、Unixソケットの代わりにTCP接続を使用するようにPHP-FPMを構成します。
sudo nano /etc/php/7.3/fpm/pool.d/www.conf
以下のようにリッスンパラメータを変更します。
listen = 127.0.0.1:9000
LAMPスタックのテスト
次の詳細については、Nginxサーバー上に名前ベースの仮想ホストを作成しましょう。
サーバー名: server.itzgeek.local
ドキュメントルート: /usr/share/nginx/html/server.itzgeek.local
/etc/nginx/conf.d/ディレクトリの下にvirtual.confという構成ファイルを作成します。
sudo nano /etc/nginx/conf.d/virtual.conf
次のコンテンツを追加します。
server { server_name server.itzgeek.local; root /usr/share/nginx/html/server.itzgeek.local; location / { index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
ドキュメントのルートディレクトリを作成します。
sudo mkdir -p /usr/share/nginx/html/server.itzgeek.local
PHPをテストするには、作成した仮想ホストのドキュメントルートにPHPファイルを配置します。
ターミナルで次の行をコピーして貼り付けます:
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/server.itzgeek.local/index.php
サービスを再開します。
sudo systemctl restart nginx sudo systemctl restart php7.3-fpm
クライアントシステムの1つで、環境にDNSサーバーがない場合に備えて、/ etc / hostsファイルにドメイン(server.itzgeek.local)のホストエントリを作成します。
sudo nano /etc/hosts
ホストエントリは以下のようになります
192.168.1.10 server.itzgeek.local
次に、Webブラウザを開き、Webアドレスにドメインを入力します。
http://server.itzgeek.localページは次のようになります:
上のスクリーンショットから、PHPは機能しており、サーバーAPI行に示されているように、FPM/FastCGIを介して機能しています。

さらに下にスクロールすると、PHPで有効になっているすべてのモジュールが表示されます。以下のスクリーンショットは、MySQLモジュール情報を示しています。

結論
それで全部です。 Ubuntu16.04にLEMPスタックをインストールする方法を学んだことを願っています。セキュリティを向上させるために、ドメインにLet’sEncrypt証明書を設定することを検討してください。コメントセクションでフィードバックを共有してください。