XAMPP for mac 配置多个站点(转载)

/ 0评 / 0

xampp

由于最近有点时间,想将博客改改版(已经在心里呐喊2年多了),改模板直接线上测试查看明显是不可能的,最靠谱还是在本地完全搞好后更新上网。所以 就要搭建一个本地的服务器环境( php + mySQL + Apache)了,现在已经有很多一键搞定的软件可供选择了,在这里介绍下最常用的 XAMPP 了(线上找到的都是 window 的,我就在这里写个mac 下 来作下贡献吧)。

XAMPP下载

这里有传送门http://www.xampp.cc/

XAMPP配置

 

安装完成后在 软件里面 点击 图标,会弹出一个简(jian)约(lou)的控制台,依次点击启动 Apache,MySQL。

修改 Apache 端口

假如 Apache 启动不了 请检查啥占了 80 端口(一般是下载软件),最优选择是把他关了,but 如果找不到 or 实在关不了,可以修改 XAMPP 中的配置文件来改变 Apache 的 80 端口。

shift + cmd + G 打开前往文件夹,然后输入以下地址:

/Applications/XAMPP/etc/httpd.conf

打开后查找 Listen 80 会看到以下的代码片段

1
2
3
4
5
6
7
8
9
10
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

配置多个站点

由于 XAMMP 默认站点必须放在 /Applications/XAMPP/htdocs/ 目录下,对于一些比较纠结 or 文件洁癖的人(例如我) 明显是不能接受的,必须改到我想放的位置才好!具体操作如下

打开 /Applications/XAMPP/etc/httpd.conf

搜索 Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

确保前面没有 # 号:

1
2
3
4
5
6
7
8
# User home directories
Include /Applications/XAMPP/etc/extra/httpd-userdir.conf
# Real-time info on requests and configuration
#Include /Applications/XAMPP/etc/extra/httpd-info.conf
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

然后打开 /Applications/XAMPP/etc/extra/httpd-vhosts.conf 文件

在文件添加以下代码(jackness.org 为例子):

1
2
3
4
5
6
7
8
<VirtualHost *:80>
    ServerAdmin webmaster@jackness.org
    DocumentRoot "/Users/jackness/sites/www.jackness.org"
    ServerName jackness.org
    ServerAlias www.jackness.org
    ErrorLog "logs/mysmarty.com-error_log"
    CustomLog "logs/mysmarty.com-access_log" common
</VirtualHost>

其中 DocumentRoot 为你站点要映射的本地目录,ServerAlias 为你想映射的 站点 域名。

然后打开你的 hosts 文件: /etc/hosts

添加对于的域名本地映射语句:

1
127.0.0.1 www.jackness.org

然后重启 Apache

大功告成!

 

记得修改httpd.conf:

# Virtual hosts
#Include etc/extra/httpd-vhosts.conf

把#去掉

发表评论

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