I have a project that working on XAMPP and APACHE and i want to switch to NGINX
My project structure like this:
-project:
----index.php:
index in project
define(‘APP_DIR’, ‘app’);
define(‘DS’, DIRECTORY_SEPARATOR);
define(‘ROOT’, dirname(FILE));
define(‘WEBROOT_DIR’, ‘webroot’);
define(‘WWW_ROOT’, ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
/**
- This only needs to be changed if the “cake” directory is located
- outside of the distributed structure.
- Full path to the directory containing “cake”. Do not add trailing directory separator
*/
if (!defined(‘CAKE_CORE_INCLUDE_PATH’)) {
define(‘CAKE_CORE_INCLUDE_PATH’, ROOT . DS . ‘lib’);
}
require APP_DIR . DS . WEBROOT_DIR . DS . ‘index.php’;
----app:
index in app
require ‘webroot’ . DIRECTORY_SEPARATOR . ‘index.php’;
-------webroot:
index in webroot
if (!defined(‘DS’)) {
define(‘DS’, DIRECTORY_SEPARATOR);
}
if (!defined(‘ROOT’)) {
define(‘ROOT’, dirname(dirname(dirname(FILE))));
}
if (!defined(‘APP_DIR’)) {
define(‘APP_DIR’, basename(dirname(dirname(FILE))));
}
$vendorPath = ROOT . DS . APP_DIR . DS . ‘Vendor’ . DS . ‘cakephp’ . DS . ‘cakephp’ . DS . ‘lib’;
$dispatcher = ‘Cake’ . DS . ‘Console’ . DS . ‘ShellDispatcher.php’;
if (!defined(‘CAKE_CORE_INCLUDE_PATH’) && file_exists($vendorPath . DS . $dispatcher)) {
define(‘CAKE_CORE_INCLUDE_PATH’, vendorPath);
}
if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (PHP_SAPI === 'cli-server') {
if (_SERVER[‘REQUEST_URI’] !== ‘/’ && file_exists(WWW_ROOT . _SERVER['PHP_SELF'])) {
return false;
}
_SERVER[‘PHP_SELF’] = ‘/’ . basename(FILE);
}
if (!defined(‘CAKE_CORE_INCLUDE_PATH’)) {
if (function_exists(‘ini_set’)) {
ini_set(‘include_path’, ROOT . DS . ‘lib’ . PATH_SEPARATOR . ini_get(‘include_path’));
}
if (!include ‘Cake’ . DS . ‘bootstrap.php’) {
$failed = true;
}
} elseif (!include CAKE_CORE_INCLUDE_PATH . DS . ‘Cake’ . DS . ‘bootstrap.php’) {
$failed = true;
}
if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . “vendors root directory.”, E_USER_ERROR);
}
App::uses(‘Dispatcher’, ‘Routing’);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest(),
new CakeResponse()
);
and i have 2 .htaccess location is:
—app:
.htaccess app
RewriteEngine on # Uncomment if you have a .well-known directory in the app folder, e.g. for the Let's Encrypt challenge # https://tools.ietf.org/html/rfc5785 #RewriteRule ^(\.well-known/.*)$ $1 [L] RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L]---------webroot:
.htaccess webroot
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] =and here is my nginx config:
nginx.conf
nginx
server {
listen 80;
server_name 35.247.162.90;
rewrite ^(.*) http://35.247.162.90$1 permanent;
}
server {
listen 80;
server_name 35.247.162.90;
# root directive should be global
root /var/www/html/KimServer/app/webroot;
index index.php;
access_log /usr/local/log/nginx/access.log;
error_log /usr/local/log/nginx/error.log;
location / {
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
location ~ \.php/ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
I dont know why my router is not work
Here is some line of my router:
router
Router::connect(’/’, array(‘controller’ => ‘pages’, ‘action’ => ‘display’, ‘home’));
Router::connect(’/api/statistic/statisticUser/*’, array(‘controller’ => ‘statistic’, ‘action’ => ‘statisticUser’));
CakePlugin::routes();
require CAKE . ‘Config’ . DS . ‘routes.php’;
I need some help to config nginx to work with cake php please give me some advice, thanks you