Apache为Php的基础搭建

1、安装xampp,注意要选择合适的版本
2、xampp的config,根据config中include信息,找到页面程序所在目录,找到对应config
3、写入以下:

#Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/dash/"
#Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs/dash/"

#LoadModule php_module modules/mod_php.so
LoadModule php5_module modules/libphp5.so

# 设置 PHP 解析器的路径
#AddHandler php-script .php
#PHPIniDir "/Applications/XAMPP/xamppfiles/bin/php-5.6.38"
 
# 设置默认文档为 index.php
DirectoryIndex index.php

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/dash/">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<VirtualHost *:80>
    # ServerName localhost
    DocumentRoot /Applications/XAMPP/xamppfiles/apache2/htdocs/dash/public/
</VirtualHost>

注意,在.htaccess中写以下内容,用来处理PATHINFO风格路径

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

等价于nginx的:

location ~* (runtime|application)/{
    return 403;
}
location / {
    if (!-e $request_filename){
        rewrite  ^(.*)$  /index.php?s=$1  last;   break;
    }
}

.htaccess一般在项目根目录下


扫描二维码,在手机上阅读!

发表评论

电子邮件地址不会被公开。 必填项已用*标注