【发布时间】:2015-08-20 09:39:05
【问题描述】:
我已经浏览了这里的相关帖子,但我似乎无法让我的应用程序正常工作。
我决定使用generator-angular-php 快速设置端到端应用程序。
当我使用 grunt serve 时,应用程序似乎按预期工作,所以我决定将它按原样放在我的 apache 服务器上。我用 grunt 构建它,并将 dist 文件夹中的文件复制到我的 /var/www//public_html/
结构如下:
- /public_html/
- index.html
- 样式:CSS
- 视图:查看部分 .html
- 脚本:angularjs 控制器
- API
- index.php
- .htaccess #1
- 供应商
- 自动加载.php
- 苗条
- 苗条
- index.php
- .htaccess #2
- 修身
- slim php 文件,例如 Route.php
- 苗条
- 许多其他目录,例如。塞巴斯蒂安,学说...
- 测试
- src : 示例 API
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
第一个 index.php 包含
<?php
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
date_default_timezone_set('UTC');
try {
// Initialize Composer autoloader
if (!file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
throw new \Exception('Composer dependencies not installed. Run `make install --directory app/api`');
}
require_once $autoload;
// Initialize Slim Framework
if (!class_exists('\\Slim\\Slim')) {
throw new \Exception(
'Missing Slim from Composer dependencies.'
. ' Ensure slim/slim is in composer.json and run `make update --directory app/api`'
);
}
// Run application
$app = new \Api\Application();
$app->run();
} catch (\Exception $e) {
if (isset($app)) {
$app->handleException($e);
} else {
http_response_code(500);
header('Content-Type: application/json');
echo json_encode(array(
'status' => 500,
'statusText' => 'Internal Server Error',
'description' => $e->getMessage(),
));
}
}
.htaccess #2 如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA]
第二个 index.php 包含 php 代码:
-Slim Framework and register its PSR-0 autoloader.
-Instantiate a Slim application
-Define the Slim application routes (get, post, put etc
在我的网站启用文件中,我有:
<VirtualHost *:80>
ServerAdmin hanto899@myphpportfolio.com
ServerName myphpportfolio.com
ServerAlias www.myphpportfolio.com
DocumentRoot /var/www/myPhpPortfolio/public_html
ErrorLog /var/www/myPhpPortfolio/public_html/error.log
CustomLog /var/www/myPhpPortfolio/public_html/access.log combined
<Directory "/var/www/myPhpPortfolio/public_html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
我已启用重写模块。
但是,当我在浏览器中打开我的网站时,我得到一个:
GET http://myphpportfolio.com/api/features 404 (Not Found)
响应:
{"status":404,"statusText":"Not Found","description":"Resource \/features using GET method does not exist."}
我没有以任何方式更改代码,并且由于它可以在 grunt serve 中工作,我猜它应该可以在没有任何更改的情况下工作(?) 这给了我更多的白发,我没有想法......我错过了什么!
【问题讨论】:
-
你想出解决方案了吗?我使用 generator-angular-php 构建了一个应用程序,当我部署到我是管理员的服务器时,它可以工作。当我部署到共享的服务器时,它不会;所以我很好奇你想出了什么解决方案?
标签: php angularjs apache .htaccess