Debian 12でLEMPをインストールして設定する方法

このチュートリアルでは、高性能のウェブホスティングに必要なソフトウェアパッケージであるNginx、MariaDB、およびPHPのインストールと設定手順を説明します。これは、プレゼンテーションウェブサイト、ブログ、オンラインストアなどに適しています。

LEMPはLinux、Nginx、MySQL/MariaDB、PHPの頭文字であり、世界中の多くのウェブプロジェクトやウェブアプリケーションの基盤です。そうでなければ、stealthsettings.comの背後にあるすべてのこれらのパッケージが、ウェブサイトのオンライン動作を保証するためになければ、この記事を表示できないでしょう。

Debian は、以下をベースにしたオープンソース オペレーティング システムです。 Linux、安定性、セキュリティ、柔軟性で有名です。 長い歴史と活発な開発者コミュニティを持つ Debian は、ユーザーの多様なニーズを満たす幅広いソフトウェア パッケージとライブラリを提供しています。 このオペレーティング システムは、企業向けに信頼性が高く効率的なサーバーを作成するためによく使用されますが、個人使用にも適応できます。

Debian 12でLEMPをインストールして設定する方法

Debian 12 に LEMP をインストールして設定する前の最初のステップは、SSH 経由 (またはローカル アクセスがある場合はコンソールから直接) でサーバーに接続することです。 LEMP または管理システム (cPanel、cPanel など) からサーバーにパッケージがすでにインストールされていないことを確認してください。 VestaCP または他の人。

このチュートリアルの一連のコマンドは「」で始まります。sudo" ただし、ユーザー " でサーバーに接続している場合は、root"、 それは必要ない "sudo”をコマンドラインの前に置きます。 注文 "sudo」をコマンド ラインの前で使用して、一時的にスーパーユーザー権限を一般ユーザーに付与します。これにより、ソフトウェアのインストールや構成、システムの管理、その他の機密性の高い操作の実行など、特別な権限や保護されたリソースへのアクセスが必要なコマンドを実行できるようになります。

Update ソフトウェア。

LAMP のインストールを開始する前に、オペレーティング システムと既にインストールされているソフトウェア パッケージの両方を更新することをお勧めします。

sudo apt update
sudo apt upgrade

利用可能なパッケージがある場合は、 update、 プレス "Y」と尋ねると、次のようになります。

Do you want to continue? [Y/n] Y

Debian 12 での Nginx Web サーバーのインストールと構成

Web サーバーが Web ページを訪問者に提供するには、 Nginx Web Server 正しくインストールされ、構成されている必要があります。

sudo apt install nginx

タイプ "Y」をクリックして、Nginx Web Server のインストールを確認します。

Do you want to continue? [Y/n] Y
Install Debian 12 上の Nginx Web サーバー
Install Debian 12 上の Nginx Web サーバー

インストールプロセスの最後の行は次のようになります。

Setting up nginx-common (1.22.1-9) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up nginx (1.22.1-9) ...
Upgrading binary: nginx.
Processing triggers for man-db (2.11.2-2) ...

最後に、すべてが正しく動作していることを確認するために、次のアドレスにアクセスします。 IP Webブラウザで。 http://your_server_ip.

NGINX ページへようこそ
NGINX ページへようこそ

Nginx サービスはサーバー上で稼働しており、Web ページを提供する準備ができています。

関連する

Debian 12 での MariaDB サーバーのインストールと構成

MariaDB は、MySQL と比較して、パフォーマンスの向上、レプリケーション速度の高速化、セキュリティ対策の強化、および追加のストレージ エンジンを提供します。

以下のコマンドラインを実行し、「」と入力します。Y” インストールを確認します MariaDB Server.

sudo apt install mariadb-server

インストール後、スクリプトを実行して MariaDB サーバーを保護する必要があります。 mysql_secure_installation。 サーバーへのアクセスが制限され、未使用のアカウントが削除されます。

コマンドラインを実行します。

sudo mysql_secure_installation

プレス "Enter「現在のユーザーのパスワードについて」root"

Debian 12でLEMPをインストールして設定する方法
安全な SQL #1
Switch to unix_socket authentication [Y/n] Y

パスワードを設定する MariaDB:

Change the root password? [Y/n] Y     
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

次に、権限とデータベースを削除します。 default インストール中 MariaDB Server.

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

アカウントに上記で設定したパスワード「root」はリモートサーバーにログインするときに必要です。 リモート。 これはのパスワードです MariaDB.

SQL Server のインストールをテストします。

root@mars:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.11.3-MariaDB-1 Debian 12

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select version();
+-------------------+
| version()         |
+-------------------+
| 10.11.3-MariaDB-1 |
+-------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> quit
Bye
root@mars:~# 

Debian 12 での PHP / PHP-FPM のインストールと構成

このステップまですべてがうまくいった場合、Debian 12 に LEMP をインストールして構成するには、PHP ソフトウェアも必要です。 Nginx で PHP をサポートするには、PHP-FPM もインストールする必要があります。

sudo apt install php-fpm php-mysql php-gd php-cli php-curl php-mbstring php-zip php-opcache php-xml

インストールプロセスが完了するまで待ちます PHP-FPM、最も重要な PHP モジュールとともに。

最終的に、チュートリアルでインストールできました PHP 8.2 Debian 12 オペレーティング システム上で。

root@mars:~# php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
root@mars:~# 

この時点で、LEMP のすべての要素がインストールされましたが、まだいくつかの設定を行う必要があります。 Nginx PHP ファイルを実行します。

PHP ファイルを実行するための NGINX の構成

ページの Nginx を設定するには、「default"、 編集 "/etc/nginx/sites-enabled/default"。 私は」nano」を編集してください。

「」に置き換えてくださいlocation /" この線:

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
     }

次の行で:

location / {
    try_files $uri $uri/ /index.php?$args;
    }

次に、ブロック「」に以下の行を追加します。server」を使用して、Nginx が PHP を処理できるようにします。

location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php/php-fpm.sock;
     }
}
Debian 12でLEMPをインストールして設定する方法
Debian 12でLEMPをインストールして設定する方法

ファイルを保存して構成を確認します。

root@mars:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@mars:~# 

構成テストが成功した場合は、サービスを再起動します nginx.

sudo systemctl restart nginx

Debian 12 に LEMP が正常にインストールされ、設定されているかどうかをテストします。

Debian 12 (LEMP) に Nginx、MariaDB、および PHP をインストールして構成したら、すべてが機能するかどうかをテストします。 テストするには、info.php ファイルを作成するのが最も簡単です。

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

ブラウザでアクセス」https://your_server_ip/info.php"

PHPのバージョン情報
PHPのバージョン情報

PHP ページは、Debian 12 用の LEMP が正常にインストールされたことを意味します。

おめでとう!

テクノロジーに情熱を持っており、喜んで記事を書いています StealthSettings2006 年から .com を運営しています。私はオペレーティング システムに関して豊富な経験を持っています。 macOS, Windows シ Linuxだけでなく、プログラミング言語やブログ プラットフォームでも使用できます (WordPress) およびオンライン ストアの場合 (WooCommerce、Magento、PrestaShop)。

» ウェブホスティング » Debian 12でLEMPをインストールして設定する方法
コメント