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

LAMP をインストールまたはアップグレードする方法:Yum を使用した Linux、Apache、MySQL、および PHP スタック

以前、Apache と PHP をソースからインストールする方法について説明しました。ソースから LAMP スタックをインストールすると、さまざまなパラメーターを完全に制御できます。

LAMP スタックのインストール yum の使用 非常に簡単で、数分しかかかりません。これは、ソースからのインストールが苦手な初心者に適したオプションです。また、物事をシンプルに保ち、デフォルト構成のみを使用したい場合は、yum を使用して LAMP スタックをインストールすることをお勧めします。

1. Yum を使用して Apache をインストールする

# rpm -qa | grep httpd

[Note: If the above command did not return anything,
          install apache as shown below]

# yum install httpd

Apache が正常にインストールされたことを確認します

# rpm -qa | grep -i http

httpd-tools-2.2.9-1.fc9.i386
httpd-2.2.9-1.fc9.i386

chkconfig を使用して、システムの起動時に httpd サービスが自動的に開始されるようにします。以下に示すように Apache を起動します。

# chkconfig httpd on

# service httpd start
Starting httpd:                   [  OK  ]

2. Yum を使用して Apache をアップグレードする

Linux のインストール中に Web サーバー パッケージを選択した場合、Apache は既に Linux にインストールされています。その場合、以下に示すように Apache を最新バージョンにアップグレードできます。

Apache が既にインストールされているかどうかを確認してください。

# rpm -qa | grep -i http

httpd-tools-2.2.8-3.i386
httpd-2.2.8-3.i386
[Note: This indicates that Apache 2.2.8 version is installed already]

yum を使用して、最新バージョンの Apache をインストールできるかどうかを確認してください。

# yum check-update httpd

Loaded plugins: refresh-packagekit
httpd.i386      2.2.9-1.fc9       updates
[Note: This indicates that the latest Apache version 2.2.9
       is available for upgrade]

yum を使用して Apache を最新バージョンにアップグレードします。

# yum update httpd

yum update httpd の出力 コマンド:

Loaded plugins: refresh-packagekit
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i386 0:2.2.9-1.fc9 set to be updated
--> Processing Dependency: httpd-tools = 2.2.9-1.fc9 for package: httpd
--> Running transaction check
---> Package httpd-tools.i386 0:2.2.9-1.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Updating:
httpd                   i386       2.2.9-1.fc9      updates           975 k
httpd-tools             i386       2.2.9-1.fc9      updates            69 k

Transaction Summary
=============================================================================
Install      0 Package(s)
Update       2 Package(s)
Remove       0 Package(s)

Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): httpd-tools-2.2.9-1.fc9.i386.rpm                  |  69 kB     00:00
(2/2): httpd-2.2.9-1.fc9.i386.rpm                        | 975 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating       : httpd-tools                                       [1/4]
Updating       : httpd                                             [2/4]
Cleanup        : httpd                                             [3/4]
Cleanup        : httpd-tools                                       [4/4]

Updated: httpd.i386 0:2.2.9-1.fc9 httpd-tools.i386 0:2.2.9-1.fc9
Complete!

Apache が正常にアップグレードされたかどうかを確認してください。

# rpm -qa | grep -i http

httpd-tools-2.2.9-1.fc9.i386
httpd-2.2.9-1.fc9.i386
[Note: This indicates that Apache was upgraded to 2.2.9 successfully]

3. Yum を使用して MySQL をインストール

Yum は、すべての依存関係を識別して自動的にインストールするのが非常にスマートです。たとえば、yum を使用して mysql-server をインストールすると、以下に示すように、依存する mysql-libs、perl-DBI、mysql、perl-DBD-MySQL パッケージも自動的にインストールされます。

# yum install mysql-server

