在CentOS/RHEL/Scientific Linux 6下安装 LAMP
创始人
2024-03-01 11:06:08
0

LAMP 是服务器系统中开源软件的一个完美组合。它是 Linux 、Apache HTTP 服务器、MySQL 数据库、PHP(或者 Perl、Python)的第一个字母的缩写代码。对于很多系统管理员来说安装 LAMP 除了是必备的技能外,都已经具有驾轻就熟的操作他们的能力了。不过新手们通常希望有没完没了的这方面的教程来告诉自己怎么做,下面我就和大家说说我的方法步骤。

LAMP 是服务器系统中开源软件的一个完美组合。它是 Linux 、Apache HTTP 服务器、MySQL 数据库、PHP(或者 Perl、Python)的第一个字母的缩写代码。对于很多系统管理员来说安装 LAMP 除了是必备的技能外,都已经具有驾轻就熟的操作他们的能力了。不过新手们通常希望有没完没了的这方面的教程来告诉自己怎么做,下面我就和大家说说我的方法步骤。

现在,很多时候我们需要用 MariaDB 来代替 MySQL 了。在这里我会告诉大家 MariaDB 的安装过程。

我的测试主机名为:server.linux.cn,测试 IP 地址为:192.168.1.200/24

安装 Apache

Apache 是​​一个开源的跨平台的 Web 服务器。它提供了一个全方位的 Web 服务器功能,包括CGI,SSL 和virtual domains (虚拟域)。

安装命令非常简单,只需要打开一个终端,在终端中输入如下命令:

[root@server ~]# yum install httpd -y

安装完毕后,需要设置让 Apache 服务启动,并且在每次服务器重启的时候都自动启动,输入如下命令来完成:

[root@server ~]# /etc/init.d/httpd start
[root@server ~]# chkconfig httpd on

如果您想通过您的防火墙活路由器来远程连接,那么需要允许 Apache 服务接管服务器的 80 端口:

[root@server ~]# vi /etc/sysconfig/iptables
[…]
-A INPUT -p udp -m state –state NEW –dport 80 -j ACCEPT
-A INPUT -p tcp -m state –state NEW –dport 80 -j ACCEPT
[…]

重新启动 iptables :

[root@server ~]# /etc/init.d/iptables restart

打开您的浏览器访问 http://localhost/ 或者 http://server-ip-address/ 测试 Apache 安装是否成功。


点击查看原始大图

安装 MariaDB

MariaDB 是一个替换 MySQL 的产品。功能强大而可靠。安装前,如果您的服务器中安装有 MySQL ,那么您需要删除它。删除命令:

[root@server ~]# yum remove mysql* mysql-server mysql-devel mysql-libs

为了让 MariaDB 同时兼容 MySQL,我们需要安装 REMI 库来解决兼容性和安装 MariaDB 时软件包依赖性问题。安装命令:

