Centos 7配置LAMP

由于安装zabbix须要LAMP环境,特记录以下。php

LAMP指的Linux(操做系统)、Apache HTTP 服务器,MySQL(有时也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,通常用来创建web应用平台。全部组成产品均是开源软件,是国际上成熟的架构框架,不少流行的商业应用都是采起这个架构,和Java/J2EE架构相比,LAMP具备Web资源丰富、轻量、快速开发等特色,微软的.NET架构相比,LAMP具备通用、跨平台、高性能、低价格的 优点,所以LAMP不管是性能、质量仍是价格都是企业搭建网站的首选平台。html

下面讨论如何在RHEL/CentOS/Scientific Linux 7上搭建LAMP环境.mysql

1、Install Apache

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,能够在大多数计算机操做系统中运行,因为其多平台和安全性被普遍使用,是最流行的Web服务器端软件之一。它快速、可靠而且可经过简单的API扩展,将Perl/Python等解释器编译到服务器中。linux

在终端以root权限运行如下命令:web

yum install httpd -y

启动Apachesql

systemctl start httpd

设置开机启动数据库

systemctl enable httpd

firewall设置容许远程登陆:apache

firewall-cmd --permanent --add-service=http

systemctl restart firewalld

测试Apachecentos

浏览器访问 http://localhost/ or http://server-ip-address/浏览器

clip_image001[8]

2、Install MariaDB

        MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL受权许可 MariaDB的目的是彻底兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美圆的价格,将本身建立的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的全部权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。

安装MariaDB

yum install mariadb-server mariadb -y

启动MariaDB

systemctl start mariadb

设置开机启动

systemctl enable mariadb

设置root密码

默认状况下,root密码为空。为防止未受权的访问,咱们设置root密码

mysql_secure_installation

3、Install PHP

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言,主要适用于Web开发领域。

使用如下的命令安装php

yum install php php-mysql php-gd php-pear -y

测试PHP:

在Apache文档根目录建立“testphp.php”

vi /var/www/html/testphp.php

编辑内容以下

<?php 

phpinfo();

?>

重启 httpd 服务:

systemctl restart httpd

浏览器访问 http://server-ip-address/testphp.php. 将会显示php的版本信息.

clip_image002[4]

也可使用以下命令安装全部php modules,重启httpd服务,查看http://server-ip-address/testphp.php能够看到全部安装的modules

yum install php* -y

4、Install phpMyAdmin (可选)

phpMyAdmin 是一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库。因为phpMyAdmin跟其余PHP程式同样在网页服务器上执行,您能够在任何地方使用这些程式产生的HTML页面,也就是于远端管理MySQL数据库,方便的创建、修改、删除数据库及资料表。也可借由phpMyAdmin创建经常使用的php语法,方便编写网页时所须要的sql语法正确性。

添加 EPEL repository   参照(Install EPEL Repository on RHEL/CentOS/Scientific Linux 7

yum install epel-release

安装 phpMyAdmin:

yum install phpmyadmin -y

配置phpMyAdmin

默认,phpMyAdmin只能由本机访问。为了可以远程访问,编辑phpmyadmin.conf file:

vi /etc/httpd/conf.d/phpMyAdmin.conf

查找/<Directory> ,注释掉或删除以下内容

<Directory /usr/share/phpMyAdmin/>

   AddDefaultCharset UTF-8

 

   <IfModule mod_authz_core.c>

     # Apache 2.4

     <RequireAny>

       Require ip 127.0.0.1

       Require ip ::1

     </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

     # Apache 2.2

     Order Deny,Allow

     Deny from All

     Allow from 127.0.0.1

     Allow from ::1

   </IfModule>

</Directory>

 

<Directory /usr/share/phpMyAdmin/setup/>

   <IfModule mod_authz_core.c>

     # Apache 2.4

     <RequireAny>

       Require ip 127.0.0.1

       Require ip ::1

     </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

     # Apache 2.2

     Order Deny,Allow

     Deny from All

     Allow from 127.0.0.1

     Allow from ::1

   </IfModule>

</Directory>

添加

<Directory /usr/share/phpMyAdmin/>

        Options none

        AllowOverride Limit

        Require all granted

</Directory>

编辑“config.inc.php” 改变phpMyAdmin的authentication,修改“cookie” 为 “http”

vi /etc/phpMyAdmin/config.inc.php

Change ‘cookie’ to ‘http’.

clip_image003[4]

重启the Apache service:

systemctl restart httpd

访问 phpmyadmin 的控制台 http://server-ip-address/phpmyadmin/

clip_image004[4]

输入MySQL username and password,将重定向到PhpMyAdmin main web interface.

clip_image005

如今你能够经过phpMyAdmin web interface 管理你的MariaDB数据库了。

至此LAMP环境搭建完毕

参考:

http://www.unixmen.com/install-lamp-server-apache-mariadb-php-centosrhelscientific-linux-7/

相关文章
相关标签/搜索