centos系列初步搭建LAMP

centos6搭建LAMP

系统环境

ip=192.168.0.105 
selinux为:setenforce 0 
iptables 为stop

客户机需要修改hosts文件

1.192.168.2.105 www1.stuX.com
2.192.168.2.105 www2.stuX.com

安装LAMP组件

1.yum install httpd php php-mysql mysql-server

设置mysql

启动mysqld服务 并设置自启动

1.service mysqld start
2.chkconfig mysqld on

之后进去mysql命令行,加入测试使用的代码

1.mysql
1.GRANT ALL PRIVILEGES ON testdb.* TO gwx@'192.168.%.%' IDENTIFIED BY '1';

之后重启mysqld服务

1.service mysqld  restart 

httpd相关配置

搭建两个虚拟主机

为两个虚拟主机创建相关目录

1.mkdir -p /web/vhosts/www{1,2}
2.mkdir -p /var/log/httpd/www{1,2}

httpd配置文件中配置相关虚拟主机相关配置

1.vi /etc/httpd/conf/httpd.conf
1.ServerName localHost
2.#DocumentRoot "/var/www/html"
3.NameVirtualHost 192.168.2.105:80
4.<VirtualHost 192.168.2.105:80>
5.    ServerAdmin gwx@stuX.com
6.    DocumentRoot /web/vhosts/www1
7.    ServerName www1.stuX.com
8.    ErrorLog /var/log/httpd/www1/error_log
9.    CustomLog /var/log/httpd/www1/access_log common
10.</VirtualHost>
11.<VirtualHost 192.168.2.105:80>
12.    ServerAdmin gwx@stuX.com
13.    DocumentRoot /web/vhosts/www2
14.    ServerName www2.stuX.com
15.    ErrorLog /var/log/httpd/www2/error_log
16.    CustomLog /var/log/httpd/www2/access_log common
17.</VirtualHost>                                        

虚拟主机www1.stuX.com的主页代码

1.vi /web/vhosts/www1/index.php
1.<h1>This a test page for php and mysql in the server of www1.stuX.com</h1>
2.<?php
3.    $conn = mysql_connect('192.168.2.105','gwx','1');                      
4.    if ($conn)
5.        echo "OK";
6.    else
7.        echo "Failed";
8.    phpinfo();
9.
10.?>

虚拟主机www2.stuX.com的主页代码

1.vi /web/vhosts/www2/index.php
1.<h1>This a test page for php and mysql in the server of www2.stuX.com</h1>
2.<?php
3.    $conn = mysql_connect('192.168.2.105','gwx','1');                      
4.    if ($conn)
5.        echo "OK";
6.    else
7.        echo "Failed";
8.    phpinfo();
9.
10.?>

启动httpd 并设置自启动

1.service httpd start
2.chkconfig httpd on

centos7搭建LAMP

系统环境

ip=1992.168.2.104 
selinux为:setenforce 0 
firewalld 为stop

安装LAMP组件

yum install -y httpd php-fpm php-mysql mariadb-server

设置mysql

启动mysqld服务 并设置自启动

1.systemctl start mariadb.service
2.systemctl enable mariadb.service

之后进去mysql命令行,加入测试使用的代码

1.mysql
1.GRANT ALL PRIVILEGES ON testdb.* TO gwx@'192.168.%.%' IDENTIFIED BY '1';

之后重启mysqld服务

1.systemctl restart mysqld

httpd相关配置

搭建两个虚拟主机

为两个虚拟主机创建相关目录

1.mkdir -p /web/vhosts/www{1,2}
2.mkdir -p /var/log/httpd/www{1,2}

httpd配置文件中配置相关虚拟主机相关配置

