LAM(M)P的简单说明:

    L: linux

    A: apache (httpd)

    M: mysql, mariadb

    M:memcached

    P: php, perl, python

说明:本实验在centos7上实现,实验的LAMP基于mariadb ,php,apache

注意:(1)关闭selinux

        vim   /etc/selinux/config

                SELINUX=disabled 

         (2)清除防火墙策略

                    iptables -F


1、安装包

    yum install httpd  mariadb-server  php

    yum install php-mysql    用于数据库与PHP连接

2、启动服务

     systemctl start httpd   mariadb  开启httpd服务和数据库mariadb服务

    ss -ntl 查看端口是否打开

        httpd 默认80端口

        mariadb 默认3306端口

3、简单实现LAP

    (1)修改主页面信息  

            修改httpd的主配置文件 vim  /etc/httpd/conf/httpd.conf

                               DirectoryIndex  index.php  index.html

    (2)编辑主页面,用php代码实现

            vim  /var/www/html/index.php          

<?php
            phpinfo();
?>

             systemctl reload  httpd    重新加载服务

     (3)在浏览器上测试

                    http://192.168.191.107/

                出现下面信息表示成功

                LAMP的实现_LInux

                

4、实现LAMP

     (1)安装完mariadb 默认任何人都能连接的,需要执行一个安全脚本

           mysql_secure_installation

          Enter current password for root (enter for none):       输入之前的root密码,回车表示没有(这里的root表示数据库中的管理员用户)

            Set root password? [Y/n] y       是否设置root口令   ,y
            New password:                            输入两次密码
            Re-enter new password:

            Remove anonymous users? [Y/n] y        是否删除匿名登录,y  ,删除后仅数据库中已存在的用户可以登录

            Disallow root login remotely? [Y/n] n         是否允许root远程连接

            Remove test database and access to it? [Y/n] n     是否删除test数据库

            Reload privilege tables now? [Y/n] y        是否保存以上设置

     (2)为了安全,在数据库中,创建一个用户,用来实现与php的连接

               1>  mysql -uroot -pcentos  登录数据库 root账号,密码centos

               2>  create user 'test'@'192.168.191.%' identified by 'centos';     创建test用户,密码centos ,主机是192.168.191.#的都可以

               3>mysql -utest -pcentos -h '192.168.191.107'   登录查看,创建的普通用户权限小,但是在这里用来连接数据库权限可以满足,可以在后续管理数据库中,对用户授权。

     (3)写测试代码                     

     cd/var/www/html 

 vim index.php

<?php
mysql_connect('192.168.191.107','test','centos');
if ($conn)
        echo "OK";
else
        echo "Failure";
mysql_close();
?>

    (4) 重启 服务 systemctl reload mariadb
 5、测试

        方法(1)在浏览器上测试http://192.168.191.107/

            

            LAMP的实现_LAMP_02

                

     方法(2)在另一台主机上

    LAMP的实现_mariadb_03

连接成功