fred-ye / summary

my blog
43 stars 9 forks source link

[PHP]XAMPP在Mac环境下的配置 #37

Open fred-ye opened 9 years ago

fred-ye commented 9 years ago

XAMPP在Mac环境下的配置

最近在想接着学学PHP,于是准备在电脑上搭一个环境,在网上搜资料,发现相关的帖子很多,但很多描述都是错误的,真是害人啊,浪费我不少时间。后来参看这个博客终于搭好了,感谢作者。在此处也记录一下具体的步骤,方便以后查找。

下载和安装

1.可以点击此处下载 2.安装XAMPP, 此处不多讲解,双击安装就好,系统会将其安装到我们的Application路径下,如下图 screen shot 2014-11-22 at 3 38 10 pm

启用虚拟路径的配置

  1. 打开 /Applications/XAMPP/xamppfiles/etc/httpd.conf 文件,找到其中的
# Virtual hosts
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

将此处的注释解开。意思是会启用httpd-vhosts.conf文件,这样我们才能配置虚拟路径。

添加虚拟路径

首先在/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf 文件先把已存在的两个虚拟路径的配置注释掉,或者删掉,然后在末尾添加

# localhost
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
    <Directory "/Applications/XAMPP/xamppfiles/htdocs">
        Options Indexes FollowSymLinks Includes execCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# My custom host
<VirtualHost *:80>
    ServerName mysite.com
    DocumentRoot "/Users/fred/Documents/tech/php"
    <Directory "/Users/fred/Documents/tech/php">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

第一个虚拟路径是针对XAMPP的,用来访问XAMPP的控制台。第二个才是我们自己的站点。

修改hosts文件

  sudo vi /etc/hosts

我的改成这个样子: screen shot 2014-11-22 at 3 52 45 pm

注:修改hosts文件需要root权限。 修改完成后重新启动apache。访问mysite.com,发现有403错误,这是因为apache默认是以daemon 的角色运行,于是打开httpd.conf 文件,找到

User/Group: The name (or #number) of the user/group to run httpd as.

It is usually good practice to create a dedicated user and group for

running httpd, as with most system services.

User daemon
Group daemon

   User daemon

换成

  User Fred

注明:我当前使用的帐号名是Fred。到此配置完成,再访问mysite.com发现可以访问了。