"Object Not Found!" OSX、Silex 和 XAMPP 开发环境
"Object Not Found!" OSX, Silex and XAMPP development environment
我整天都在为设置 PHP/MySQL 环境而苦苦挣扎,我想我终于可以寻求帮助了。
我有 XAMPP 和 运行。为了在我的首选目录中工作,我将 /Applications/XAMPP/xamppfiles/etc/httpd.conf
更新为:
User MY_USERNAME
...
DocumentRoot "/Users/PATH/TO/WORKING/DIR/web"
<Directory "/Users/PATH/TO/WORKING/DIR/web">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
# since XAMPP 1.4:
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
否则我的 httpd.conf
设置是 XAMPP 默认设置。在我的 web
目录中,我有 index.php:
<?php
require_once __DIR__."/../vendor/autoload.php";
$app = new Silex\Application();
$app->get("/", function () {
return "Hello World";
});
$app->get("/test", function () {
return "Success";
});
$app->run();
?>
如果我转到 localhost
,我得到预期的 "Hello World." 但是,如果我转到 localhost/test
,我得到:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.23 (Unix) OpenSSL/1.0.2h PHP/5.6.24 mod_perl/2.0.8-dev Perl/v5.16.3
这是一个简化得多的示例,但说明了问题。
我已针对此错误搜索了 Google 结果,但 none 的推荐建议有所帮助:
- 很多人建议我更新
.htaccess
,但我不知道它在 XAMPP 中的什么位置或者我应该在哪里创建它或者我应该在其中放入什么或者它是什么。
- 在
httpd.conf
中将 AllowOverride None
更改为 AllowOverride All
的建议似乎没有用。 (在确认它没有帮助后,我将其恢复为默认设置)
如有任何帮助,我们将不胜感激!感谢您的宝贵时间!
解决方案
我在 /Users/PATH/TO/WORKING/DIR/todo
中创建了 .htaccess
,我需要将它放在 /Users/PATH/TO/WORKING/DIR/todo/web
中,我指向 XAMPP。然后在 .htaccess
里面,我把 Silex 告诉我的东西放在那里:http://silex.sensiolabs.org/doc/master/web_servers.html
.htaccess
需要位于 Web 应用程序的根目录中,因此在 web
中。如果它不存在,请创建它。它应该包含此处指示的内容 http://silex.sensiolabs.org/doc/master/web_servers.html
AllowOverride All
确实是必需的,但如果您的 Web 应用程序文件夹中没有任何 .htaccess
文件,它成功的可能性为 0。
我整天都在为设置 PHP/MySQL 环境而苦苦挣扎,我想我终于可以寻求帮助了。
我有 XAMPP 和 运行。为了在我的首选目录中工作,我将 /Applications/XAMPP/xamppfiles/etc/httpd.conf
更新为:
User MY_USERNAME
...
DocumentRoot "/Users/PATH/TO/WORKING/DIR/web"
<Directory "/Users/PATH/TO/WORKING/DIR/web">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
# since XAMPP 1.4:
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
否则我的 httpd.conf
设置是 XAMPP 默认设置。在我的 web
目录中,我有 index.php:
<?php
require_once __DIR__."/../vendor/autoload.php";
$app = new Silex\Application();
$app->get("/", function () {
return "Hello World";
});
$app->get("/test", function () {
return "Success";
});
$app->run();
?>
如果我转到 localhost
,我得到预期的 "Hello World." 但是,如果我转到 localhost/test
,我得到:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost Apache/2.4.23 (Unix) OpenSSL/1.0.2h PHP/5.6.24 mod_perl/2.0.8-dev Perl/v5.16.3
这是一个简化得多的示例,但说明了问题。
我已针对此错误搜索了 Google 结果,但 none 的推荐建议有所帮助:
- 很多人建议我更新
.htaccess
,但我不知道它在 XAMPP 中的什么位置或者我应该在哪里创建它或者我应该在其中放入什么或者它是什么。 - 在
httpd.conf
中将AllowOverride None
更改为AllowOverride All
的建议似乎没有用。 (在确认它没有帮助后,我将其恢复为默认设置)
如有任何帮助,我们将不胜感激!感谢您的宝贵时间!
解决方案
我在 /Users/PATH/TO/WORKING/DIR/todo
中创建了 .htaccess
,我需要将它放在 /Users/PATH/TO/WORKING/DIR/todo/web
中,我指向 XAMPP。然后在 .htaccess
里面,我把 Silex 告诉我的东西放在那里:http://silex.sensiolabs.org/doc/master/web_servers.html
.htaccess
需要位于 Web 应用程序的根目录中,因此在 web
中。如果它不存在,请创建它。它应该包含此处指示的内容 http://silex.sensiolabs.org/doc/master/web_servers.html
AllowOverride All
确实是必需的,但如果您的 Web 应用程序文件夹中没有任何 .htaccess
文件,它成功的可能性为 0。