I have browsed through the related posts here, but i cannot seem to get my application working.
I decided to use generator-angular-php to quickly setup an end-to-end application.
When i use grunt serve the application seem to work as intended, so i decided to put it, as is, on my apache server. I build it with grunt, and copied the files in the dist-folder to my /var/www//public_html/
The structure is as follows:
- /public_html/
- index.html
- styles : css
- views : view partials .html
- scripts : angularjs controllers
- api
- index.php
- .htaccess #1
- vendor
- autoload.php
- slim
- slim
- index.php
- .htaccess #2
- Slim
- slim php files eg Route.php
- slim
- plenty of other dirs, eg. sebastian, doctrine...
- tests
- src : the example Api
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
The first index.php contains
<?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(),
));
}
}
The .htaccess #2 looks as follows:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA]
The second index.php contains php code to:
-Slim Framework and register its PSR-0 autoloader.
-Instantiate a Slim application
-Define the Slim application routes (get, post, put etc
In my site-enable file for my site i have:
<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>
I have enabled the rewrite-mod.
However, when i open up my site in a browser, i get an:
GET http://myphpportfolio.com/api/features 404 (Not Found)
with the response:
{"status":404,"statusText":"Not Found","description":"Resource \/features using GET method does not exist."}
I haven't altered the code in any way, and since it works durig grunt serve, I am guessing it should work without any alterering (?) This is giving me more gray hairs, and I am out of ideas...what am I missing!