无法在OSX Mavericks上运行localhost PHP服务器


1

所以我以前做过这个,但我不记得这个命令了。我能够使用一个目录localhost文件。我试过sudo apachectl start但是当我去localhost页面时找不到。我也试过重启服务器,但结果仍然一样。有任何想法吗?

Answers:


1

你用.conf文件设置了apache 吗?

对于本地开发环境,通常建议.conf使用您的用户名为apache 创建一个新文件:

  1. 终奌站: sudo nano -w /etc/apache2/users/USERNAME.conf

    其中USERNAME是结果 whoami

  2. 然后把它放在那里:

    <Directory "/Users/USERNAME/Sites/"> Options Indexes Multiviews AllowOverride AuthConfig Limit Order allow,deny Allow from all </Directory>

  3. sudo apachectl restart

以下是未来使用的参考链接:

http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/

祝好运!


1

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启用Apache。/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/工作。

您可以通过取消注释启用PHP #LoadModule php5_module libexec/apache2/libphp5.so/etc/apache2/httpd.conf运行sudo apachectl restart

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.