1.vi /etc/httpd/conf/httpd.conf
1.ServerName localHost
2.<Directory />
3.    AllowOverride none
4.    Require all ip 192.168.0.0/24
5.</Directory>
6.#DocumentRoot "/var/www/html"
7.<VirtualHost 192.168.2.104:80>
8.    ServerAdmin gwx@stuX.com
9.    DocumentRoot /web/vhosts/www1
10.    ServerName www1.stuX.com
11.    ErrorLog /var/log/httpd/www1/error_log
12.    CustomLog /var/log/httpd/www1/access_log common
13.</VirtualHost>
14.<VirtualHost 192.168.2.104:80>
15.    ServerAdmin gwx@stuX.com
16.    DocumentRoot /web/vhosts/www2
17.    ServerName www2.stuX.com
18.    ErrorLog /var/log/httpd/www2/error_log
19.    CustomLog /var/log/httpd/www2/access_log common
20.</VirtualHost>                                        

虚拟主机www1.stuX.com的主页代码

1.vi /web/vhosts/www1/index.php
1.<h1>This a test page for php and mysql in the server of www1.stuX.com</h1>
2.<?php
3.    $conn = mysql_connect('192.168.2.105','gwx','1');                      
4.    if ($conn)
5.        echo "OK";
6.    else
7.        echo "Failed";
8.    phpinfo();
9.
10.?>

虚拟主机www2.stuX.com的主页代码

1.vi /web/vhosts/www2/index.php
1.<h1>This a test page for php and mysql in the server of www2.stuX.com</h1>
2.<?php
3.    $conn = mysql_connect('192.168.2.105','gwx','1');                      
4.    if ($conn)
5.        echo "OK";
6.    else
7.        echo "Failed";
8.    phpinfo();
9.
10.?>

启动httpd 并设置自启动

1.systemctl  start httpd
2.systemctl enable httpd

原创文章,作者:N24-wenxuan,如若转载,请注明出处:http://www.178linux.com/63239

(0)
N24-wenxuanN24-wenxuan
上一篇 2016-12-11
下一篇 2016-12-11

相关推荐

  • Linux 入门基础 及一些常见命令(下)

    date:                    显示日期时间:date [OPTION]… [+FORMAT]        &nbsp…

    Linux干货 2016-09-17
  • MySQL常用字符函数

    MySQL常用字符函数简介 CONCAT(S1,S2…Sn) 连接S1,S2…Sn为一个字符串 concat函数,把传入的参数连接成为一个字符串。 例如: 把“aaa”、“bbb”、”ccc”3个字符串连接成一个字符串,“aaabbbccc”.另外任何与NULL进行连接的结果都将是NULL. >SELEC…

    Linux干货 2017-05-01
  • LINUX系统文件类型分类

    使用LINUX过程中,时常会对文件进行操作。但是linux中文件究竟有哪些分类呢?今天让我们大家来总结一下吧! 概述:         linux文件可以分为五种类型,分别为:普通文件、目录、字符设备或块设备、套接口文件、符号链接文件。下面详细介绍这几种文件。 1 普通文件[root@lo…

    Linux干货 2017-07-22
  • Linux脚本基础练习

    马哥教育网络班+ 第7周课堂练习 Linux脚本基础练习 练习: 1、创建一个10G分区,并格式为ext4文件系统; (1)要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl (2)挂载至/data/mydata目录 要求挂载时禁止程序自动运行,且不更新文件的访问时间戳 第一步,在虚拟机中挂载一块20G的新硬盘 &…

    Linux干货 2016-11-09
  • 网络配置——路由配置实验

    一、实验环境: 4台虚拟主机,2台CentOS6.8主机做了R1路由器和PC1主机,2台CentOS7.2主机做了R2路由器和PC2主机,4台主机工作在桥接模式下 实验拓扑图: 二、网络配置: ·PC1的网卡配置; ·PC2的网卡配置; ·R1的网卡配置; ·R2的网卡配置; ·启用路由      &nbsp…

    Linux干货 2016-09-07
  • PXE网络引导系统自动化安装CentOS7

     一.PXE 注意:安装前 selinux 禁用,iptables 关闭 dhcp 服务器静态IP地址  1.PXE的工作原理:      Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC  &nbsp…

    Linux干货 2017-07-24

评论列表(1条)

  • 马哥教育
    马哥教育 2016-12-14 14:55

    在Centos 6 和Centos 7 都实现了LAMP,非常的好。