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 17:33
下一篇 2016-12-11 17:44

相关推荐

  • httpd协议配置进阶

    目录 虚拟主机配置 status状态页面 curl命令 mod_deflate模块 https配置 httpd自带应用程序 虚拟主机配置 有三种实现方案:    基于IP:        为每个虚拟主机准备至少一个IP地址    基于端口:     &nbsp…

    Linux干货 2016-10-31
  • Linux基础知识(五)

    本文主要讲述使用grep做模式匹配,具体示例包括: 1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; 3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行; 4、添加用户b…

    Linux干货 2016-10-23
  • 老王的心路历程(二):下一站Web体验监控产品

    在上一篇文章中,和大家聊到了建立Web应用体验监控体系,经过了概念阶段,也完成了技术选型,就进入了把实质性的产品研发阶段。作为产品经理,时刻不敢忘记我们的产品目标:无限感知你的用户,建立完备的体验监控体系,驱动产品的设计、开发和运维! 一、一切皆操作 仔细分析终端用户和Web应用及网站的交互过程,无论是打开页面、点击链接或按钮,还是填写表单、提交查询,一切皆…

    2016-08-15
  • 进程管理

    linux维护工作中,常常需要对系统上运行的程序进行管理,那么进程管理就显得相当重要。 进程初识 什么是进程?   进程是并发执行的程序在执行过程中分配和管理资源的基本单位,是一个动态概念。它代表CPU所能处理的单个任务。 什么是线程?   线程是程序流执行的最小单元,可以理解为进程中执行的一段程序片段。 进程与线程联…

    Linux干货 2016-09-07
  • python

    作业;练习

    2018-03-21
  • 9.脚本练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现;  declare -a shell     declare sum_login=0     declare sum_nologin=0     shell=($(cat /etc/pass…

    2017-09-20

评论列表(1条)

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

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