备注:历时两小时,完成配置mac的Apache2+thinkphp以及虚拟主机
其中还是有很多坑等着你的~
首先来看看Apache2需要主要的配置项 /etc/httpd.conf
sudo vim /etc/apache2/httpd.conf
然后修改以下配置
//需要打开的配置
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
// 重新指定地址
DocumentRoot "/Users/Ajzzz/Documents/www"
<Directory "/Users/Ajzzz/Documents/www">
#
# 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
#MultiviewsMatch Any
#
# 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 All
#Options All
#Allow from all
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
切换了网站根目录之后,记得给予权限:
sudo chmod -R 0777 地址
接下来是虚拟主机配置文件:
sudo vim /etc/apache2/extra/httpd-vhost.conf
在最后追加配置项:
<VirtualHost *:80>
DocumentRoot "网站根目录绝对地址"
ServerName www.appjobs.cc
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
<Directory "网站根目录绝对地址">
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo Options
Require all granted
</Directory>
</VirtualHost>
修改host配置:
sudo vim /etc/hosts
在文件最后追加:
127.0.0.1 www.appjobs.cc
最后重新Apache
// 检查配置是否出错
sudo apachectl configtest
// 重启服务
sudo apachectl restart