所以我以前做過這個,但我不記得命令了。我能夠使用本機主機檔案的目錄。我已經嘗試過,sudo apachectl start
但是當我轉到localhost
該頁面時找不到該頁面。我也嘗試過重啟伺服器,但結果還是一樣。有任何想法嗎?
答案1
您是否使用檔案設定了 apache .conf
?
對於本機開發環境,通常建議.conf
使用您的使用者名稱為 apache 建立一個新檔案:
終端:
sudo nano -w /etc/apache2/users/USERNAME.conf
其中 USERNAME 是以下結果
whoami
然後把它放在那裡:
<Directory "/Users/USERNAME/Sites/"> Options Indexes Multiviews AllowOverride AuthConfig Limit Order allow,deny Allow from all </Directory>
sudo apachectl restart
這是一個供將來使用的參考連結:
http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/
祝你好運!
答案2
sudo -v
在終端機中運行並貼上以下行:
echo '<Directory "/Users/'$USER'/Sites/">
Options Indexes Multiviews
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all
</Directory>'|sudo tee /etc/apache2/users/$USER.conf
sudo sed -i '' 's/#\(LoadModule php5_module.*\)/\1/p' /etc/apache2/httpd.conf
sudo apachectl restart
mkdir -p ~/Sites
echo '<?php phpinfo(); ?>'>~/Sites/test.php
sleep 1
open http://localhost/~$USER/test.php
sudo apachectl start
啟用阿帕契。/usr/sbin/apachectl
是 OS X 中的 shell 腳本,apachectl start
只運行launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
./etc/apache2/users/$USER.conf
需要修改才能http://localhost/~username/
運作。
您可以透過取消註解並運行#LoadModule php5_module libexec/apache2/libphp5.so
來啟用 PHP 。/etc/apache2/httpd.conf
sudo apachectl restart