您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

[PHP] - Apache + PHP 环境搭建

2026/3/18 6:25:29发布10次查看
apache和php的版本分别为:httpd-2.4.9-win64-vc11.zipphp-5.6.9-win32-vc11-x64.zip下载地址:
php-5.6.9-win32-vc11-x64
http://windows.php.net/downloads/releases/php-5.6.9-win32-vc11-x64.zip
httpd-2.4.9-win64-vc11.zip
http://dldx.csdn.net/fd.php?i=615771039219219&s=de822f7950620fad9343c3728e04b1b6
本机使用提win7 64位(基本上现在的操作系统都是64位的了),同时,apache和php的编译器必需是一致。
比如我上面的版本均是vc11。如果一个使用vc9一个是vc11,运行会出错。这点要注意。
将apache解压到:d:\program files\php5.6.9将php解压到:d:\program files\php5.6.9
apache配置:打开conf\httpd.conf文件,修改如下:将所有:c:/apache24替换为:d:/program files/apache24
在前面加入:loadmodule php5_module d:/program files/php5.6.9/php5apache2_4.dllphpinidir d:/program files/php5.6.9addtype application/x-httpd-php .php .html .htm
修改servername:servername 127.0.0.1:80
修改directory: options followsymlinks allowoverride none order deny,allow deny from all
注释掉这个directory:#d:/program files/apache24/htdocs> # # possible values for the options directive are none, all, # or any combination of: # indexes includes followsymlinks symlinksifownermatch execcgi multiviews # # note that multiviews must be named *explicitly* --- options all # doesn't give it to you. # # the options directive is both complicated and important. please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # #options indexes followsymlinks # # allowoverride controls what directives may be placed in .htaccess files. # it can be all, none, or any combination of the keywords: # allowoverride fileinfo authconfig limit # #allowoverride none # # controls who can get stuff from this server. # #require all granted#
加入默认页文件命名: directoryindex index.html index.htm index.php
开启虚拟主机:include conf/extra/httpd-vhosts.conf
httpd.conf文件所有配置:
## this is the main apache http server configuration file. it contains the# configuration directives that give the server its instructions.# see for detailed information.# in particular, see # # for a discussion of each configuration directive.## do not simply read the instructions in here without understanding# what they do. they're here only as hints or reminders. if you are unsure# consult the online docs. you have been warned. ## configuration and logfile names: if the filenames you specify for many# of the server's control files begin with / (or drive:/ for win32), the# server will use that explicit path. if the filenames do *not* begin# with /, the value of serverroot is prepended -- so logs/access_log# with serverroot set to /usr/local/apache2 will be interpreted by the# server as /usr/local/apache2/logs/access_log, whereas /logs/access_log # will be interpreted as '/logs/access_log'.## note: where filenames are specified, you must use forward slashes# instead of backslashes (e.g., c:/apache instead of c:\apache).# if a drive letter is omitted, the drive on which httpd.exe is located# will be used by default. it is recommended that you always supply# an explicit drive letter in absolute paths to avoid confusion.## serverroot: the top of the directory tree under which the server's# configuration, error, and log files are kept.## do not add a slash at the end of the directory path. if you point# serverroot at a non-local disk, be sure to specify a local disk on the# mutex directive, if file-based mutexes are used. if you wish to share the# same serverroot for multiple httpd daemons, you will need to change at# least pidfile.#serverroot d:/program files/apache24## mutex: allows you to set the mutex mechanism and mutex file directory# for individual mutexes, or change the global defaults## uncomment and change the directory if mutexes are file-based and the default# mutex file directory is not on a local disk or is not appropriate for some# other reason.## mutex default:logs## listen: allows you to bind apache to specific ip addresses and/or# ports, instead of the default. see also the # directive.## change this to listen on specific ip addresses as shown below to # prevent apache from glomming onto all bound ip addresses.##listen 12.34.56.78:80listen 80## dynamic shared object (dso) support## to be able to use the functionality of a module which was built as a dso you# have to place corresponding `loadmodule' lines at this location so the# directives contained in it are actually available _before_ they are used.# statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## example:# loadmodule foo_module modules/mod_foo.so#loadmodule access_compat_module modules/mod_access_compat.soloadmodule actions_module modules/mod_actions.soloadmodule alias_module modules/mod_alias.soloadmodule allowmethods_module modules/mod_allowmethods.soloadmodule asis_module modules/mod_asis.soloadmodule auth_basic_module modules/mod_auth_basic.so#loadmodule auth_digest_module modules/mod_auth_digest.so#loadmodule auth_form_module modules/mod_auth_form.so#loadmodule authn_anon_module modules/mod_authn_anon.soloadmodule authn_core_module modules/mod_authn_core.so#loadmodule authn_dbd_module modules/mod_authn_dbd.so#loadmodule authn_dbm_module modules/mod_authn_dbm.soloadmodule authn_file_module modules/mod_authn_file.so#loadmodule authn_socache_module modules/mod_authn_socache.so#loadmodule authnz_ldap_module modules/mod_authnz_ldap.soloadmodule authz_core_module modules/mod_authz_core.so#loadmodule authz_dbd_module modules/mod_authz_dbd.so#loadmodule authz_dbm_module modules/mod_authz_dbm.soloadmodule authz_groupfile_module modules/mod_authz_groupfile.soloadmodule authz_host_module modules/mod_authz_host.so#loadmodule authz_owner_module modules/mod_authz_owner.soloadmodule authz_user_module modules/mod_authz_user.soloadmodule autoindex_module modules/mod_autoindex.so#loadmodule buffer_module modules/mod_buffer.so#loadmodule cache_module modules/mod_cache.so#loadmodule cache_disk_module modules/mod_cache_disk.so#loadmodule cache_socache_module modules/mod_cache_socache.so#loadmodule cern_meta_module modules/mod_cern_meta.soloadmodule cgi_module modules/mod_cgi.so#loadmodule charset_lite_module modules/mod_charset_lite.so#loadmodule data_module modules/mod_data.so#loadmodule dav_module modules/mod_dav.so#loadmodule dav_fs_module modules/mod_dav_fs.so#loadmodule dav_lock_module modules/mod_dav_lock.so#loadmodule dbd_module modules/mod_dbd.so#loadmodule deflate_module modules/mod_deflate.soloadmodule dir_module modules/mod_dir.so#loadmodule dumpio_module modules/mod_dumpio.soloadmodule env_module modules/mod_env.so#loadmodule expires_module modules/mod_expires.so#loadmodule ext_filter_module modules/mod_ext_filter.so#loadmodule file_cache_module modules/mod_file_cache.so#loadmodule filter_module modules/mod_filter.so#loadmodule headers_module modules/mod_headers.so#loadmodule heartbeat_module modules/mod_heartbeat.so#loadmodule heartmonitor_module modules/mod_heartmonitor.so#loadmodule ident_module modules/mod_ident.so#loadmodule imagemap_module modules/mod_imagemap.soloadmodule include_module modules/mod_include.so#loadmodule info_module modules/mod_info.soloadmodule isapi_module modules/mod_isapi.so#loadmodule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so#loadmodule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so#loadmodule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so#loadmodule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so#loadmodule ldap_module modules/mod_ldap.so#loadmodule logio_module modules/mod_logio.soloadmodule log_config_module modules/mod_log_config.so#loadmodule log_debug_module modules/mod_log_debug.so#loadmodule log_forensic_module modules/mod_log_forensic.so#loadmodule lua_module modules/mod_lua.so#loadmodule macro_module modules/mod_macro.soloadmodule mime_module modules/mod_mime.so#loadmodule mime_magic_module modules/mod_mime_magic.soloadmodule negotiation_module modules/mod_negotiation.so#loadmodule proxy_module modules/mod_proxy.so#loadmodule proxy_ajp_module modules/mod_proxy_ajp.so#loadmodule proxy_balancer_module modules/mod_proxy_balancer.so#loadmodule proxy_connect_module modules/mod_proxy_connect.so#loadmodule proxy_express_module modules/mod_proxy_express.so#loadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so#loadmodule proxy_ftp_module modules/mod_proxy_ftp.so#loadmodule proxy_html_module modules/mod_proxy_html.so#loadmodule proxy_http_module modules/mod_proxy_http.so#loadmodule proxy_scgi_module modules/mod_proxy_scgi.so#loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so#loadmodule ratelimit_module modules/mod_ratelimit.so#loadmodule reflector_module modules/mod_reflector.so#loadmodule remoteip_module modules/mod_remoteip.so#loadmodule request_module modules/mod_request.so#loadmodule reqtimeout_module modules/mod_reqtimeout.so#loadmodule rewrite_module modules/mod_rewrite.so#loadmodule sed_module modules/mod_sed.so#loadmodule session_module modules/mod_session.so#loadmodule session_cookie_module modules/mod_session_cookie.so#loadmodule session_crypto_module modules/mod_session_crypto.so#loadmodule session_dbd_module modules/mod_session_dbd.soloadmodule setenvif_module modules/mod_setenvif.so#loadmodule slotmem_plain_module modules/mod_slotmem_plain.so#loadmodule slotmem_shm_module modules/mod_slotmem_shm.so#loadmodule socache_dbm_module modules/mod_socache_dbm.so#loadmodule socache_memcache_module modules/mod_socache_memcache.so#loadmodule socache_shmcb_module modules/mod_socache_shmcb.so#loadmodule speling_module modules/mod_speling.so#loadmodule ssl_module modules/mod_ssl.so#loadmodule status_module modules/mod_status.so#loadmodule substitute_module modules/mod_substitute.so#loadmodule unique_id_module modules/mod_unique_id.so#loadmodule userdir_module modules/mod_userdir.so#loadmodule usertrack_module modules/mod_usertrack.so#loadmodule version_module modules/mod_version.so#loadmodule vhost_alias_module modules/mod_vhost_alias.so#loadmodule watchdog_module modules/mod_watchdog.so#loadmodule xml2enc_module modules/mod_xml2enc.soloadmodule php5_module d:/program files/php5.6.9/php5apache2_4.dllphpinidir d:/program files/php5.6.9addtype application/x-httpd-php .php .html .htm## if you wish httpd to run as a different user or group, you must run# httpd as root initially and it will switch. ## user/group: the name (or #number) of the user/group to run httpd as.# it is usually good practice to create a dedicated user and group for# running httpd, as with most system services.#user daemongroup daemon# 'main' server configuration## the directives in this section set up the values used by the 'main'# server, which responds to any requests that aren't handled by a# definition. these values also provide defaults for# any containers you may define later in the file.## all of these directives may appear inside containers,# in which case these default settings will be overridden for the# virtual host being defined.### serveradmin: your address, where problems with the server should be# e-mailed. this address appears on some server-generated pages, such# as error documents. e.g. admin@your-domain.com#serveradmin admin@example.com## servername gives the name and port that the server uses to identify itself.# this can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## if your host doesn't have a registered dns name, enter its ip address here.#servername 127.0.0.1:80## deny access to the entirety of your server's filesystem. you must# explicitly permit access to web content directories in other # blocks below.# options followsymlinks allowoverride none order deny,allow deny from all## note that from this point forward you must specifically allow# particular features to be enabled - so if something's not working as# you might expect, make sure that you have specifically enabled it# below.### documentroot: the directory out of which you will serve your# documents. by default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.##documentroot d:/program files/apache24/htdocs# # # possible values for the options directive are none, all, # or any combination of: # indexes includes followsymlinks symlinksifownermatch execcgi multiviews # # note that multiviews must be named *explicitly* --- options all # doesn't give it to you. # # the options directive is both complicated and important. please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # #options indexes followsymlinks # # allowoverride controls what directives may be placed in .htaccess files. # it can be all, none, or any combination of the keywords: # allowoverride fileinfo authconfig limit # #allowoverride none # # controls who can get stuff from this server. # #require all granted### directoryindex: sets the file that apache will serve if a directory# is requested.# directoryindex index.html index.htm index.php## the following lines prevent .htaccess and .htpasswd files from being # viewed by web clients. #require all denied## errorlog: the location of the error log file.# if you do not specify an errorlog directive within a # container, error messages relating to that virtual host will be# logged here. if you *do* define an error logfile for a # container, that host's errors will be logged there and not here.#errorlog logs/error.log## loglevel: control the number of messages logged to the error_log.# possible values include: debug, info, notice, warn, error, crit,# alert, emerg.#loglevel warn# # the following directives define some format nicknames for use with # a customlog directive (see below). # logformat %h %l %u %t \%r\ %>s %b \%{referer}i\ \%{user-agent}i\ combined logformat %h %l %u %t \%r\ %>s %b common # 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 # # the location and format of the access logfile (common logfile format). # if you do not define any access logfiles within a # container, they will be logged here. contrariwise, if you *do* # define per- access logfiles, transactions will be # logged therein and *not* in this file. # customlog logs/access.log common # # if you prefer a logfile with access, agent, and referer information # (combined logfile format) you can use the following directive. # #customlog logs/access.log combined# # redirect: allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. the client # will make a new request for the document at its new location. # example: # redirect permanent /foo http://www.example.com/bar # # alias: maps web paths into filesystem paths and is used to # access content that does not live under the documentroot. # example: # alias /webpath /full/filesystem/path # # if you include a trailing / on /webpath then the server will # require it to be present in the url. you will also likely # need to provide a section to allow access to # the filesystem path. # # scriptalias: this controls which directories contain server scripts. # scriptaliases are essentially the same as aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. the same rules about trailing / apply to scriptalias # directives as to alias. # scriptalias /cgi-bin/ d:/program files/apache24/cgi-bin/# # scriptsock: on threaded servers, designate the path to the unix # socket used to communicate with the cgi daemon of mod_cgid. # #scriptsock cgisock## d:/program files/apache24/cgi-bin should be changed to whatever your scriptaliased# cgi directory exists, if you have that configured.# allowoverride none options none require all granted# # typesconfig points to the file containing the list of mappings from # filename extension to mime-type. # typesconfig conf/mime.types # # addtype allows you to add to or override the mime configuration # file specified in typesconfig for specific file types. # #addtype application/x-gzip .tgz # # addencoding allows you to have certain browsers uncompress # information on the fly. note: not all browsers support this. # #addencoding x-compress .z #addencoding x-gzip .gz .tgz # # if the addencoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # addtype application/x-compress .z addtype application/x-gzip .gz .tgz # # addhandler allows you to map certain file extensions to handlers: # actions unrelated to filetype. these can be either built into the server # or added with the action directive (see below) # # to use cgi scripts outside of scriptaliased directories: # (you will also need to add execcgi to the options directive.) # #addhandler cgi-script .cgi # for type maps (negotiated resources): #addhandler type-map var # # filters allow you to process content before it is sent to the client. # # to parse .shtml files for server-side includes (ssi): # (you will also need to add includes to the options directive.) # #addtype text/html .shtml #addoutputfilter includes .shtml## the mod_mime_magic module allows the server to use various hints from the# contents of the file itself to determine its type. the mimemagicfile# directive tells the module where the hint definitions are located.##mimemagicfile conf/magic## customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## some examples:#errordocument 500 the server made a boo boo.#errordocument 404 /missing.html#errordocument 404 /cgi-bin/missing_handler.pl#errordocument 402 http://www.example.com/subscription_info.html### maxranges: maximum number of ranges in a request before# returning the entire resource, or one of the special# values 'default', 'none' or 'unlimited'.# default setting is to accept 200 ranges.#maxranges unlimited## enablemmap and enablesendfile: on systems that support it, # memory-mapping or the sendfile syscall may be used to deliver# files. this usually improves server performance, but must# be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise# broken on your system.# defaults: enablemmap on, enablesendfile off##enablemmap off#enablesendfile on# supplemental configuration## the configuration files in the conf/extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary.# server-pool management (mpm specific)#include conf/extra/httpd-mpm.conf# multi-language error messages#include conf/extra/httpd-multilang-errordoc.conf# fancy directory listings#include conf/extra/httpd-autoindex.conf# language settings#include conf/extra/httpd-languages.conf# user home directories#include conf/extra/httpd-userdir.conf# real-time info on requests and configuration#include conf/extra/httpd-info.conf# virtual hostsinclude conf/extra/httpd-vhosts.conf# local access to the apache http server manual#include conf/extra/httpd-manual.conf# distributed authoring and versioning (webdav)#include conf/extra/httpd-dav.conf# various default settings#include conf/extra/httpd-default.conf# configure mod_proxy_html to understand html4/xhtml1include conf/extra/proxy-html.conf# secure (ssl/tls) connections#include conf/extra/httpd-ssl.conf## note: the following must must be present to support# starting without ssl on platforms with no /dev/random equivalent# but a statically compiled-in mod_ssl.#sslrandomseed startup builtinsslrandomseed connect builtin## uncomment out the below to deal with user agents that deliberately# violate open standards by misusing dnt (dnt *must* be a specific# end-user choice)###browsermatch msie 10.0; bad_dnt###requestheader unset dnt env=bad_dnt#
打开conf\extra\httpd-vhosts.conf文件:修改为:
# virtual hosts## required modules: mod_log_config# if you want to maintain multiple domains/hostnames on your# machine you can setup virtualhost containers for them. most configurations# use only name-based virtual hosts so the server doesn't need to worry about# ip addresses. this is indicated by the asterisks in the directives below.## please see the documentation at # # for further details before you try to setup virtual hosts.## you may use the command line option '-s' to verify your virtual host# configuration. serveradmin admin@example.com # 虚拟主机路径 documentroot f:/phpproject # 虚拟主机域名或ip servername 127.0.0.1 # 虚拟主机域名或ip(别名或第二个域名) serveralias localhost # 错误日志 errorlog logs/dummy-host.localhost-error.log customlog logs/dummy-host.localhost-access.log combined #------------------------------------------------------------------ # 主目录配置权限 #------------------------------------------------------------------ # 列出目录资源 options indexes followsymlinks # 禁止列出目录资源 #options followsymlinks allowoverride all order allow,deny allow from all #------------------------------------------------------------------ # 虚拟目录配置 # 以下别名配置意思是配置一个:http://localhost/p 的虚拟目录 #------------------------------------------------------------------ alias /p f:/phpproject/zendhello # 列出目录资源 options indexes followsymlinks # 禁止列出目录资源 #options followsymlinks allowoverride all order allow,deny allow from all
其中,documentroot是php源码的目录。
php配置:打开php的解压目录,将php.ini-deployment重命名为:php.ini修改extension_dir为:extension_dir = d:/program files/php5.6.9/ext
修改extension:extension=php_bz2.dllextension=php_curl.dllextension=php_fileinfo.dllextension=php_gd2.dllextension=php_gettext.dllextension=php_gmp.dllextension=php_intl.dllextension=php_imap.dll;extension=php_interbase.dllextension=php_ldap.dllextension=php_mbstring.dllextension=php_exif.dll ; must be after mbstring as it depends on itextension=php_mysql.dllextension=php_mysqli.dll;extension=php_oci8_12c.dll ; use with oracle database 12c instant clientextension=php_openssl.dll;extension=php_pdo_firebird.dllextension=php_pdo_mysql.dll;extension=php_pdo_oci.dllextension=php_pdo_odbc.dllextension=php_pdo_pgsql.dll;extension=php_pdo_sqlite.dllextension=php_pgsql.dll;extension=php_pspell.dllextension=php_shmop.dll; the mibs data available in the php distribution must be installed. ; see http://www.php.net/manual/en/snmp.installation.php ;extension=php_snmp.dll;extension=php_soap.dll;extension=php_sockets.dllextension=php_sqlite3.dll;extension=php_sybase_ct.dll;extension=php_tidy.dll;extension=php_xmlrpc.dll;extension=php_xsl.dll
修改date.timezone:date.timezone = asia/shanghai
将apache设置为windows service方法:到apache的bin目录(使用管理员身份运行cmd),运行命令:
httpd.exe -k install
然后双击运行apachemonitor.exe即可。
卸载服务方法是:
httpd.exe -k uninstall
测试
在f:\phpproject目录下面新建一个文件:index.php
php phpinfo();?>
将看到如下:
文章参考:windows下搭建php开发环境
http://www.cnblogs.com/pharen/archive/2012/02/06/2340628.html
手动将apache注册为系统服务
http://www.cnblogs.com/zhenmingliu/archive/2012/01/09/2316886.html
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product