首頁  >  文章  >  後端開發  >  Apache和PHP的設定詳細講解

Apache和PHP的設定詳細講解

韦小宝
韦小宝原創
2018-02-23 10:01:517468瀏覽

我們在配置PHP運行環境時很多初學者都會選擇使用phpstudy作為開發環境工具,我們這就來講一下在phpstudy中的apache的配置和PHP的配置,廢話少說我們一起來看一下本篇文章吧!

 Apache 設定詳解

設定檔:httpd.conf

#1.基本設定


ServerRoot  "D:/Apache"  
Apache的安裝

目錄

Listen  80 伺服器監聽的連接埠號碼

#ServerName  www.xxx.com:80 主網站名稱(網站的主機名稱)

ServerAdmin xxx@qq.com 管理員的郵件地址

#DocumentRoot "D:/WWW" 網站的根目錄#2.以下是對主網站目錄進行存取控制


#Options FollowSymLinks

#AllowOverride None

Order allow,deny

#Allow from all#選項詳解:


Options:設定在特定目錄中使用那些屬性,其值和意義如下


    ExecCGI 允許在此目錄下執行CGI腳本

    FollowSymLinks 在此目錄下允許檔案系統使用符號連接

    Indexs 在當使用者存取目錄時,如果找不到DirectoryIndex指定的主頁檔案(如index.html)則傳回該目錄的檔案清單給使用者


    SymLinksIfOwnerMatch 當使用符號連接時,只有符號連接的擁有者與檔案的擁有者相同時才可以存取

AllowOverride: 允許村莊與.htaccess檔案中的指令(.htaccess的檔案名稱可以更改,其檔案名有AccessFileName指令決定)

    None: 當設定為None時,預設不搜尋伺服器目錄的.htaccess文件,可以減少伺服器開銷

    All:  在.htaccess檔案中可以使用所有的指令

Order: 控制在存取時Allow,deny兩個存取規則哪個優先

    All:允許存取的主機清單

    Deny:拒絕存取的主機清單

DirectoryIndex: index.html index.htm index.php 預設首頁的檔案3.虛擬網站的設定

條件:在http.conf 中將httpd-vhosts.conf包含進來

# Virtual hosts
      Include conf/extra/httpd-vhosts.conf
##在httpd-vhost.conf中設定

# (1)基於IP的虛擬主機

#修改hosts文件,新增3個域名與之對應

192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com

建立虛擬主機存放檔案的根目錄,如

www/test1/1.html
www/test2/2.html
www/test3/3.html
在httpd-vhosts.conf進行如下設定

<VirtualHost 192.188.1.11*80>
         ServerName www.test1.com
         DocumentRoot "www/test1"
         <Directory "www/test1">
             Options Indexs FollowSysLinks
             AllowOverride None
             Order allow deny
             allow from all
             DirectoryIndex  index.html index.htm index.php
         </Directory>
</VirtualHost>
        
<VirtualHost 192.168.1.12:80>
          ServerName www.test2.com
           DocumentRoot /www/test2/
          <Directory "/www/test2">
             Options Indexes FollowSymLinks
              AllowOverride None
              Order allow,deny
              Allow From All
           </Directory>
</VirtualHost>
  
<VirtualHost 192.168.1.13:80>
        ServerName www.test3.com
        DocumentRoot /www/test3/
        <Directory "/www/test3">
         Options Indexes FollowSymLinks
         AllowOverride None
         Order allow,deny
          Allow From All
       </Directory>
</VirtualHost>
(2)基於主機名稱


#設定網域名稱映射同一個主機

192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com

設定存放網頁的根目錄

www/test1/1.html
www/test2/2.html
www/test3/3.html
在使用基於網域名稱的虛擬主機時,必須指定伺服器的IP位址和可能的存取連接埠來使主機接受請求,可以使用NameVirtualHost指令來配置,如果伺服器上所有的IP都會用到,則可以使用*來表示,在NameVirtualHost指定的ip並不會讓伺服器監聽這個IP

# 接著設定017421ec4e1d87ae7f66fefe80084b1d

如果在現有的WEB伺服器上設定虛擬主機,則必須為現存的虛擬主機也設定017421ec4e1d87ae7f66fefe80084b1d ,其中ServerName 和DocumentRoot包含的內容應該與全域的內容一致,且要放在設定檔的最前面,作為預設主機的設定

 NameVirtualHost *:80
<VirtualHost *:80>
        ServerName www.test1.com
        DocumentRoot "www/test2"
        <Directory "www/test1">
             Options Indexs FollowSymLinks
             AllowOverride None
             Order allow,deny
             allow from all
        </Directory>
</VirtualHost>
       <VirtualHost *:80>
        ServerName www.test2.com
        DocumentRoot "www/test2"
        <Directory "www/test2">
             Options Indexs FollowSymLinks
             AllowOverride None
             Order allow,deny
             allow from all
        </Directory>
</VirtualHost>
<VirtualHost *:80>
        ServerName www.test3.com
        DocumentRoot "www/test3"
        <Directory "www/test3">
             Options Indexs FollowSymLinks
             AllowOverride None
             Order allow,deny
             allow from all
        </Directory>
</VirtualHost>
( 3)基於連接埠

###

修改httpd.conf
设置为 Listen 8001、Listen 8002

修改虚拟主机配置文件 httpd-vhosts.conf

<VirtualHost *:8001>
         ServerName www.test1.com
         DocumentRoot "www/test1"
     </VirtualHost>
      <VirtualHost *:8002>
         ServerName www.test2.com
         DocumentRoot "www/test2"
</VirtualHost>

PHP 配置

配置文件:php.in

1. 模块加载:

extension = php_mysql.dll

2. 修改模块的目录

extension_dir = "D:/php/ext"

也可以将 D:/php ,D:/php/ext 添加到系统环境变量中

 3. 在Apache中配置php

    更改httpd.conf

LoadModule php5_module "D:/php/php5apache2_2.dll 添加PHP模块

PHPIniDir "D:/php" 配置php.in路径

 配置AddType

AddType application/x-httpd-php .php
AddType application/x-httpd-php .txt

4. register_globals = Off 设置是否开启全局变量

若设置为On

已GET/POST提交的参数,直接可以使用变量用调用, 建议不开启

5.设置时区:date.timezone =PRC

以上就是本篇文章的所有内容,希望对你的PHP学习提供到帮助!

相关文章:

Apache和PHP的配置

以上是Apache和PHP的設定詳細講解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn