RHELCentOSApacheLAMPMariaDB
我
是新的 Red Hat Enterprise Linux 版本 7 用户/系统管理员/开发人员。此版本对 RHEL 7/CentOS 7 进行了重大更改。如何使用 CLI 或基于 ssh 的会话在 RHEL 版本 7 或 CentOS Linux 版本 7 上安装 LAMP(Linux、Apache、MariaDB、PHP)堆栈?Tutorial details | |
---|---|
Difficulty | Easy(rss) |
Root privileges | Yes |
Requirements | CentOS/RHEL v7.x |
Estimated completion time | 20m |
RHEL 7 已经发布,CentOS Linux 7 即将推出,其中有许多显着的变化。本指南介绍如何安装 LAMP 服务器。
有关 LAMP 的更多信息
LAMP 只是一个软件包或一个由 Linux 操作系统、Apache Web 服务器、MySQL 数据库服务器和 PHP 组成的平台(或 Perl/Python)脚本语言。 LAMP 堆栈用于完全使用免费开源软件构建重型动态网站。在本教程中,我将解释如何在 CentOS 7 或 RHEL 7 上使用 Linux、Apache、MySQL/MariaDB(替代 MySQL)、PHP (LAMP) 堆栈。
假设
- 我假设您已经安装了基本的 RHEL 7 或 CentOS 7 服务器。打开终端应用程序并以 root 用户身份键入以下命令。
- 您必须熟悉他们的命令
- 您必须知道服务器的 IP 地址。使用以下命令查找 eth0 接口的服务器 IP 地址:
ifconfig eth0
或
ip a show eth0
或
ip 地址列表 eth0 | awk '/inet /{sub(///[0-9] /,"",$2);打印 $2}'
或
ifconfig eth0 | awk '/inet /{print $2}'
10.41.143.156 - 我将使用 IP 地址 10.41.143.156 用于测试目的。请随意将此 IP 地址替换为您的实际私有或公共 IP 地址。
说得够多了,让我们设置 LAMP 堆栈。
第 1 步:在 CentOS 7 / RHEL 7 服务器上安装 Apache
输入以下 yum 命令来安装 Apache web-server:
sudo yum install httpd
示例输出:
Loaded plugins: amazon-id, rhui-lbResolving Dependencies--> Running transaction check---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64--> Running transaction check---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed--> Finished Dependency Resolution Dependencies Resolved ====================================================================================================== PackageArchVersion Repository Size======================================================================================================Installing: httpdx86_642.4.6-17.el7rhui-REGION-rhel-server-releases1.2 MInstalling for dependencies: httpd-toolsx86_642.4.6-17.el7rhui-REGION-rhel-server-releases 77 k mailcapnoarch2.1.41-2.el7rhui-REGION-rhel-server-releases 31 k Transaction Summary======================================================================================================Install1 Package (+2 Dependent packages) Total download size: 1.3 MInstalled size: 3.9 MIs this ok [y/d/N]: yDownloading packages:(1/3): httpd-tools-2.4.6-17.el7.x86_64.rpm |77 kB00:00:00(2/3): httpd-2.4.6-17.el7.x86_64.rpm | 1.2 MB00:00:00(3/3): mailcap-2.1.41-2.el7.noarch.rpm |31 kB00:00:00------------------------------------------------------------------------------------------------------Total 2.0 MB/s | 1.3 MB00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : httpd-tools-2.4.6-17.el7.x86_641/3Installing : mailcap-2.1.41-2.el7.noarch2/3Installing : httpd-2.4.6-17.el7.x86_643/3Verifying: mailcap-2.1.41-2.el7.noarch1/3Verifying: httpd-tools-2.4.6-17.el7.x86_642/3Verifying: httpd-2.4.6-17.el7.x86_643/3 Installed:httpd.x86_64 0:2.4.6-17.el7 Dependency Installed:httpd-tools.x86_64 0:2.4.6-17.el7 mailcap.noarch 0:2.1.41-2.el7 Complete!
在启动时启用 httpd 服务
确保 httpd 服务在启动时自动启动,输入:
sudo systemctl enable httpd.service
示例输出:
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
以下命令将在启动时禁用 httpd 服务:
sudo systemctl disable httpd.service
示例输出:
rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
在 CentOS/RHEL v7.x 上启动 httpd 服务
sudo systemctl start httpd.service
在此阶段,您可以将 Web 浏览器指向服务器的 IP 地址,例如 http:// /10.41.143.156)。屏幕上应显示以下页面:

图 01:检查 Apache 是否在 CentOS/RHEL 7 服务器上运行
在 CentOS/RHEL v7.x 上停止 httpd 服务
sudo systemctl stop httpd.service
在 CentOS/RHEL v7.x 上重启 httpd 服务
sudo systemctl restart httpd.service
在 CentOS/RHEL v7.x 上查找 httpd 服务状态
到验证 httpd 服务是否正在运行,输入:
systemctl is-active httpd.service
示例输出:
active
在 CentOS/RHEL v7.x 上正常重启 httpd 服务
sudo apachectl graceful
在 CentOS/RHEL v7.x 上测试 httpd/Apache 配置文件是否有错误
sudo apachectl configtest
示例输出:
Syntax OK
httpd 服务默认配置
- 默认配置文件:/etc/httpd/conf/httpd.conf
- 加载模块的配置文件:/etc/httpd/conf.modules.d/ 目录(例如 PHP)
- 选择 MPM(处理模型)作为可加载模块 [worker、prefork(默认)] 和事件:/etc/httpd/conf.modules.d/00-mpm .conf
- 默认端口:80 和 443 (SSL)
- 默认日志文件:/var/log/httpd/{access_log,error_log}
步骤 #2:在 CentOS 7 / RHEL 7 服务器上安装 MariaDB
MariaDB MySQL 服务器的增强型直接替代品。 RHEL/CentOS v7.x 从 MySQL 转向 MariaDB 以满足其数据库管理系统需求。键入以下 yum 命令来安装 MariaDB 服务器:
sudo yum install mariadb-server mariadb
要启动 mariadb,请键入:
sudo systemctl start mariadb.service
要确保 mariadb 服务在启动时自动启动,请输入:
sudo systemctl enable mariadb.service
示例输出:
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
要停止/重新启动和禁用 mariadb 服务,请使用以下命令:
sudo systemctl stop mariadb.service #<h3 id="保护-MariaDB">保护 MariaDB</h3> <p>键入以下命令:</p> <code>sudo /usr/bin/mysql_secure_installation</code> <p>示例输出:</p><pre class="brush:php;toolbar:false">NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE!PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user.If you've just installed MariaDB, andyou 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): <strong>PRESS-ENTER-KEY</strong>OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] YNew password: <strong>YOUR-NEW-PASSWORD-HERE</strong>Re-enter new password: <strong>YOUR-NEW-PASSWORD-HERE</strong>Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.This is intended only for testing, and to make the installationgo a bit smoother.You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] <strong>Y</strong> ... Success!Normally, root should only be allowed to connect from 'localhost'.Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] <strong>Y</strong> ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess.This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] <strong>Y</strong> - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] <strong>Y</strong> ... Success!Cleaning up...All done!If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!
测试 MariaDB 安装
键入以下命令
mysql -u root -p
示例输出:

图 02:CentOS / RHEL Linux v7.x 上的 Mariadb 测试连接
步骤 #3:在 CentOS/RHEL v7.x 上安装 PHP
要安装 PHP 和 gd/msyql 等模块,请输入以下 yum 命令:
sudo yum install php php-mysql php-gd php-pear
You must restart the httpd (Apache) service, enter:
sudo systemctl restart httpd.service
To search all other php modules, type:
sudo yum search php-
Sample outputs:
php-cli.x86_64 : Command-line interface for PHPphp-common.x86_64 : Common files for PHPphp-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp-ldap.x86_64 : A module for PHP applications that use LDAPphp-mysql.x86_64 : A module for PHP applications that use MySQL databasesphp-odbc.x86_64 : A module for PHP applications that use ODBC databasesphp-pdo.x86_64 : A database access abstraction module for PHP applicationsphp-pear.noarch : PHP Extension and Application Repository frameworkphp-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemonphp-pgsql.x86_64 : A PostgreSQL database module for PHPphp-process.x86_64 : Modules for PHP script using system process interfacesphp-recode.x86_64 : A module for PHP applications for using the recode libraryphp-soap.x86_64 : A module for PHP applications that use the SOAP protocolphp-xml.x86_64 : A module for PHP applications which use XMLphp-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
To find more info about a module type:
sudo yum info php-pgsql
To install php module called php-pgsql type:
sudo yum install php-pgsql
Test PHP on your server
Create a file called /var/www/html/test.php as follows:
sudo vi /var/www/html/test.php
Append the following code:
<?php phpinfo(INFO_GENERAL);?>
Save and close the file. Point your web-browser to your server's IP address such as http://10.41.143.156/info.php (feel free to replace the 10.41.143.156 with your actual IP address):
http://10.41.143.156/info.php

MySQL在Web应用中的主要作用是存储和管理数据。1.MySQL高效处理用户信息、产品目录和交易记录等数据。2.通过SQL查询,开发者能从数据库提取信息生成动态内容。3.MySQL基于客户端-服务器模型工作,确保查询速度可接受。

构建MySQL数据库的步骤包括:1.创建数据库和表,2.插入数据,3.进行查询。首先,使用CREATEDATABASE和CREATETABLE语句创建数据库和表,然后用INSERTINTO语句插入数据,最后用SELECT语句查询数据。

MySQL适合初学者,因为它易用且功能强大。1.MySQL是关系型数据库,使用SQL进行CRUD操作。2.安装简单,需配置root用户密码。3.使用INSERT、UPDATE、DELETE、SELECT进行数据操作。4.复杂查询可使用ORDERBY、WHERE和JOIN。5.调试需检查语法,使用EXPLAIN分析查询。6.优化建议包括使用索引、选择合适数据类型和良好编程习惯。

MySQL适合初学者,因为:1)易于安装和配置,2)有丰富的学习资源,3)SQL语法直观,4)工具支持强大。尽管如此,初学者需克服数据库设计、查询优化、安全管理和数据备份等挑战。

是的,sqlisaprogramminglanguges pecialized fordatamanage.1)它具有焦点,focusingonwhattoachieveratherthanhow.2)sqlisessential forquerying forquerying,插入,更新,更新,和detletingdatainrelationalDatabases.3)

ACID属性包括原子性、一致性、隔离性和持久性,是数据库设计的基石。1.原子性确保事务要么完全成功,要么完全失败。2.一致性保证数据库在事务前后保持一致状态。3.隔离性确保事务之间互不干扰。4.持久性确保事务提交后数据永久保存。

MySQL既是数据库管理系统(DBMS),也与编程语言紧密相关。1)作为DBMS,MySQL用于存储、组织和检索数据,优化索引可提高查询性能。2)通过SQL与编程语言结合,嵌入在如Python中,使用ORM工具如SQLAlchemy可简化操作。3)性能优化包括索引、查询、缓存、分库分表和事务管理。

MySQL使用SQL命令管理数据。1.基本命令包括SELECT、INSERT、UPDATE和DELETE。2.高级用法涉及JOIN、子查询和聚合函数。3.常见错误有语法、逻辑和性能问题。4.优化技巧包括使用索引、避免SELECT*和使用LIMIT。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Linux新版
SublimeText3 Linux最新版

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器