CentOS 7/RHEL 7: 如何安装LAMP工具(Apache, MariaDB,PHP)

CentOS 和RHEL 官方发布的最新版centos 7 和rhel 7系统有了很大的改变,那么如何在新的centos 7 和rhel 7 系统上搭建LAMP server.
centos 7 lamp

1.安装并配置apache 服务器

通过yum安装apache web 服务器:
[cc lang=”php”]
yum install httpd
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-18.el7.centos will be installed
–> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================
Package Arch Version Repository Size
==============================================================================================
Installing:
httpd x86_64 2.4.6-18.el7.centos updates 2.7 M
Transaction Summary
==============================================================================================
Install 1 Package
Total download size: 2.7 M
Installed size: 9.3 M
Is this ok [y/d/N]: y
Downloading packages:
httpd-2.4.6-18.el7.centos.x86_64.rpm | 2.7 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.6-18.el7.centos.x86_64 1/1
Verifying : httpd-2.4.6-18.el7.centos.x86_64 1/1
Installed:
httpd.x86_64 0:2.4.6-18.el7.centos
Complete!
[/cc]
设置apache服务器在系统启动的时候自动启动
[cc lang=”php”]
systemctl enable httpd.service
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# systemctl enable httpd.service
ln -s ‘/usr/lib/systemd/system/httpd.service’ ‘/etc/systemd/system/multi-user.target.wants/httpd.service’
[/cc]
centos 7 下启动httpd 服务
[cc lang=”php”]
systemctl start httpd.service
[/cc]

2. 在centos 7 系统上安装MariaDB

通过yum 命令来安装MariaDB 服务器:
[cc lang=”php”]
yum install mariadb-server mariadb
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# yum install mariadb-server mariadb
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Resolving Dependencies
–> Running transaction check
—> Package mariadb.x86_64 1:5.5.40-1.el7_0 will be installed
–> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.40-1.el7_0 for package: 1:mariadb-5.5.40-1.el7_0.x86_64
—> Package mariadb-server.x86_64 1:5.5.40-1.el7_0 will be installed
–> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.40-1.el7_0.x86_64
–> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.40-1.el7_0.x86_64
–> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.40-1.el7_0.x86_64
–> Running transaction check
—> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be updated
—> Package mariadb-libs.x86_64 1:5.5.40-1.el7_0 will be an update
—> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed
—> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
–> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
–> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
–> Running transaction check
—> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
–> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Running transaction check
—> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
–> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
–> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
—> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
–> Running transaction check
—> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
—> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================
Package Arch Version Repository Size
==============================================================================================
Installing:
mariadb x86_64 1:5.5.40-1.el7_0 updates 8.9 M
mariadb-server x86_64 1:5.5.40-1.el7_0 updates 11 M
Installing for dependencies:
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Updating for dependencies:
mariadb-libs x86_64 1:5.5.40-1.el7_0 updates 753 k
Transaction Summary
==============================================================================================
Install 2 Packages (+7 Dependent packages)
Upgrade ( 1 Dependent package)
Total size: 22 M
Total download size: 21 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00
(2/9): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00
(3/9): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00
(4/9): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00
(5/9): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00
(6/9): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00
(7/9): mariadb-5.5.40-1.el7_0.x86_64.rpm | 8.9 MB 00:00:07
(8/9): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm | 140 kB 00:00:07
(9/9): mariadb-server-5.5.40-1.el7_0.x86_64.rpm | 11 MB 00:00:13
———————————————————————————————-
Total 1.6 MB/s | 21 MB 00:00:13
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:mariadb-libs-5.5.40-1.el7_0.x86_64 1/11
Installing : 1:mariadb-5.5.40-1.el7_0.x86_64 2/11
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 3/11
Installing : perl-Net-Daemon-0.48-5.el7.noarch 4/11
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 5/11
Installing : perl-IO-Compress-2.061-2.el7.noarch 6/11
Installing : perl-PlRPC-0.2020-14.el7.noarch 7/11
Installing : perl-DBI-1.627-4.el7.x86_64 8/11
Installing : perl-DBD-MySQL-4.023-5.el7.x86_64 9/11
Installing : 1:mariadb-server-5.5.40-1.el7_0.x86_64 10/11
Cleanup : 1:mariadb-libs-5.5.35-3.el7.x86_64 11/11
Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/11
Verifying : perl-Net-Daemon-0.48-5.el7.noarch 2/11
Verifying : 1:mariadb-5.5.40-1.el7_0.x86_64 3/11
Verifying : 1:mariadb-server-5.5.40-1.el7_0.x86_64 4/11
Verifying : 1:mariadb-libs-5.5.40-1.el7_0.x86_64 5/11
Verifying : perl-PlRPC-0.2020-14.el7.noarch 6/11
Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 7/11
Verifying : perl-DBI-1.627-4.el7.x86_64 8/11
Verifying : perl-IO-Compress-2.061-2.el7.noarch 9/11
Verifying : perl-DBD-MySQL-4.023-5.el7.x86_64 10/11
Verifying : 1:mariadb-libs-5.5.35-3.el7.x86_64 11/11
Installed:
mariadb.x86_64 1:5.5.40-1.el7_0 mariadb-server.x86_64 1:5.5.40-1.el7_0
Dependency Installed:
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-5.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
Dependency Updated:
mariadb-libs.x86_64 1:5.5.40-1.el7_0
Complete!
[/cc]
启动mariadb 服务,输入:
[cc lang=”php”]
systemctl start mariadb.service
[/cc]
设置mariadb 服务器在系统启动时候启用,输入命令:
[cc lang=”php”]
systemctl enable mariadb.service
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# systemctl enable mariadb.service
ln -s ‘/usr/lib/systemd/system/mariadb.service’ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service’
[/cc]
Mariadb 权限配置
输入下面的命令:
[cc lang=”php”]
./usr/bin/mysql_secure_installation
[/cc]
命令输出:
[cc lang=”php”]
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] Y
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] 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!
[/cc]
测试MariaDB是否安装成功,输入下面的命令:
[cc lang=”php”]
mysql -u root -p
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.40-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
+——————–+
3 rows in set (0.01 sec)
[/cc]

