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.www58058.com/63239

(0)
N24-wenxuanN24-wenxuan
上一篇 2016-12-11 17:33
下一篇 2016-12-11 17:44

相關推薦

  • ?卸載kernel玩一玩

    卸載kernel玩一玩 廢話不多說,下面開始卸載內核這一驚險之旅,特別提醒在開始之前做好虛擬機的快照,也許會造成系統無法啟動,也許會出現各種錯誤,也許會笑著刪數據庫跑路,也許會從入門到放棄,,請系好安全帶。  練習 冒泡排序法 #!/bin/bash##Author:jasonmc#Date:2016-08-24#Description:buble…

    Linux干貨 2016-08-26
  • 第十一周作業

    1、詳細描述一次加密通訊的過程,結合圖示最佳。 一次通信加密過程: 發送方: 1.使用單向加密算法提取生成數據特征碼; 2.使用自己的私鑰加密特征碼附加在數據后面; 3.生成用于對稱加密的臨時密鑰; 4.用此臨時密鑰加密數據和已經使用私鑰加密后的特征碼; 5.使用接受方的公鑰加密此臨時密鑰,附加在對稱密鑰后的數據后方; 接受方: 1.使用自己的私鑰解密加密的…

    2017-10-02
  • 2016-11-4作業

    1、創建一個2G的文件系統,塊大小為2048byte,預留1%可用空間,文件系統ext4,卷標為TEST,要求此分區開機后自動掛載至/test目錄,且默認有acl掛載選項  mkfs.ext4 -b 2048  -L "TEST" -m 1 /dev/sdb6 2、寫一個腳本,完成如下功能: (1) 列出當前系統識別到…

    Linux干貨 2016-11-06
  • N21沉舟11周作業

    1、詳細描述一次加密通訊的過程,結合圖示最佳。 2、描述創建私有CA的過程,以及為客戶端發來的證書請求進行辦法證書。 一、CA服務器端 #進入CA目錄:cd    /etc/pki/CA #創建初始文件touch index.txt serialecho 01 >&nbsp…

    Linux干貨 2016-09-19
  • rsyslog將日志記錄于MySQL中,并用loganalyzer進行分析日志

    1、首先來安裝lamp環境的支持,與其相關的軟件包      # yum -y install rsyslog-mysql mariadb-server php php-mysql php-gd httpd       說明:rsyslog-mysql在數據庫中生成一個庫文件,但這個文件需…

    Linux干貨 2013-09-03
  • 淺談正則表達式

    1.       什么是正則表達式 基本說來,正則表達式是一種用來描述一定數量文本的模式。Regex代表Regular Express。本文將用<<regex>>來表示一段具體的正則表達式。 一段文本就是最基本的模式,簡單的匹配相同的文本。   2. &n…

    Linux干貨 2016-08-12

評論列表(1條)

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

    在Centos 6 和Centos 7 都實現了LAMP,非常的好。

欧美性久久久久