GNU/Linux >> Linux の 問題 >  >> Debian

Debian 8 VPSにLEMP(Linux、Nginx、MySQL、PHP-FPM)をインストールする方法

この記事では、Debian 8 VPSにLEMP(Linux、Nginx、MySQL、PHP-FPM)をインストールする手順を説明します。
LEMPスタックは、LEMPサーバーまたはLEMPWebサーバーの同義語です。 Linux、Nginx、MySQL(MariaDB)、PHPを含むセットアップを指します。


要件

このチュートリアルでは、SSD 1LinuxVPSホスティングプランを使用します。

システムを更新する

以下を使用して、サーバーが完全に最新であることを確認してください:

# apt-get update && apt-get upgrade

NGINXをインストール

Debian 8サーバーにNginxをインストールするには、次のコマンドを実行する必要があります。

# apt-get install nginx

インストールが完了したら、次のコマンドでNginxを起動できます:

# systemctl start nginx

Nginxが起動時に開始できるようにします:

# systemctl enable nginx

考えられる問題:

Nginxのインストール中に、次のようなエラーが発生した場合:

dpkg: error processing package nginx (--configure):
dependency problems - leaving unconfigured
Processing triggers for systemd (215-17+deb8u1) ...
Errors were encountered while processing:
nginx-full
nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

次に、デフォルトのNginx構成ファイルを開き、 listen [::]:80 default_server;にコメントすることでこれを修正できます。 ライン。次のコマンドを入力します:

# vim /etc/nginx/sites-available/default

listen [::]:80 default_server;を見つけます 行を作成し、行の前に#を付けてコメントします。変更を有効にするためにNginxを再起動し、install Nginxコマンドを実行して、パッケージマネージャーがNginxの構成を完了するようにします。

# systemctl restart nginx

# apt-get install nginx

Webブラウザーを開き、サーバーのIPアドレス(http:// server_ip)にアクセスして、Nginxが実行されていることを確認します。以下のようなNginxウェルカムページが表示されます:

MYSQLをインストールする

それでは、MySQLをインストールしましょう。次を発行します:

# apt-get install mysql-server

インストール中に、MySQLrootユーザーのパスワードを入力するように求められます。解読しやすいパスワードは入力しないでください。大文字と小文字を組み合わせた8文字以上を含める必要があります。

MySQLがインストールされたので、次を実行してMySQLの安全なインストールを実行することをお勧めします。

# mysql_secure_installation

ルートパスワードを入力し、MySQLルートパスワードの変更を求められたら「n」で答えます。以下は、実行できる手順全体です。

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
... skipping.

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? [Y/n] 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? [Y/n] 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? [Y/n] y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed!  Not critical, keep moving...
- 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
... Success!

Cleaning up...


All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

MySQLが起動時に起動できるようにします:

# systemctl enable mysql

PHP-FPMのインストール

下のコマンドを実行してPHP-FPMをインストールします:

# apt-get install php5-fpm php5-mysql

次のステップは、Nginx構成ファイルを変更することです。ただし、デフォルトのNginxファイルで編集またはコメントアウトする必要のある行を探すのを避けるために、ファイルの名前を変更して新しいファイルを作成しましょう。以下のコマンドはまさにそれを行います:

# mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

# vim /etc/nginx/sites-available/default

これで、新しいデフォルトファイルが開いたので、次のコンテンツを貼り付けます。

server {
        listen       80;
        server_name  your_website_name.com;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        location / {
                try_files $uri $uri/ =404;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /var/www/html;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

ファイルを保存して終了します。

それでは、簡単なPHPページテストを作成しましょう。 PHP情報ページを作成して、PHPのバージョン、アクティブ化されたモジュールなどを確認できるようにします…

ファイルを作成します。info.phと呼びましょう。 / var / www / htmlにp ディレクトリ:

 # vim /var/www/html/info.php

以下をファイルに貼り付けます:

<?php
phpinfo();
?>

変更を有効にするためにNginxを再起動します:

# systemctl restart nginx

次に、お気に入りのWebブラウザーを開き、http://your_server_ip_address/info.phpに移動します。以下のようなWebページで歓迎されます:

それでおしまい。 LEMPが正常にインストールされました Debian8VPSにスタックします。

もちろん、Linux VPSホスティングサービスのいずれかを使用している場合は、これを行う必要はありません。その場合は、専門のLinux管理者にLEMPスタックのインストールを依頼するだけです。 24時間年中無休でご利用いただけます。リクエストはすぐに処理されます。

PS。この投稿が気に入った場合は、左側のボタンを使用してソーシャルネットワーク上の友達と共有するか、下に返信を残してください。ありがとう。


Debian
  1. CentOS 7 VPSにLEMP(Linux、Nginx、MariaDB、PHP-FPM)をインストールする方法

  2. Debian8VPSにDotclearをインストールする方法

  3. Debian 8 VPSにLEMP(Linux、Nginx、MySQL、PHP-FPM)をインストールする方法

  1. MySQLコミュニティサーバーをDebian9StretchLinuxにインストールする方法

  2. Debian8VPSにJamroomをインストールする方法

  3. Debian8VPSにNginxを使用してFuelPHPをインストールする方法

  1. MySQLをDebian11にインストールする方法

  2. Debian 6(スクイーズ)VPSにLEMP(Nginx、MySQL、PHP)サーバーをインストールして設定する方法

  3. Debian 11 に LEMP Stack Nginx、MySQL、PHP をインストールする方法