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 @ 2023-06-14 16:15  love/coder  阅读(279)  评论(0编辑  收藏  举报