在CentOS/RHEL/Scientific Linux 6下安装 LAMP

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 的文件。查找以“<Directory” 开头到 包含的部分,如下命令所示:

[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 服务器已经安装完毕并运行起来了。

原文发布时间为:2013-07-01

时间: 2024-08-30 23:00:50

在CentOS/RHEL/Scientific Linux 6下安装 LAMP的相关文章

在CentOS/RHEL/Scientific Linux 6 &amp; 7 上安装Telnet

在CentOS/RHEL/Scientific Linux 6 & 7 上安装Telnet 声明: 在安装和使用Telnet之前,需要记住以下几点. 在公网(WAN)中使用Telnet是非常不好的想法.它会以明文的格式传输登入数据.每个人都可以看到明文. 如果你还是需要Telnet,强烈建议你只在局域网内部使用. 你可以使用SSH作为替代方法.但是确保不要用root用户登录. Telnet是什么? Telnet 是用于通过TCP/IP网络远程登录计算机的协议.一旦与远程计算机建立了连接,它就会成

CentOS 6.3 Linux系统下安装Oracle 10g R2

一.硬件要求 1.内存 & swap Minimum: 1 GB of RAM Recommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal /proc/meminfo # grep SwapTotal /proc/meminfo 2.硬盘 由于CentOS安装后差不多有4~5G,再加上Oracle等等的安装,所以请准备至少10G的硬盘空间. 检查磁盘情况 # df -h 二.软件 系统平台:CentOS 6.3(x86_64) CentOS-6

Redhat Linux AS4下安装LAMP与Discuz

LAMP最简单的配置 做这个东西,刚开始觉得挺难的,不想试,后来朋友说弄个论坛试试,所以就先试了.本来想先学iptables的.现在先学基础的LAMP. 看了网上介绍以及鸟哥的东西,安装过程基本如下: 软件如下: Mysql: mysql-4.0.21.tar.gz (刚开始装的是rpm的,可是找不到配置的文件之类的,所以就自己编译了) Php:php-4.4.2.tar.gz Apache:httpd-2.2.0.tar.bz2 Discuz!_4.1.0_SC_GBK.zip (都在CU上下

Linux系统下安装谷歌Google拼音输入法的方法

  Linux系统下安装谷歌Google拼音输入法的方法.目前,网络上提供的拼音输入法非常多,不过,不少网友会觉得使用谷歌拼音输入法这款软件更顺手.那么,谷歌拼音输入法怎么安装使用呢?在今天的教程中,我们就以Linux系统为例子,给大家分享一下谷歌拼音输入法的安装方法.需要说明的是,本操作方法是基于Linux系统的CentOS 5进行的! 谷歌拼音输入法安卓版 推荐:谷歌拼音输入法安卓版 SCIM-GooglePinyin 项目试图将 Android 上的 Google 拼音输入法移植到 GNU

Linux系统下安装rz/sz命令及使用说明(详解)_Linux

对于经常使用Linux系统的人员来说,少不了将本地的文件上传到服务器或者从服务器上下载文件到本地,rz / sz命令很方便的帮我们实现了这个功能,但是很多Linux系统初始并没有这两个命令. 今天,我们就简单的讲解一下如何安装和使用rz.sz命令. 1.软件安装 root 账号登陆后,依次执行以下命令: cd /tmp wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz tar zxvf lrzsz-0.12.20.tar.gz &

求教怎么在一台服务器(linux)下安装多台vmware(或者KVM等别的虚拟机)?

问题描述 求教怎么在一台服务器(linux)下安装多台vmware(或者KVM等别的虚拟机)? 然后在每个虚拟机里各装一个linux(centos),并实现他们的相互通信与管理. 解决方案 安装一个virtualbox 然后设置网络为nat,或者同一局域网.厉害点的安装个xen,再新点的,安装docker玩玩 解决方案二: 第一次提问,没钱悬赏,,万分感谢!! 解决方案三: 第一次提问,没钱悬赏,,万分感谢!! 解决方案四: 第一次提问,没钱悬赏,,万分感谢!! 解决方案五: 第一次提问,没钱悬

请问在新电脑linux环境下安装win7系统,需要对硬盘分区吗?步骤是什么

问题描述 请问在新电脑linux环境下安装win7系统,需要对硬盘分区吗?步骤是什么 请问在新电脑linux环境下安装win7系统,需要对硬盘分区吗?步骤是什么?能描述的详细点吗,一步一步的.....,帮帮忙 解决方案 建议你先安装windows 7 然后安装linux 比较容易,由于在linux 和windows 的文件系统不同,意识很难说清楚, 解决方案二: 只要WIN7的话,建议先格式化硬盘..然后在安装!

linux系统下安装Maven报错如下怎么解决?

问题描述 linux系统下安装Maven报错如下怎么解决? 在使用mvn install命令时出错的

为什么在linux系统下安装QQ的时候出现这种情况?

问题描述 为什么在linux系统下安装QQ的时候出现这种情况? 装入归档文件时出现了一个错误. Archive: /tmp/QQ7.2.exe [/tmp/QQ7.2.exe] End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the centr