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

相关推荐

  • Linux系统启动流程、内核及模块管理、linux启动故障排除和自制linux

    Linux系统启动流程、内核及模块管理 Linux系统的组成部分组成:内核+根文件系统(kernel+rootfs)内核(kernel): 进程管理(创建、调度、销毁等)、内存管理、网络管理(网络协议栈)、驱动程序、文件系统、安全功能IPC:Inter Process Communication机制本地进程间通信机制:消息队列、semerphor、shm(共…

    2016-09-29
  • 马哥教育网络班22期-第3周博客作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@zck ~]# who | cut -d ' ' -f1 | sort -u roo root 2、取出最后登录到当前系统的用…

    Linux干货 2016-08-30
  • N22-第十一周作业

    第十一周作业 1、详细描述一次加密通讯的过程,结合图示最佳 (1)为了做到数据的安全,应该同时满足 保密性 完整性 可用性 (2)假设A,B通信,A是客户机,B是服务器 a、客户端向服务器端发送自己支持的加密方式,并且向服务器端请求其CA颁发给的证书 b、服务器选择共同支持的加密方式并发送自己的证书; c、客户端收到其证书,并验证证书,证书必须同时满足以下条…

    Linux干货 2016-12-06
  • 启动和内核管理2

    五、自制linux系统     分区并创建文件系统         fdisk /dev/sdb         分两个必要的分区   &n…

    Linux干货 2016-09-18
  • tomcat

      编程语言:硬件级:微码编程,汇编语言系统级:C,C++,…应用级:Java, PHP, Python, Ruby, Perl, C#, …Python: PVMStandard LibraryWeb Framework:Django, Flask, …Java:JVM,JDKbash:bash ex…

    Linux干货 2017-05-22
  • linux 网络管理命令 SS的使用详则

    SS命令 ss命令用来显示处于活动状态的套接字信息,ss迷路可以用来获取socket统计信息,它可以显示和netstat类似的内容。但ss的优势在于它能够显示更多更详细的有关TCO和连接状态信息,而且比netstat更快速更高效。 当服务器的socket连接数量变得非常大时,无论是使用netest命令还是直接  cat/proc/net/tcp 。…

    2017-08-19

评论列表(1条)

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

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