yum install mysql-server の出力 コマンド:

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.0.51a-1.fc9 set to be updated
--> Processing Dependency: libmysqlclient_r.so.15 for mysql-server
--> Processing Dependency: libmysqlclient.so.15 for mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: mysql = 5.0.51a-1.fc9 for package: mysql-server
--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
--> Running transaction check
---> Package mysql.i386 0:5.0.51a-1.fc9 set to be updated
---> Package mysql-libs.i386 0:5.0.51a-1.fc9 set to be updated
---> Package perl-DBD-MySQL.i386 0:4.005-8.fc9 set to be updated
---> Package perl-DBI.i386 0:1.607-1.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
mysql-server            i386       5.0.51a-1.fc9    fedora            9.8 M
Installing for dependencies:
mysql                   i386       5.0.51a-1.fc9    fedora            2.9 M
mysql-libs              i386       5.0.51a-1.fc9    fedora            1.5 M
perl-DBD-MySQL          i386       4.005-8.fc9      fedora            165 k
perl-DBI                i386       1.607-1.fc9      updates           776 k

Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-DBD-MySQL-4.005-8.fc9.i386.rpm           | 165 kB     00:00
(2/5): perl-DBI-1.607-1.fc9.i386.rpm                 | 776 kB     00:00
(3/5): mysql-libs-5.0.51a-1.fc9.i386.rpm             | 1.5 MB     00:00
(4/5): mysql-5.0.51a-1.fc9.i386.rpm                  | 2.9 MB     00:00
(5/5): mysql-server-5.0.51a-1.fc9.i386.rpm           | 9.8 MB     00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : mysql-libs                                        [1/5]
Installing     : perl-DBI                                          [2/5]
Installing     : mysql                                             [3/5]
Installing     : perl-DBD-MySQL                                    [4/5]
Installing     : mysql-server                                      [5/5]

Installed: mysql-server.i386 0:5.0.51a-1.fc9
Dependency Installed:
  mysql.i386 0:5.0.51a-1.fc9 mysql-libs.i386 0:5.0.51a-1.fc9
  perl-DBD-MySQL.i386 0:4.005-8.fc9 perl-DBI.i386 0:1.607-1.fc9
Complete!

MySQL が正しくインストールされているかどうかを確認してください。

# rpm -qa | grep -i mysql

php-mysql-5.2.6-2.fc9.i386
mysql-libs-5.0.51a-1.fc9.i386
mysql-server-5.0.51a-1.fc9.i386
perl-DBD-MySQL-4.005-8.fc9.i386
mysql-5.0.51a-1.fc9.i386

# mysql -V

mysql  Ver 14.12 Distrib 5.0.51a, for redhat-linux-gnu (i386) using readline 5.0

システムの起動時に MySQL が自動的に起動するように構成します。

# chkconfig mysqld on

MySQL サービスを開始します。

# service mysqld start

初めて mysqld を起動すると、以下に示すように、インストール後の構成を実行するように指示する追加情報メッセージが表示されます。

Initializing MySQL database:
Installing MySQL system tables... OK
Filling help tables... OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h dev-db password 'new-password'

Alternatively you can run: /usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
highly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com

Starting MySQL:                                            [  OK  ]

4. MySQL のインストール後のアクティビティを実行する

mysql のインストール後、以下に示すように、パスワードを入力せずに mysql ルート アカウントにログインできます。

# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

この問題を解決するには、以下に示すように mysql root アカウントにパスワードを割り当てる必要があります。次のアクティビティを実行する mysql_secure_installation スクリプトを実行します:

  • root パスワードを割り当てる
  • 匿名ユーザーを削除する
  • リモート マシンからのルート ログインを許可しない
  • デフォルトのサンプル テスト データベースを削除する
# /usr/bin/mysql_secure_installation

mysql_secure_installation スクリプトの出力:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

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

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

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...
... 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 MySQL
installation should now be secure.
Thanks for using MySQL!

MySQL のインストール後のアクティビティを確認します:

# mysql -u root

ERROR 1045 (28000):Access denied for user 'root'@'localhost'(using password:NO)
[Note: root access without password is denied]

# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)
[Note: test database is removed]

5. Yum を使用して MySQL をアップグレード

MySQL が既にインストールされているかどうかを確認してください。

# rpm -qa | grep -i mysql

yum を使用して、MySQL の最新バージョンをインストールできるかどうかを確認してください。

# yum check-update mysql-server

yum を使用して MySQL を最新バージョンにアップグレードします。

# yum update mysql-server

6. Yum を使用して PHP をインストール

# yum install php

yum install php の出力 :

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php.i386 0:5.2.6-2.fc9 set to be updated
--> Processing Dependency: php-common = 5.2.6-2.fc9 for package: php
--> Processing Dependency: php-cli = 5.2.6-2.fc9 for package: php
--> Running transaction check
---> Package php-common.i386 0:5.2.6-2.fc9 set to be updated
---> Package php-cli.i386 0:5.2.6-2.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php                     i386       5.2.6-2.fc9      updates           1.2 M
Installing for dependencies:
php-cli                 i386       5.2.6-2.fc9      updates           2.3 M
php-common              i386       5.2.6-2.fc9      updates           228 k

Transaction Summary
=============================================================================
Install      3 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 3.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-common-5.2.6-2.fc9.i386.rpm  | 228 kB     00:00
(2/3): php-5.2.6-2.fc9.i386.rpm         | 1.2 MB     00:00
(3/3): php-cli-5.2.6-2.fc9.i386.rpm     | 2.3 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : php-common     [1/3]
Installing     : php-cli        [2/3]
Installing     : php            [3/3]

Installed: php.i386 0:5.2.6-2.fc9
Dependency Installed: php-cli.i386 0:5.2.6-2.fc9 php-common.i386 0:5.2.6-2.fc9
Complete!

PHP が正常にインストールされたことを確認してください。

# rpm -qa | grep -i php

php-cli-5.2.6-2.fc9.i386
php-5.2.6-2.fc9.i386
php-common-5.2.6-2.fc9.i386

PHP 用の MySQL モジュールをインストールします。

# yum search php-mysql

Loaded plugins: refresh-packagekit
=========== Matched: php-mysql =============
php-mysql.i386 : A module for PHP applications that use MySQL databases

# yum install php-mysql

yum install php-mysql の出力 :

Loaded plugins: refresh-packagekit
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.i386 0:5.2.6-2.fc9 set to be updated
--> Processing Dependency: php-pdo for package: php-mysql
--> Running transaction check
---> Package php-pdo.i386 0:5.2.6-2.fc9 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php-mysql               i386       5.2.6-2.fc9      updates            81 k
Installing for dependencies:
php-pdo                 i386       5.2.6-2.fc9      updates            62 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 143 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-pdo-5.2.6-2.fc9.i386.rpm     |  62 kB     00:00
(2/2): php-mysql-5.2.6-2.fc9.i386.rpm   |  81 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : php-pdo                [1/2]
Installing     : php-mysql              [2/2]

Installed: php-mysql.i386 0:5.2.6-2.fc9
Dependency Installed: php-pdo.i386 0:5.2.6-2.fc9
Complete!

追加の PHP モジュールが必要な場合は、以下に示すように yum を使用してインストールしてください。

# yum install php-common php-mbstring php-mcrypt php-devel php-xml php-gd

7. Yum を使用して PHP をアップグレード

PHP がインストールされているかどうかを確認してください。

# rpm -qa | grep -i php

yum を使用して最新バージョンの PHP をインストールできるかどうかを確認してください。

# yum check-update php

yum を使用して PHP を最新バージョンにアップグレードします。

# yum update php

yum を使用してインストールした追加の PHP モジュールをアップグレードします。

# yum check-update php-common php-mbstring php-mcrypt php-devel php-xml php-gd

# yum update php-common php-mbstring php-mcrypt php-devel php-xml php-gd

以下に示すように、test.php ファイルを作成して、PHP のインストールを確認します。

# cat /var/www/html/test.php

<? phpinfo(); ?>

ブラウザ http://{lamp-server-ip}/test.php から test.php を呼び出すと、すべての PHP 構成情報とインストールされているモジュールが表示されます。

この記事が気に入ったら、del.icio.us でブックマークしてください そしてつまずく .


Linux
  1. Rocky Linux / Centos 8にApacheとPHP(LAMPスタック)をインストールする方法

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

  3. Debian 9にLAMP(Linux、Apache、MySQL、PHP)をインストールする方法

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

  2. CentOS 7.3(LAMP)にApache、PHP 7.1、MySQLをインストールする方法

  3. Debian 11 に LAMP Apache、MySQL、PHP をインストールする方法

  1. CentOS 7.4(LAMP)にApache、PHP 7.2、MySQLをインストールする方法

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

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