diff --git a/config/bootstrap.php b/config/bootstrap.php index a9ac650..71951bb 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -41,16 +41,19 @@ function handle_setup_exception(SetupException $e){ // Show error message and exit http_response_code(500); echo "
" . Util::escape_html($setupError['message']) . "
"; + echo "" . Util::escape_html($e->getSetupIssue) . '-' . Util::escape_html($e->getMessage()) . "
"; exit; case 'table_contents': // Recoverable error. // Redirect to setup if we aren't already headed there. - $config = ConfigModel::load(); + // NOTE: Just read directly from init.php instead of + // trying to use the config object. This is the initial + // setup. It shouldn't assume anything can be loaded. + $init = require APP_ROOT . '/config/init.php'; $currentPath = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if (strpos($currentPath, 'setup') === false) { - header('Location: ' . $config->basePath . 'setup'); + header('Location: ' . $init['base_path'] . 'setup'); exit; } } @@ -92,7 +95,7 @@ function validate_storage_subdirs(): void { foreach($storageSubdirs as $storageSubdir){ if (!is_dir($storageSubdir)) { - if (!mkdir($dir, 0770, true)) { + if (!mkdir($storageSubdir, 0770, true)) { throw new SetupException( "Failed to create required directory: $dir", 'directory_creation' diff --git a/examples/nginx/root/nginx.conf b/examples/nginx/root/nginx.conf index c134f66..74c65ba 100644 --- a/examples/nginx/root/nginx.conf +++ b/examples/nginx/root/nginx.conf @@ -37,7 +37,16 @@ server { # I've excluded /css/custom so that requests for uploaded css can be handled by the PHP app. # That lets me store uploaded content outside of the document root, # so it isn't served directly. - location ~* ^/(?!css/custom/).+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + + # CSS files - 1 hour cache + location ~* ^/(?!css/custom/).+\.css$ { + expires 1h; + add_header Cache-Control "public"; + try_files $uri =404; + } + + # Other static assets - 1 year cache + location ~* ^/.+\.(js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; diff --git a/examples/nginx/subfolder/nginx.conf b/examples/nginx/subfolder/nginx.conf index 249eb4b..8352289 100644 --- a/examples/nginx/subfolder/nginx.conf +++ b/examples/nginx/subfolder/nginx.conf @@ -42,7 +42,16 @@ server { # I've excluded /css/custom so that requests for uploaded css can be handled by the PHP app. # That lets me store uploaded content outside of the document root, # so it isn't served directly. - location ~* ^/tkr/(?!css/custom/).+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + + # CSS files - 1 hour cache + location ~* ^/tkr/(?!css/custom/).+\.css$ { + expires 1h; + add_header Cache-Control "public"; + try_files $uri =404; + } + + # Other static assets - 1 year cache + location ~* ^/tkr/.+\.(js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; diff --git a/public/index.php b/public/index.php index a179f03..8d94a57 100644 --- a/public/index.php +++ b/public/index.php @@ -15,10 +15,6 @@ if (preg_match('/\.php$/', $path)) { include_once(dirname(dirname(__FILE__)) . "/config/bootstrap.php"); load_classes(); -// initialize the database -global $db; -$db = get_db(); - // Make sure the initial setup is complete // unless we're already heading to setup if (!(preg_match('/setup$/', $path))) { @@ -30,6 +26,10 @@ if (!(preg_match('/setup$/', $path))) { } } +// initialize the database +global $db; +$db = get_db(); + // Everything's loaded and setup is confirmed. // Let's start ticking.