mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-25 00:50:15 +08:00
PUB:20150616 Installing LAMP Linux, Apache, MariaDB, PHP or PhpMyAdmin in RHEL or CentOS 7.0
@geekpi
This commit is contained in:
parent
0c6f6ef301
commit
b3c0a231df
@ -0,0 +1,240 @@
|
||||
在 RHEL/CentOS 7.0 中安装 LAMP(Linux、 Apache、 MariaDB、 PHP/PhpMyAdmin)
|
||||
================================================================================
|
||||
|
||||
跳过 LAMP 的介绍,因为我认为你们大多数已经知道了。这个教程会集中在如何在升级到 Apache 2.4 的 Red Hat Enterprise Linux 7.0 和 CentOS 7.0 中安装和配置 LAMP:Linux、Apache、 MariaDB、 PHP/PhpMyAdmin。
|
||||
|
||||

|
||||
|
||||
*在 RHEL/CentOS 7.0 中安装 LAMP*
|
||||
|
||||
#### 前置要求 ####
|
||||
|
||||
根据使用的发行版是 RHEL 还是 CentOS 7.0,按照下面的链接来进行最小化的系统安装,网络使用静态 IP。
|
||||
|
||||
**对于 RHEL 7.0**
|
||||
|
||||
- [RHEL 7.0 安装过程][1]
|
||||
- [在 RHEL 7.0 中注册和启用订阅仓库][2]
|
||||
|
||||
**对于 CentOS 7.0**
|
||||
|
||||
- [CentOS 7.0 安装过程][3]
|
||||
|
||||
### 第一步:使用基本配置安装apache ###
|
||||
|
||||
1、在完成最小化系统安装,并[在 RHEL/CentOS 7.0 上配置静态 IP][4] 后,就可以使用下面的命令从官方仓库安装最新的 Apache 2.4 httpd 服务了。
|
||||
|
||||
# yum install httpd
|
||||
|
||||

|
||||
|
||||
*安装 apache 服务*
|
||||
|
||||
2、安装完成后,使用下面的命令来管理apache守护进程,因为 RHEL 和 CentOS 7.0 都将 init 脚本从 SysV 升级到了systemd,所以同时你还可以使用 SysV 脚本和 Apache 脚本来管理服务。
|
||||
|
||||
# systemctl status|start|stop|restart|reload httpd
|
||||
|
||||
或者
|
||||
|
||||
# service httpd status|start|stop|restart|reload
|
||||
|
||||
或者
|
||||
|
||||
# apachectl configtest| graceful
|
||||
|
||||

|
||||
|
||||
*启动apache服务*
|
||||
|
||||
3、在使用 systemd 初始化脚本来启动 apache 服务后,要用 `firewall-cmd` 打开 RHEL/CentOS 7.0 防火墙规则, 这是通过 [firewalld][7] 守护进程管理 iptables 的默认命令。**
|
||||
|
||||
# firewall-cmd --add-service=http
|
||||
|
||||
**注意**:上面的命令会在系统重启或者 firewalld 服务重启后失效,因为它是即时的规则,它不会永久生效。要使 iptables 规则在 fiewalld 中持久化,使用 `--permanent` 选项并重启 firewalld 服务来生效。(LCTT 译注:也可以不重启 firewalld 服务,而是再执行一遍不带 ` --permanent` 选项的命令。)
|
||||
|
||||
# firewall-cmd --permanent --add-service=http
|
||||
# systemctl restart firewalld
|
||||
|
||||

|
||||
|
||||
*在 CentOS 7 中启用防火墙*
|
||||
|
||||
下面是 firewalld 其他的重要选项:
|
||||
|
||||
# firewall-cmd --state
|
||||
# firewall-cmd --list-all
|
||||
# firewall-cmd --list-interfaces
|
||||
# firewall-cmd --get-service
|
||||
# firewall-cmd --query-service service_name
|
||||
# firewall-cmd --add-port=8080/tcp
|
||||
|
||||
4、要验证 apache 的功能,打开一个远程浏览器并使用 http 协议访问你服务器的 IP 地址(http://server_IP), 应该会显示下图中的默认页面。
|
||||
|
||||

|
||||
|
||||
*Apache 默认页*
|
||||
|
||||
5、现在 apache 的根地址在 `/var/www/html`,该目录中没有提供任何索引文件。如果你想要看见根目录下的文件夹列表,打开 apache 欢迎配置文件并设置 `<LocationMach>` 下 `Indexes` 前的状态从`-`到`+`,下面的截图就是一个例子。
|
||||
|
||||
# nano /etc/httpd/conf.d/welcome.conf
|
||||
|
||||

|
||||
|
||||
*Apache 目录列出*
|
||||
|
||||
6、关闭文件,重启 apache 服务来使设置生效,重载页面来看最终效果。
|
||||
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
*Apache 索引文件*
|
||||
|
||||
### 第二步:为 Apache 安装 php5 支持 ###
|
||||
|
||||
7、在为 apache 安装 php 支持之前,使用下面的命令的得到所有可用的php模块和扩展。
|
||||
|
||||
# yum search php
|
||||
|
||||

|
||||
|
||||
在 CentOS 7 上安装 PHP*
|
||||
|
||||
8、根据你所要使用的应用类型,安装上述列表中所需的 PHP 模块。对于 PHP 中的基本的 MariaDB 支持和 PhpMyAdmin,你需要安装如下模块。
|
||||
|
||||
# yum install php php-mysql php-pdo php-gd php-mbstring
|
||||
|
||||

|
||||
|
||||
*安装 PHP 模块*
|
||||
|
||||

|
||||
|
||||
*安装 PHP mbstring 模块*
|
||||
|
||||
9、 要在你的浏览器上显示 PHP 的全部信息,用 root 账号执行如下命令在 Apache 的文档根目录下创建一个 `info.php` 文件,然后重启 httpd 服务,并在你的浏览器里面访问 http://server_IP/info.php 。
|
||||
|
||||
# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
*查看 CentOS 7 上的 PHP 信息*
|
||||
|
||||
10、如果你得到一个 PHP 的日期和时区错误,打开配置文件 `php.ini`,取消 `date.timezone` 语句的注释,加上你的实际时区参数,然后重启 Apache 守护进程。
|
||||
|
||||
# nano /etc/php.ini
|
||||
|
||||
找到并如下修改`date.timezone`,参考 [PHP 支持的时区列表][5]。(LCTT 译注:对于中国,可以使用 Asia/Shanghai、Asia/Chongqing 等,但是不建议使用向后兼容而保留的 PRC。)
|
||||
|
||||
date.timezone = Continent/City
|
||||
|
||||

|
||||
|
||||
*设置 PHP 的时区*
|
||||
|
||||
###第三步:安装和配置 MariaDB 数据库 ###
|
||||
|
||||
11、 Red Hat Enterprise Linux/CentOS 7.0 使用 MariaDB 替换 MySQL 为默认数据库管理系统。使用如下命令安装 MariaDB 数据库。
|
||||
|
||||
# yum install mariadb-server mariadb
|
||||
|
||||

|
||||
|
||||
*在 CentOS 7中安装 MariaDB*
|
||||
|
||||
12、安装 MariaDB 后,启动数据库守护进程并使用 mysql_secure_installation 脚本来保护数据库(设置数据库的 root 密码、禁止远程 root 登录、移除测试数据库、移除匿名用户等)。
|
||||
|
||||
# systemctl start mariadb
|
||||
# mysql_secure_installation
|
||||
|
||||

|
||||
|
||||
*启动 MariaDB 数据库*
|
||||
|
||||

|
||||
|
||||
*MariaDB 安全设置*
|
||||
|
||||
13、要测试数据库功能,使用 root 账户登录 MariaDB 并用 quit 退出。
|
||||
|
||||
mysql -u root -p
|
||||
MariaDB > SHOW VARIABLES;
|
||||
MariaDB > quit
|
||||
|
||||

|
||||
|
||||
*连接 MariaDB 数据库*
|
||||
|
||||
### 第四步:安装 PhpMyAdmin ###
|
||||
|
||||
14、 RHEL 7.0 或者 CentOS 7.0 仓库默认没有提供 PhpMyAdmin 二进制安装包。如果你不适应使用 MySQL 命令行来管理你的数据库,你可以通过下面的命令启用 CentOS 7.0 rpmforge 仓库来安装 PhpMyAdmin。
|
||||
|
||||
# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
|
||||
|
||||
启用 rpmforge 仓库后,下面安装 PhpMyAdmin。
|
||||
|
||||
# yum install phpmyadmin
|
||||
|
||||

|
||||
|
||||
*启用 RPMForge 仓库*
|
||||
|
||||
15、下面配置 PhpMyAdmin 的 `phpmyadmin.conf` 来允许远程连接,它位于 Apache 的 `conf.d` 目录下,并注释掉下面的行。
|
||||
|
||||
# nano /etc/httpd/conf.d/phpmyadmin.conf
|
||||
|
||||
使用#来注释掉下列行。
|
||||
|
||||
# Order Deny,Allow
|
||||
# Deny from all
|
||||
# Allow from 127.0.0.1
|
||||
|
||||

|
||||
|
||||
*允许远程 PhpMyAdmin 访问*
|
||||
|
||||
16、 要使用 cookie 验证来登录 PhpMyAdmin,像下面的截图那样使用[生成的秘密字符串][6]来添加一个 blowfish 字符串到 `config.inc.php` 文件中,重启 apache 服务并打开 URL:http://server_IP/phpmyadmin/。
|
||||
|
||||
# nano /etc/httpd/conf.d/phpmyadmin.conf
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
*在 PhpMyAdmin 中添加 Blowfish*
|
||||
|
||||

|
||||
|
||||
*PhpMyAdmin 面板*
|
||||
|
||||
### 第五步:在系统范围内启用 LAMP ###
|
||||
|
||||
17、 如果你需要在重启后自动运行 MariaDB 和 Apache 服务,你需要在系统级地启用它们。
|
||||
|
||||
# systemctl enable mariadb
|
||||
# systemctl enable httpd
|
||||
|
||||

|
||||
|
||||
*系统级启用服务*
|
||||
|
||||
这就是在 Red Hat Enterprise 7.0 或者 CentOS 7.0 中安装 LAMP 的过程。在 CentOS/RHEL 7.0 上关于 LAMP 的系列文章接下来将会讨论在 Apache 中创建虚拟主机,生成 SSL 证书、密钥和添加 SSL 事务支持。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/install-lamp-in-centos-7/
|
||||
|
||||
作者:[Matei Cezar][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/cezarmatei/
|
||||
[1]:http://www.tecmint.com/redhat-enterprise-linux-7-installation/
|
||||
[2]:http://www.tecmint.com/enable-redhat-subscription-reposiories-and-updates-for-rhel-7/
|
||||
[3]:http://www.tecmint.com/centos-7-installation/
|
||||
[4]:https://linux.cn/article-3977-1.html
|
||||
[5]:http://php.net/manual/en/timezones.php
|
||||
[6]:http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator
|
||||
[7]:https://linux.cn/article-4425-1.html
|
@ -1,239 +0,0 @@
|
||||
在RHEL/CentOS 7.0中安装LAMP(Linux、 Apache、 MariaDB、 PHP/PhpMyAdmin)
|
||||
================================================================================
|
||||
跳过LAMP的介绍因为我认为你们大多数已经知道了。这个教程会集中在如何在升级到Apache 2.4的 Red Hat Enterprise Linux 7.0 和 CentOS 7.0中安装和配置LAMP-Linux Apache、 MariaDB、 PHP、PhpMyAdmin。
|
||||
|
||||

|
||||
|
||||
在RHEL/CentOS 7.0中安装LAMP
|
||||
|
||||
#### 要求 ####
|
||||
|
||||
根据使用的发行版,RHEL 或者 CentOS 7.0使用下面的链接来执行最小的系统安装,网络使用静态ip
|
||||
|
||||
**对于RHEL 7.0**
|
||||
|
||||
- [RHEL 7.0安装过程][1]
|
||||
- [在RHEL 7.0中注册和启用订阅仓库][2]
|
||||
|
||||
**对于 CentOS 7.0**
|
||||
|
||||
- [CentOS 7.0 安装过程][3]
|
||||
|
||||
### 第一步: 使用基本配置安装apache ###
|
||||
|
||||
**1. 在执行最小系统安装并配置[在RHEL/CentOS 7.0中配置静态ip][4]**就可以从使用下面的命令从官方仓库安装最新的Apache 2.4 httpd服务。
|
||||
|
||||
# yum install httpd
|
||||
|
||||

|
||||
|
||||
安装apache服务
|
||||
|
||||
**2. 安装安城后,使用下面的命令来管理apache守护进程,因为RHEL and CentOS 7.0都将init脚本从SysV升级到了systemd - 你也可以同事使用SysV和Apache脚本来管理服务。**
|
||||
|
||||
# systemctl status|start|stop|restart|reload httpd
|
||||
|
||||
或者
|
||||
|
||||
# service httpd status|start|stop|restart|reload
|
||||
|
||||
或者
|
||||
|
||||
# apachectl configtest| graceful
|
||||
|
||||

|
||||
|
||||
启动apache服务
|
||||
|
||||
**3. 下一步使用systemd初始化脚本来启动apache服务并用firewall-cmd打开RHEL/CentOS 7.0防火墙规则, 这是通过firewalld守护进程管理iptables的默认命令。**
|
||||
|
||||
# firewall-cmd --add-service=http
|
||||
|
||||
**注意**:上面的命令会在系统重启或者firewalld服务重启后失效,因为它是即时的规则,它不会永久生效。要使iptables规则在fiewwall中持久化,使用-permanent选项并重启firewalld服务来生效。
|
||||
|
||||
# firewall-cmd --permanent --add-service=http
|
||||
# systemctl restart firewalld
|
||||
|
||||

|
||||
|
||||
在CentOS 7中启用Firewall
|
||||
|
||||
下面是firewalld其他的重要选项:
|
||||
|
||||
# firewall-cmd --state
|
||||
# firewall-cmd --list-all
|
||||
# firewall-cmd --list-interfaces
|
||||
# firewall-cmd --get-service
|
||||
# firewall-cmd --query-service service_name
|
||||
# firewall-cmd --add-port=8080/tcp
|
||||
|
||||
**4. 要验证apache的功能,打开一个远程浏览器并使用http协议输入你服务器的ip地址(http://server_IP), 应该会显示下图中的默认页面。**
|
||||
|
||||

|
||||
|
||||
Apache默认页
|
||||
|
||||
**5. 现在apache的根地址在/var/www/html,该目录中没有提供任何index文件。如果你想要看见根目录下的文件夹列表,打开apache欢迎配置文件并设置 <LocationMach>下Indexes前的状态从-到+,下面的截图就是一个例子。**
|
||||
|
||||
# nano /etc/httpd/conf.d/welcome.conf
|
||||
|
||||

|
||||
|
||||
Apache目录列出
|
||||
|
||||
**6. 关闭文件,重启apache服务来使设置生效,重载页面来看最终效果。**
|
||||
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
Apache Index 文件
|
||||
|
||||
### 第二步: 为Apache安装php5支持 ###
|
||||
|
||||
|
||||
**7. 在为apache安装php支持之前,使用下面的命令的得到所有可用的php模块和扩展。**
|
||||
|
||||
# yum search php
|
||||
|
||||

|
||||
|
||||
在
|
||||
|
||||
**8. Depending on what type of applications you want to use, install the required PHP modules from the above list, but for a basic MariaDB support in PHP and PhpMyAdmin you need to install the following modules.**
|
||||
|
||||
# yum install php php-mysql php-pdo php-gd php-mbstring
|
||||
|
||||

|
||||
|
||||
Install PHP Modules
|
||||
|
||||

|
||||
|
||||
Install PHP mbstring Module
|
||||
|
||||
**9. To get a full information list on PHP from your browser, create a info.php file on Apache Document Root using the following command from root account, restart httpd service and direct your browser to the http://server_IP/info.php address.**
|
||||
|
||||
# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
Check PHP Info in CentOS 7
|
||||
|
||||
**10. If you get an error on PHP Date and Timezone, open php.ini configuration file, search and uncomment date.timezone statement, append your physical location and restart Apache daemon.**
|
||||
|
||||
# nano /etc/php.ini
|
||||
|
||||
Locate and change date.timezone line to look like this, using [PHP Supported Timezones list][5].
|
||||
|
||||
date.timezone = Continent/City
|
||||
|
||||

|
||||
|
||||
Set Timezone in PHP
|
||||
|
||||
### Step 3: Install and Configure MariaDB Database ###
|
||||
|
||||
**11. Red Hat Enterprise Linux/CentOS 7.0 switched from MySQL to MariaDB for its default database management system. To install MariaDB database use the following command.**
|
||||
|
||||
# yum install mariadb-server mariadb
|
||||
|
||||

|
||||
|
||||
在CentOS 7中安装PHP
|
||||
|
||||
***12. 安装MariaDB后,开启数据库守护进程并使用mysql_secure_installation脚本来保护数据库(设置root密码、禁止远程root登录、移除测试数据库、移除匿名用户)**
|
||||
|
||||
# systemctl start mariadb
|
||||
# mysql_secure_installation
|
||||
|
||||

|
||||
|
||||
启动MariaDB数据库
|
||||
|
||||

|
||||
|
||||
MySQL安全设置
|
||||
|
||||
**13. 要测试数据库功能,使用root账户登录MariaDB并用quit退出。**
|
||||
|
||||
mysql -u root -p
|
||||
MariaDB > SHOW VARIABLES;
|
||||
MariaDB > quit
|
||||
|
||||

|
||||
|
||||
连接MySQL数据库
|
||||
|
||||
### 第四步: 安装PhpMyAdmin ###
|
||||
|
||||
**14. RHEL 7.0 或者 CentOS 7.0仓库默认没有提供PhpMyAdmin二进制安装包。如果你不适应使用MySQL命令行来管理你的数据库,你可以通过下面的命令启用CentOS 7.0 rpmforge仓库来安装PhpMyAdmin。**
|
||||
|
||||
# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
|
||||
|
||||
启用rpmforge仓库后,下面安装PhpMyAdmin。
|
||||
|
||||
# yum install phpmyadmin
|
||||
|
||||

|
||||
|
||||
启用RPMForge仓库
|
||||
|
||||
**15. 下面配置PhpMyAdmin的phpmyadmin.conf来允许远程连接,它位于Apache conf.d目录下,并注释掉下面的行。**
|
||||
|
||||
# nano /etc/httpd/conf.d/phpmyadmin.conf
|
||||
|
||||
使用#来注释掉行。
|
||||
|
||||
# Order Deny,Allow
|
||||
# Deny from all
|
||||
# Allow from 127.0.0.1
|
||||
|
||||

|
||||
|
||||
允许远程PhpMyAdmin访问
|
||||
|
||||
**16. 要使用cookie验证来登录PhpMyAdmin,像下面的截图那样使用[生成字符串][6]添加一个blowfish字符串到config.inc.php文件下,重启apache服务并打开URL:http://server_IP/phpmyadmin/。**
|
||||
|
||||
# nano /etc/httpd/conf.d/phpmyadmin.conf
|
||||
# systemctl restart httpd
|
||||
|
||||

|
||||
|
||||
在PhpMyAdmin中添加Blowfish
|
||||
|
||||

|
||||
|
||||
PhpMyAdmin面板
|
||||
|
||||
### 第五步: 系统范围启用LAMP ###
|
||||
|
||||
**17. 如果你需要在重启后自动运行MariaDB和Apache服务,你需要系统级地启用它们。**
|
||||
|
||||
# systemctl enable mariadb
|
||||
# systemctl enable httpd
|
||||
|
||||

|
||||
|
||||
系统级启用服务
|
||||
|
||||
这就是在Red Hat Enterprise 7.0或者CentOS 7.0中安装LAMP的过程。CentOS/RHEL 7.0上关于LAMP洗系列文章将会讨论在Apache中创建虚拟主机,生成SSL证书、密钥和添加SSL事物支持。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/install-lamp-in-centos-7/
|
||||
|
||||
作者:[Matei Cezar][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/cezarmatei/
|
||||
[1]:http://www.tecmint.com/redhat-enterprise-linux-7-installation/
|
||||
[2]:http://www.tecmint.com/enable-redhat-subscription-reposiories-and-updates-for-rhel-7/
|
||||
[3]:http://www.tecmint.com/centos-7-installation/
|
||||
[4]:http://www.tecmint.com/configure-network-interface-in-rhel-centos-7-0/
|
||||
[5]:http://php.net/manual/en/timezones.php
|
||||
[6]:http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator
|
Loading…
Reference in New Issue
Block a user