GNU/Linux >> Linux の 問題 >  >> Ubuntu

Ubuntu 22.04にLAMPスタック(Apache、MariaDB、PHP)をインストールします

LAMPスタック(Linux、Apache、MariaDB / MySQL、およびPHP)は、ホスティング会社がWebサイトやブログをホストするために使用する最も広く使用されているソフトウェアテクノロジースタックです。さらに、このスタックは、WordPress、Drupal、Joomlaなどのコンテンツ管理システムをデプロイするために一般的に使用されます。

ここでは、Ubuntu20.04にLAMPスタックをインストールする方法を説明します。

AMPスタックのインストール

Ubuntuでは、Apache、MariaDB、PHPを1つずつ、または1つのコマンドでスタック全体をインストールすることで、AMPスタックを手動でインストールできます。

単一のコマンドを使用してAMPスタックをインストールすると、MySQLv8.0がインストールされます。ただし、同時に、LAMPスタックを手動でインストールすることを選択した場合は、MariaDBv10.6を入手できます。

方法1:LAMPスタックを手動で(1つずつ)インストールする

AMP(Apache v2.4、PHP v8.1、およびMariaDB v10.6)をUbuntu20.04にインストールします。

Apacheのインストール

まず、パッケージリポジトリのインデックスを更新します。

sudo apt update

次に、aptを使用してapache2パッケージをインストールします コマンド。

sudo apt install -y apache2 apache2-utils

MariaDBのインストール

MariaDBは、UbuntuのデフォルトのデータベースサーバーとしてMySQLに取って代わり、Ubuntuリポジトリから入手できます(v10.6)。

MariaDBリポジトリから最新バージョンのMariaDBをインストールすることもできます。

sudo apt install -y mariadb-server mariadb-client

次に、mysql_secure_installationを実行します MySQLのインストールを保護するコマンド。

sudo mysql_secure_installation

出力:

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): << Just 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  << Disable Unix Socket Authentication
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y << Set MariaDB root password
New password: xxx << Enter new MariaDB root password
Re-enter new password: xxx << Re-enter new MariaDB root 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 tables
 ... 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のインストール

デフォルトでは、Apacheサーバーは静的HTMLファイルの提供のみをサポートし、PHPはサポートしません。したがって、PHPサポートを有効にするために必要な場合は、PHPとMariaDB/MySQL用のPHP拡張パッケージをインストールする必要があります。

Ubuntu22.04にはPHPv8.1が付属しています。

sudo apt install -y php php-mysql libapache2-mod-php

インストール後、ApacheWebサーバーを再起動します。

sudo systemctl restart apache2

これで、LAMPスタックのテストに進むことができます。

方法2:単一のコマンドでLAMPスタックをインストールする

AMP(Apache v2.4、PHP v8.1、およびMySQL v8.0)をUbuntu20.04にインストールします。

aptコマンドを使用してリポジトリキャッシュを更新します。

sudo apt update

ターミナルの線の下に貼り付けて、Enterキーを押します。

sudo apt install -y lamp-server^

上記のコマンドは、LAMPサーバーに必要なパッケージを検索してインストールします。 LAMPスタックのインストールが完了するまで、数分待つ必要があります。

mysql_secure_installationを実行します MySQLのインストールを保護するコマンド。

sudo mysql_secure_installation

出力:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y << Enable validate password component to validate the strength of user passwords

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 << Level of password validation policy
Please set the password for root here.

New password: xxx << Set MySQL root password

Re-enter new password: xxx << Re-Enter MySQL root password

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y << Continue
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y << Disable root login remotely
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y << Reload tables
Success.

All done!
MySQLは、Ubuntuリポジトリからインストールされると、MySQLrootユーザーに対してUnixソケット認証メカニズムを使用します。この認証メカニズムにより、MySQLのrootユーザーはUnixソケット(#promptまたはsudo)からのみログインできます。

Unixソケット認証を無効にし、ネイティブパスワードメカニズムを有効にするには、次の手順に従います。

MariaDBrootユーザーとしてログインします。

sudo mysql -u root -p

パスワードは必要ありません

use mysql;

update user set plugin='mysql_native_password' where user='root';

flush privileges;

quit;

LAMPスタックのテスト

Apacheのデフォルトのドキュメントルートは/var/www/htmlです。 メインの設定ファイルは/etc/apache2/apache2.confです。 。仮想ホストやモジュールなどの追加の構成は、/etc/apache2/*-enabledにあります。 ディレクトリ。

PHPをテストするために、1つのPHPファイルをApacheのデフォルトのドキュメントルートに配置します。

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

次に、Webブラウザを開き、Webアドレスに次のように入力してテストページにアクセスします。

http://ip.ad.dr.ess/info.php

ページは以下のようになります。

ページを下にスクロールして、MySQL/MariaDBのPHP拡張機能の詳細を確認します。

結論

それで全部です。今では、Ubuntu20.04にLAMPスタックがあることを願っています。コメントセクションでフィードバックを共有してください。


Ubuntu
  1. Ubuntu18.04にLAMPスタックをインストールする方法

  2. LAMPスタックを使用してUbuntu18.04にWordPressをインストールする方法

  3. Ubuntu 20.04にPHPとApache(LAMPスタック)をインストールしてセットアップする方法

  1. Linux、Apache、MySQL、PHP(LAMP)スタックをUbuntu16.04にインストールする方法

  2. Ubuntu20.04にLAMPスタックを使用してWordPressをインストールする

  3. Debian 11にApache、MariaDB、PHP(LAMPスタック)をインストールする方法

  1. Linux、Apache、MySQL、PHP(LAMP)スタックをUbuntu 16.04 /Ubuntu14.04にインストールする方法

  2. Linux、Apache、MariaDB、PHP(LAMPスタック)をUbuntu18.04にインストールする方法

  3. Ubuntu 18.04 LTSにApache、MySQL、PHP(LAMP)スタックをインストールします