[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

安装兼容 mysql55 包命令:

[root@server ~]# yum –enablerepo=remi-test –disablerepo=remi install compat-mysql55

为 MariaDB 创建一个 repository 文件,并在其中输入如下代码:

32 位系统:

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo

MariaDB 5.5 CentOS repository list - created 2013-06-06 07:42 UTC

http://mariadb.org/mariadb/repositories/

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

64 位系统:

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo

MariaDB 5.5 CentOS repository list - created 2013-06-06 07:53 UTC

http://mariadb.org/mariadb/repositories/

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

保存并退出该文件,并运行 yum update 命令:

[root@server ~]# yum update

现在开始安装 MariaDB :

[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y

安装完毕后,启动 MariaDB 服务,并让它在每次重启服务器后自动启动。

[root@server ~]# /etc/init.d/mysql start
Starting MySQL… SUCCESS!
[root@server ~]# chkconfig mysql on

为 MySQL 的 root 设置密码,默认情况下,MySWL root 密码是空的。为了防止未经授权的用户访问 MySQL 我们需要设置 root 用户密码:

[root@server ~]# /usr/bin/mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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.

You already have a root password set, so you can safely answer ’n'.

Change the 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]
… 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…
    ERROR 1008 (HY000) at line 1: Can’t drop database ’test’; database doesn’t exist
    … Failed! Not critical, keep moving…
  • 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!

安装 PHP

PHP(PHP 是:Hypertext Preprocessor 的缩写)是一种广泛使用的开放源码的通用脚本语言,适合于 Web 开发,可嵌入到 HTML 中。

安装 PHP 命令:

[root@server ~]# yum install php -y

创建一个的 “testphp.php” 的文件在 Apache 的文档根目录文件夹,在其中如入如下代码。命令:

[root@server ~]# vi /var/www/html/testphp.php
phpinfo();
?>

重新启动 httpd 服务:

[root@server ~]# /etc/init.d/httpd restart

用浏览器打开 http://server-ip-address/testphp.php 。它会显示关于 PHP 的详细信息,比如版本,建立日期等。


点击查看原始大图

如果您需要安装所有的 PHP 模块,可以输入 yum install php* -y 来安装,安装完毕后重启 httpd 服务。重启服务后,您可以用浏览器打开 http://server-ip-address/testphp.php 来查看您刚才安装的模块情况。

安装 nstall phpMyAdmi

根据您的情况来选择是否安装 nstall phpMyAdmin 。

phpMyAdmin 是一个免费开源的 MySQL 管理工具。默认情况下 CentOS/RHEL/Scientific Linux 官方库中没有 phpMyAdmin。所以我们需要从 EPEL 库中安装。

首先,我们需要添加 EPEL 库:

[root@server ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

现在我们可以安装 phpMyAdmin 了。安装命令:

[root@server ~]# yum install phpmyadmin -y

安装完毕后,我们需要配置的 phpMyAdmin。打开 phpmyadmin.conf 的文件。查找以“

[root@server ~]# vi /etc/httpd/conf.d/phpMyAdmin.conf

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

Comment the following Section

# Apache 2.4

Require ip 127.0.0.1

Require ip ::1

# Apache 2.2

Order Deny,Allow

Deny from All

Allow from 127.0.0.1

Allow from ::1

打开 config.inc.php 文件,将 cookie 改为 http。

[root@server ~]# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
[root@server ~]# vi /usr/share/phpMyAdmin/config.inc.php
[…]
/* Authentication type */
$cfg[‘Servers’][$i][‘auth_type’] = ‘http’;
[…]

重新启动 Apache 服务:

[root@server ~]# /etc/init.d/httpd restart

现在,您可以访问 phpmyadmin 控制太来管理 MySQL 了。打开一个浏览器,访问:http://server-ip-address/phpmyadmin/ 。需要输入您的 MySQL 用户名和密码,如果您按前面的步骤设置了密码的话。我设置的是 “root” 和 “centOS”。


点击查看原始大图

您将被重定向到 phpMyAdmin 的 Web 主界面:


点击查看原始大图

现在,您能够通过 phpMyAdmin 管理您的 MariaDB 数据库了。

好了,您的 LAMP 服务器已经安装完毕并运行起来了。

相关内容

AI拿走HBM,手机与PC...
“数据库最早发展的时候,关键挑战就是内存墙,到今天,这个‘幽灵’又...
2026-01-31 17:49:06
天翼云上线AI助手Molt...
近日,天翼云宣布全面上线Moltbot,为用户提供“7×24小时在...
2026-01-30 19:49:17
联想宣布AI云超级工厂已经...
近日,联想集团有限公司(以下简称“联想”)宣布AI云超级工厂已落地...
2026-01-28 17:49:18
新买的云服务器如何快速上手...
拿到新云服务器的心情,就像拿到一把新家的钥匙,兴奋之余,可能更多的...
2026-01-26 10:17:31
飞荣达涨1.91%,成交额...
来源:新浪证券-红岸工作室 1月23日,飞荣达涨1.91%,成交额...
2026-01-24 07:48:02
Robo.ai将支持中东、...
(全球TMT2026年1月23日讯)纳斯达克上市公司Robo.ai...
2026-01-23 20:48:01

热门资讯

如何在 Github 上创建一... 学习如何复刻一个仓库,进行更改,并要求维护人员审查并合并它。你知道如何使用 git 了,你有一个 G...
Helix:高级 Linux ... 说到 基于终端的文本编辑器,通常 Vim、Emacs 和 Nano 受到了关注。这并不意味着没有其他...
2020 年的 GitHub ... 距离 2020 年结束只剩下区区 24 天,我们即将结束魔幻的 2020 ,迎来新的一年,新的一年或...
开源新闻速递:openSUSE... 今日关注openSUSE 项目组的 Dominique Leuenberger 在他的周报中说:“这...
《Apex 英雄》正式可在 S... 《Apex 英雄》现已通过 Steam Deck 验证,这使其成为支持 Linux 的顶级多人游戏之...
KDE4.11 Beta1 正...   KDE 项目工作组刚刚发布了 KDE Software Compilation 4.11 Bet...
使用时间序列数据,用开源工具助... InfluxData 是一个开源的时间序列数据库平台。下面介绍了它是如何被用于边缘应用案例的。收集到...
JStock:Linux 上不... 如果你在股票市场做投资,那么你可能非常清楚投资组合管理计划有多重要。管理投资组合的目标是依据你能承受...
Textual:为 Pytho... 快速入门使用 TextualPython 在 Linux 上有像 TkInter 这样的优秀 GUI...
硬核观察 #1245 Open... #1 OpenAI 悄然删除禁止将 ChatGPT 用于 “军事和战争” 的禁令在 1 月 10 日...