apache 配置
常用命令
sudo apachectl start
sudo apachectl stop
sudo apachectl restart
sudo apachectl configtest // debug apache 神器站點配置
在 mac 里面有兩個地方可以放站點,一個是系統層面,一個是用戶層面,系統層面的默認目錄在 /Library/Webserver/Documents,用戶層面的默認目錄在 ~/Sites/。
通常來講,我們只需要在用戶層面配置就好了,在cd 到用戶目錄下,創(chuàng)建 sites 文件夾。
同時我們需要在 apache 里面配置 user 文件,在 /etc/apache2/user/ 里面,以你的用戶名username命名問,username.conf,username是對應你的用戶名的。在里面需要配置 direcroty,配置為如下
<Directory "/Users/steven/Sites/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
作用不多說,具體可以上網查看,主要是用于保證可以重寫,權限可以訪問。
- 虛擬目錄配置
有時候我們的文件夾的目錄和我們實際生產的目錄并不一致,項目文件的目錄嵌套比較深,但是我們希望在顯示出來的時候,是從某一個目錄開始為根目錄,這個時候我們需要配置虛擬目錄。
同樣去到 /etc/apache2/extra,找到 httd-vhost.conf,注釋掉原來的配置,配置如下代碼:
<VirtualHost *:80>
DocumentRoot "/Users/steven/Sites/laravel/public"
ServerName mysite.com
ErrorLog "/private/var/log/apache2/mysite-error_log"
CustomLog "/private/var/log/apache2/mysite-access_log" common
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
同時在 /etc/hosts 文件里面,添加上對應的映射
127.0.0.1 mysite.com
- 重寫模塊開啟
LoadModule rewrite_module libexec/apache2/mod_rewrite.so