3. 在centos 7 上安装PHP

使用yum命令安装php包和其相关的软件包:
[cc lang=”php”]
yum install php php-mysql php-gd php-pear
[/cc]
命令输出:
[cc lang=”php”]
[root@osetc /]# yum install php php-mysql php-gd php-pear
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Resolving Dependencies
–> Running transaction check
—> Package php.x86_64 0:5.4.16-23.el7_0.3 will be installed
–> Processing Dependency: php-common(x86-64) = 5.4.16-23.el7_0.3 for package: php-5.4.16-23.el7_0.3.x86_64
–> Processing Dependency: php-cli(x86-64) = 5.4.16-23.el7_0.3 for package: php-5.4.16-23.el7_0.3.x86_64
—> Package php-gd.x86_64 0:5.4.16-23.el7_0.3 will be installed
–> Processing Dependency: libt1.so.5()(64bit) for package: php-gd-5.4.16-23.el7_0.3.x86_64
—> Package php-mysql.x86_64 0:5.4.16-23.el7_0.3 will be installed
–> Processing Dependency: php-pdo(x86-64) = 5.4.16-23.el7_0.3 for package: php-mysql-5.4.16-23.el7_0.3.x86_64
—> Package php-pear.noarch 1:1.9.4-21.el7 will be installed
–> Processing Dependency: php-xml for package: 1:php-pear-1.9.4-21.el7.noarch
–> Processing Dependency: php-posix for package: 1:php-pear-1.9.4-21.el7.noarch
–> Running transaction check
—> Package php-cli.x86_64 0:5.4.16-23.el7_0.3 will be installed
—> Package php-common.x86_64 0:5.4.16-23.el7_0.3 will be installed
–> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-23.el7_0.3.x86_64
—> Package php-pdo.x86_64 0:5.4.16-23.el7_0.3 will be installed
—> Package php-process.x86_64 0:5.4.16-23.el7_0.3 will be installed
—> Package php-xml.x86_64 0:5.4.16-23.el7_0.3 will be installed
—> Package t1lib.x86_64 0:5.1.2-14.el7 will be installed
–> Running transaction check
—> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================
Package Arch Version Repository Size
==============================================================================================
Installing:
php x86_64 5.4.16-23.el7_0.3 updates 1.3 M
php-gd x86_64 5.4.16-23.el7_0.3 updates 124 k
php-mysql x86_64 5.4.16-23.el7_0.3 updates 97 k
php-pear noarch 1:1.9.4-21.el7 base 357 k
Installing for dependencies:
libzip x86_64 0.10.1-8.el7 base 48 k
php-cli x86_64 5.4.16-23.el7_0.3 updates 2.7 M
php-common x86_64 5.4.16-23.el7_0.3 updates 561 k
php-pdo x86_64 5.4.16-23.el7_0.3 updates 95 k
php-process x86_64 5.4.16-23.el7_0.3 updates 52 k
php-xml x86_64 5.4.16-23.el7_0.3 updates 122 k
t1lib x86_64 5.1.2-14.el7 base 166 k
Transaction Summary
==============================================================================================
Install 4 Packages (+7 Dependent packages)
Total download size: 5.7 M
Installed size: 21 M
Is this ok [y/d/N]: y
ownloading packages:
(1/11): libzip-0.10.1-8.el7.x86_64.rpm | 48 kB 00:00:01
(2/11): php-gd-5.4.16-23.el7_0.3.x86_64.rpm | 124 kB 00:00:01
(3/11): php-5.4.16-23.el7_0.3.x86_64.rpm | 1.3 MB 00:00:01
(4/11): php-mysql-5.4.16-23.el7_0.3.x86_64.rpm | 97 kB 00:00:00
(5/11): php-pdo-5.4.16-23.el7_0.3.x86_64.rpm | 95 kB 00:00:00
(6/11): php-cli-5.4.16-23.el7_0.3.x86_64.rpm | 2.7 MB 00:00:02
(7/11): t1lib-5.1.2-14.el7.x86_64.rpm | 166 kB 00:00:00
(8/11): php-process-5.4.16-23.el7_0.3.x86_64.rpm | 52 kB 00:00:00
(9/11): php-xml-5.4.16-23.el7_0.3.x86_64.rpm | 122 kB 00:00:01
(10/11): php-pear-1.9.4-21.el7.noarch.rpm | 357 kB 00:00:01
(11/11): php-common-5.4.16-23.el7_0.3.x86_64.rpm | 561 kB 00:00:06
———————————————————————————————-
Total 920 kB/s | 5.7 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libzip-0.10.1-8.el7.x86_64 1/11
Installing : php-common-5.4.16-23.el7_0.3.x86_64 2/11
Installing : php-cli-5.4.16-23.el7_0.3.x86_64 3/11
Installing : php-pdo-5.4.16-23.el7_0.3.x86_64 4/11
Installing : php-process-5.4.16-23.el7_0.3.x86_64 5/11
Installing : php-xml-5.4.16-23.el7_0.3.x86_64 6/11
Installing : t1lib-5.1.2-14.el7.x86_64 7/11
Installing : php-gd-5.4.16-23.el7_0.3.x86_64 8/11
Installing : 1:php-pear-1.9.4-21.el7.noarch 9/11
Installing : php-mysql-5.4.16-23.el7_0.3.x86_64 10/11
Installing : php-5.4.16-23.el7_0.3.x86_64 11/11
Verifying : php-common-5.4.16-23.el7_0.3.x86_64 1/11
Verifying : php-pdo-5.4.16-23.el7_0.3.x86_64 2/11
Verifying : t1lib-5.1.2-14.el7.x86_64 3/11
Verifying : php-process-5.4.16-23.el7_0.3.x86_64 4/11
Verifying : php-5.4.16-23.el7_0.3.x86_64 5/11
Verifying : php-gd-5.4.16-23.el7_0.3.x86_64 6/11
Verifying : php-xml-5.4.16-23.el7_0.3.x86_64 7/11
Verifying : php-mysql-5.4.16-23.el7_0.3.x86_64 8/11
Verifying : php-cli-5.4.16-23.el7_0.3.x86_64 9/11
Verifying : libzip-0.10.1-8.el7.x86_64 10/11
Verifying : 1:php-pear-1.9.4-21.el7.noarch 11/11
Installed:
php.x86_64 0:5.4.16-23.el7_0.3 php-gd.x86_64 0:5.4.16-23.el7_0.3
php-mysql.x86_64 0:5.4.16-23.el7_0.3 php-pear.noarch 1:1.9.4-21.el7
Dependency Installed:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-23.el7_0.3
php-common.x86_64 0:5.4.16-23.el7_0.3 php-pdo.x86_64 0:5.4.16-23.el7_0.3
php-process.x86_64 0:5.4.16-23.el7_0.3 php-xml.x86_64 0:5.4.16-23.el7_0.3
t1lib.x86_64 0:5.1.2-14.el7
Complete!
[/cc]
测试安装后的php服务器
在/var/www/html/下创一个test.php 文件,并加入下面的内容:
[cc lang=”php”]

[/cc]
保存退出后,在浏览器上输入:http://127.0.0.1/test.php,后出现下面的界面。
centos 7 php
到此在centos 7 系统上配置LAMP的工具已完成。

Leave a Reply