本文主要记录Apache2 的一些环境配置问题
Apache安装过程就不一一细说,Ubuntu的具体安装过程可以参考:Ubuntu 搭建Laravel开发环境
开启php支持
安装完Apache后,大部分东西都是不需要我们关心了,下面介绍几种常用的配置以及用法,如有其它需要,欢迎留言。
首先Apache一般用于PHP开发环境,这就需要我们开启PHP支持
LoadModule php5_module libexec/apache2/libphp5.so
去掉原文件中的“#”,如果是Mac或者Linux,一般不需要额外去配置php的路径,如果是Windows的话加 一个
PHPIniDir "php的安装路径"
更改网站根目录
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All
Require all granted
</Directory>
DocumentRoot
就是配置网站根目录,将后面的地址改为所需要修改的地址,建议采用绝对路径
如果出现
Forbidden
You don’t have permission to access / on this server.
首先,检查一下文件权限问题,Apache对该文件夹是否有读写权限,其次,检查一下网站根目录下是否有相对应的文件(index.html或者其他的),最后,还不行,就把<Directory "/Library/WebServer/Documents">
也改为相对应的路径。
开启多端口
开启多端口支持
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
引入相关配置
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
修改配置文件:
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Users/test/workspace/www/80/public"
ServerName localhost
#erverAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:8080>
#ServerAdmin localhost
DocumentRoot "/Users/test/workspace/www/8080"
ServerName localhost:8080
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>
DocumentRoot
改为相关的目录路径
注意:httpd.conf文件里面DocumentRoot "/Library/WebServer/Documents"
要改为 虚拟端口所在目录的父目录
隐藏index.php或者index.html
开启mod_rewrite模块
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
将 AllowOverride None
改为 AllowOverride All
以上为常用配置,如有额外需要,持续更新……