XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建站集成软件包。支持Windows、Linux、Solaris、Mac OS X 等多种操作系统下安装使用,支持多语言。对于刚接触PHP后台开发的同学来说,省了很多事情,可以快速建立自己的服务器。
下载地址
XAMPP选择OS X系统最好下载最新的版本。
- 下载后按照提示安装完成后,开启的界面应该是这样的。
配置虚拟主机
- 在终端运行
vim /Applications/XAMPP/etc/httpd.conf
,打开XAMPP Apche的配置文件 - 找到
#Include /private/etc/apache2/extra/httpd-vhosts.conf
,去掉前面的“#”。
找到下面内容:
<Directory />
AllowOverride none
Require all denied
</Directory>
改为:
<Directory />
AllowOverride none
# Require all denied
Require all granted
</Directory>
保存并退出。
- 在终端运行
vi /Applications/XAMPP/etc/extra/httpd-vhosts.conf
打开配置虚拟主机文件httpd-vhost.conf,配置虚拟主机。注释掉默认的两个虚拟主机。添加自己的虚拟主机:
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "/Applications/XAMPP/xamppfiles/docs/dummy-host.example.com"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot "/Applications/XAMPP/xamppfiles/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
<VirtualHost *:80>
# This is not needed but seriously recommended
ServerAdmin admin@XXX.com
# Path to your folder
DocumentRoot "/Users/aimoke/Documents/MyPHPWorkspace/dev"
# This line is your host name (example.dev if you prefere)
ServerName local.design.com
# You can add another server name using ServerAlias
ServerAlias zhuo.dev
# For the error file, exactly like you did
ErrorLog "/private/var/log/apache2/sites-error_log"
CustomLog "/private/var/log/apache2/sites-access_log" common
# A little bonus that remove the server signature from http requests
ServerSignature Off
# Here are options neeeded to authorizations and I added some classical options
<Directory "/Users/aimoke/Documents/MyPHPWorkspace/dev">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
保存并退出,并重启Apache。这里的ServerAdmin
和DocumentRoot
,ServerName
可以根据自己的实际情况进行修改。但是ServerName
要和下一步骤hosts
中对应起来。
- 运行
sudo vi /etc/hosts
,打开hosts配置文件,加入127.0.0.1 local.design.com
,这样就可以配置完成 XAMPPlocal.design.com
虚拟主机了。
其实XAMPP的配置和Mac OS X中配置Apache基本一样。但是需要注意的是不要和系统自带的Apache同时开启。