Apache配置php运行环境

apache2.4 x64php7.4.27

解压缩php安装文件到目录,修改php.ini配置文件里的exe扩展目录,时区设置,编码设置等,略。

解压Apache到目录,执行安装注册服务等。

注册apache服务

管理员cmd到bin目录下执行:
httpd.exe -k install -n "Apache24"

打开服务:net start Apache24或在任务管理器打开

配置文件修改

复制代码
Apache配置C\Apache24\conf\httpd.conf
ServerRoot Apache安装主目录
listen 监听端口
servername 域名或主机名

虚拟主机配置:

#虚拟主机及虚拟目录
<VirtualHost *:8080>
#该虚拟主机发布目录
DocumentRoot "G:/projects/public"
#DocumentRoot "{SRVROOT}"     ServerName localhost:8080     ServerAlias localhost:8080 #www.aaa.com www.bbb.com    #绑定多个域名,如果你网站有多个域名的话     DirectoryIndex index.php #设置默认的访问的页面    <Directory "G:/projects/public">  Options Indexes FollowSymLinks  AllowOverride All  Require all granted   Header set Access-Control-Allow-Origin *          Header set Access-Control-Allow-Methods GET,POST,OPTIONS          Header set Access-Control-Allow-Headers Content-Type,*          Header set Access-Control-Allow-Credentials true     </Directory>     ErrorLog "{SRVROOT}\logs\error.log"
CustomLog "${SRVROOT}\logs\access.log" "[%a]%{%F %T}t id=%{APIIndex}i time=%D(us) url=%U%q"
</VirtualHost>



默认文档

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php index.htm #这里的顺序也是网站起始页的优先级
</IfModule>

443占用

conf\extra\httpd-ahssl.conf修改443为其他端口或禁用ssl

 

复制代码

.htacess文件(一般放在项目根目录下)

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

静态文件映射

 

php输出乱码

1、php代码文件编码为utf-8
2、php.ini设置默认编码为utf-8   
3、项目目录添加指令
<Directory "C:\projects\phptestpro">
    AddDefaultCharset  utf-8
</Directory>
一般前两条就够用。

 

posted @   love/coder  阅读(291)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
点击右上角即可分享
微信分享提示