win7下php環境配置(apache,php,mysql)

來源:互聯網
上載者:User

標籤:

win7是64位旗艦版。

安裝包:

php-5.6.3-Win32-VC11-x64.zip

httpd-2.4.10-win64-VC11.zip

mysql-5.6.22-winx64.zip

解壓到相應的路徑。

1.php

複製php.ini-production,並改名為php.ini,修改如下:

;隱藏PHP版本號碼expose_php = Off;php擴充庫目錄extension_dir = "D:\devsoft\apm\php-5.6.3-Win32-VC11-x64\ext";以下extension=xxx,根據需要開啟相應的.我開啟以下幾項.extension=php_curl.dllextension=php_gd2.dllextension=php_mbstring.dllextension=php_mysql.dllextension=php_pdo_mysql.dllextension=php_xmlrpc.dll;時區date.timezone = Asia/Shanghai;SESSION儲存目錄session.save_path = "D:\config_web\session_home";上傳檔案時使用的臨時目錄upload_tmp_dir = "D:\config_web\upload_home";禁用的函數,先禁用,以後用再開啟.disable_functions = phpinfo,exec,passthru,popen,proc_open,shell_exec,system,assert,chroot,getcwd,scandir,unlink,delete,rmdir,rename,chgrp,chmod,chown,fopen,copy,mkdir,file,file_get_contents,fputs,fwrite,dir

 2.apache

備份原來的httpd.conf,修改如下:

#apache路徑
ServerRoot "D:\devsoft\apm\httpd-2.4.10-win64-VC11\Apache24"

#在LoadModule vhost_alias_module modules/mod_vhost_alias.so
#下面增加3行,增加對php模組的支援,php.ini檔案位置,由php處理的檔案類型(.php .html .htm)
LoadModule php5_module "D:\devsoft\apm\php-5.6.3-Win32-VC11-x64\php5apache2_4.dll"
PHPIniDir "D:\devsoft\apm\php-5.6.3-Win32-VC11-x64"
AddType application/x-httpd-php .php .html .htm

#url重寫模組,我做了簡單的測試
LoadModule rewrite_module modules/mod_rewrite.so

#解決httpd.exe: Could not reliably determine the server‘s fully qualified domain name
ServerName localhost:80
Listen 80

#web程式目錄
DocumentRoot "D:\config_web\php_web_sum\php_web"
<Directory "D:\config_web\php_web_sum\php_web">
#限制使用者訪問檔案的範圍
php_admin_value open_basedir "D:\config_web\php_web_sum\php_web\;D:\config_web\log\;D:\config_web\upload_home\;D:\config_web\session_home\;D:\config_web\upload_home_tmp\"

  #Options Indexes FollowSymLinks
  #Indexes 去掉,防止從web瀏覽目錄
  Options FollowSymLinks
</Directory>

#使Apache首先尋找php檔案,增加index.php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

#rotatelogs按大小,時間來控制日誌
ErrorLog "|D:/devsoft/apm/httpd-2.4.10-win64-VC11/Apache24/bin/rotatelogs.exe logs/error_%Y%m%d.log 5M 86400 +480"

<IfModule log_config_module>

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  #此處,我修改了日期記錄格式. %t => %{[%Y-%m-%d %H:%M:%S]}t
    LogFormat "%h %l %u %{[%Y-%m-%d %H:%M:%S]}t \"%r\" %>s %b" common
    
    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

  #使日誌按5M,天為單位進行分割,同時記錄檔名稱改為以日期結尾.
    CustomLog "|D:/devsoft/apm/httpd-2.4.10-win64-VC11/Apache24/bin/rotatelogs.exe logs/access_%Y%m%d.log 5M 86400 +480" common
    LogFormat "%h %l %u %{[%Y-%m-%d %H:%M:%S]}t %{Referer}i -> %U" referer
    CustomLog "|D:/devsoft/apm/httpd-2.4.10-win64-VC11/Apache24/bin/rotatelogs.exe logs/referer_%Y%m%d.log 5M 86400 +480" referer
    LogFormat "%h %l %u %{[%Y-%m-%d %H:%M:%S]}t %{User-agent}i" agent
    CustomLog "|D:/devsoft/apm/httpd-2.4.10-win64-VC11/Apache24/bin/rotatelogs.exe logs/agent_%Y%m%d.log 5M 86400 +480" agent
</IfModule>

#目錄替換,這項作用還未知.
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "D:\devsoft\apm\httpd-2.4.10-win64-VC11\Apache24\cgi-bin\"
</IfModule>

#目錄替換
<Directory "D:\devsoft\apm\httpd-2.4.10-win64-VC11\Apache24\cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

#我設定的403,404頁面
ErrorDocument 404 /missing.php
ErrorDocument 403 /forbidden.php

#php_flag和php_value設定php.ini中的內容
php_flag display_startup_errors off
php_value display_errors off
php_value error_reporting 2047
php_flag log_errors on

#簡單測試了下url重寫
RewriteEngine on
RewriteRule ^(.*).html$ /$1.php

#隱藏apache版本號碼
ServerSignature Off
ServerTokens Prod

#禁止訪問指定副檔名檔案
<Files ~ "(.*)\.(exe|inc|log|sh|py|pyc|h|c)$">
    Order allow,deny
    Deny from all
</Files>

#指定php記錄檔路徑
php_value error_log D:\config_web\log\php_errors.log

#禁止訪問日誌
<Files "D:\config_web\log\php_errors.log">
 Order allow,deny
 Deny from all
 Satisfy All
</Files>

 3.mysql

複製my-default.ini,並重新命名為my.ini,修改如下:

[mysqld]
# set basedir to your installation pathbasedir=D:\devsoft\apm\mysql-5.6.22-winx64# set datadir to the location of your data directorydatadir=D:\devsoft\apm\mysql-5.6.22-winx64\data#mysql時間資料類型的設定explicit_defaults_for_timestamp=TRUEsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#編碼設定character-set-server=utf8 [mysql]
default-character-set=utf8

 

記錄下配置,主要是目錄,apache支援php,還有許可權的配置。

發現問題請及時指出,我會及時修改。

apache啟動失敗,安裝 vcredist_x64.exe。

apache啟動失敗,缺少libssh2.dll,把libssh2.dll 複製到 C:\Windows\SysWOW64 後解決。

 

win7下php環境配置(apache,php,mysql)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.