この記事では、LAMP環境の構築手順を詳しく紹介していますので、参考になると思いますので、困っている方は参考にしていただければ幸いです。
CentOS 7 を最小限インストールした後、ifconfig コマンドを直接入力すると、「ifconfig コマンドが見つかりません」というメッセージが表示されます。
, 最小限のインストールでは関連ソフトウェアがインストールされないことを示しています。ネットワーク カードの詳細を表示するには、ifconfig の代わりに ip addr を使用するか、yum install を使用できます。
net-tools を使用して ifconfig コマンドをインストールします。インストール プロセス中に y を 2 回入力して、インストールを完了します。
1. Apache
yum install httpd
//Apache をインストールします
1 2 3 | Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]:
|
ログイン後にコピー
1 2 3 4 5 6 7 | Retrieving key from file:
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-5.1804.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]:
|
ログイン後にコピー
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-80.el7.centos.1.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-80.el7.centos.1.x86_64 5/5
Verifying : mailcap-2.1.41-2.el7.noarch 1/5
Verifying : httpd-tools-2.4.6-80.el7.centos.1.x86_64 2/5
Verifying : apr-util-1.5.2-6.el7.x86_64 3/5
Verifying : apr-1.4.8-3.el7_4.1.x86_64 4/5
Verifying : httpd-2.4.6-80.el7.centos.1.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-80.el7.centos.1
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-80.el7.centos.1
mailcap.noarch 0:2.1.41-2.el7
Complete!
|
ログイン後にコピー
Apache サービスを開いて設定しますシステムの起動時にサービスが自動的に開始されます。
systemctl start httpd.service
systemctl enable httpd.service
次のことを可能にするために、外部から Web サーバーにアクセスするには、ファイアウォールで HTTP (80) ポートと HTTPS (443) ポートを開く必要があります。 CentOS のデフォルトのファイアウォールは firewalld で、firewalld-cmd コマンドを使用して構成できます。
firewall-cmd --permanent --zone = public --add-service = http
firewall-cmd --permanent --zone = public --add-service = https
firewall-cmd --reload
//firewalldを再起動します
Apacheサービスが開いているかどうかを検出します:
systemctl status httpd.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2018-08-06 20:14:21 CST; 9s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 1498 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─1498 /usr/sbin/httpd -DFOREGROUND
├─1499 /usr/sbin/httpd -DFOREGROUND
├─1500 /usr/sbin/httpd -DFOREGROUND
├─1501 /usr/sbin/httpd -DFOREGROUND
├─1502 /usr/sbin/httpd -DFOREGROUND
└─1503 /usr/sbin/httpd -DFOREGROUND
Aug 06 20:14:21 localhost systemd[1]: Starting The Apache HTTP Server...
Aug 06 20:14:21 localhost httpd[1498]: AH00558: httpd: Could not reliably determine the server's f...sage
Aug 06 20:14:21 localhost systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
|
ログイン後にコピー
ブラウザを使用してサーバーの IP アドレスを入力します。

##次のようなインターフェイスが表示された場合図では、インストールは成功しています。
2. MySQL/MariaDB
MariaDB データベース管理システムは MySQL のブランチであり、主にオープン ソース コミュニティによって保守され、GPL に基づいてライセンスされています。
このブランチを開発した理由の 1 つは、Oracle が MySQL を買収した後、ソースとしての MySQL を閉鎖する潜在的なリスクがあったため、コミュニティはこのリスクを回避するためにブランチ アプローチを採用したことです。
MariaDB は、API やコマンド ラインを含め、MySQL との完全な互換性を目指しており、現在最も人気のある MySQL データベースの派生データベースであり、オープン ソース データベース MySQL の代替としてもみなされています。
ここでは MySQL の代わりに MariaDB を使用しますが、MySQL のインストール方法と操作方法はほぼ同様です。
インストール時に、mariadb を mysql に置き換えます;
サービスを開始、停止し、ステータスを確認し、mariadb.service を mysql.service に置き換えます。
yum -y install mariadb-server mariadb //MariaDB をインストールします
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | Installed:
mariadb.x86_64 1:5.5.56-2.el7 mariadb-server.x86_64 1:5.5.56-2.el7
Dependency Installed:
perl.x86_64 4:5.16.3-292.el7 perl-Carp.noarch 0:1.26-244.el7
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Encode.x86_64 0:2.51-7.el7
perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7
perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7
perl- Getopt -Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PathTools.x86_64 0:3.40-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
perl-Pod-Escapes.noarch 1:1.04-292.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7
perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7
perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7
perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7
perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7
perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-292.el7
perl-macros.x86_64 4:5.16.3-292.el7 perl-parent.noarch 1:0.225-244.el7
perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7
perl-threads-shared.x86_64 0:1.43-6.el7
Complete!
|
ログイン後にコピー
MariaDB サービスを有効にし、システム起動時にサービスが自動的に開始されるように設定します:
systemctl start mariadb.service
systemctl enable mariadb.service
MySQL root アカウントのパスワードを設定します:
mysql_secure_installation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 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
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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new 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]
... 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]
... 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]
- 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]
... 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!
|
ログイン後にコピー
3. PHP
yum install php //phpをインストールします
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | Total download size: 4.7 M
Installed size: 17 M
Is this ok [y/d/N]:
Downloading packages:
(1/4): libzip-0.10.1-8.el7.x86_64.rpm | 48 kB 00:00:00
(2/4): php-5.4.16-45.el7.x86_64.rpm | 1.4 MB 00:00:01
(3/4): php-common-5.4.16-45.el7.x86_64.rpm | 565 kB 00:00:01
(4/4): php-cli-5.4.16-45.el7.x86_64.rpm | 2.7 MB 00:00:02
---------------------------------------------------------------------------------------------------------
Total 2.1 MB/s | 4.7 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libzip-0.10.1-8.el7.x86_64 1/4
Installing : php-common-5.4.16-45.el7.x86_64 2/4
Installing : php-cli-5.4.16-45.el7.x86_64 3/4
Installing : php-5.4.16-45.el7.x86_64 4/4
Verifying : php-5.4.16-45.el7.x86_64 1/4
Verifying : php-cli-5.4.16-45.el7.x86_64 2/4
Verifying : libzip-0.10.1-8.el7.x86_64 3/4
Verifying : php-common-5.4.16-45.el7.x86_64 4/4
Installed:
php.x86_64 0:5.4.16-45.el7
Dependency Installed:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-45.el7 php-common.x86_64 0:5.4.16-45.el7
Complete!
|
ログイン後にコピー
データベースとphpを関連付けるにはphp-mysql もインストールする必要があります。
yum install php-mysql //インストールを完了するには、インストール プロセス中に y を入力します。
systemctl restart httpd.service //php をインストールした後、Apache サービスを再起動します
php がインストールされているかどうかをテストします:
vi /var/www/html/index.php //新しい php ファイルを作成し、次の内容を入力します
前の URL の後に /info.php を追加します。次のインターフェイスが表示されれば、インストールは成功しています。
# おすすめ関連記事:
thinkPHP フレームワークのビューの説明 (コード付き)
以上がLAMP環境をセットアップするにはどうすればよいですか? LAMP環境構築の具体的な流れの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。