Reflect index.php change in server install docs

This commit is contained in:
Ingo Schommer 2017-10-04 11:17:41 +01:00 committed by Damian Mooyman
parent 4a94dfe55b
commit cea5cd1c3e
8 changed files with 40 additions and 115 deletions

View File

@ -62,7 +62,9 @@ control.
3. Apache rewrite (mod_rewrite) isn't working and it's installed (prior to SilverStripe 3.1.11)
Due to some changes to `mod_dir` in [Apache 2.4](http://httpd.apache.org/docs/current/mod/mod_dir.html#DirectoryCheckHandler) (precedence of handlers), index.php gets added to the URLs as soon as you navigate to the homepage of your site. Further requests are then handled by index.php rather than `mod_rewrite` (`main.php`). To fix this place the following within the `mod_rewrite` section of your .htaccess file:
Due to some changes to `mod_dir` in [Apache 2.4](http://httpd.apache.org/docs/current/mod/mod_dir.html#DirectoryCheckHandler) (precedence of handlers),
index.php gets added to the URLs as soon as you navigate to the homepage of your site.
To fix this place the following within the `mod_rewrite` section of your .htaccess file:
```
<IfModule mod_rewrite.c>

View File

@ -24,7 +24,6 @@ On "live" environments, the `?isDev=1` solution is preferred, as it means that y
Due to some changes to `mod_dir` in [Apache 2.4](http://httpd.apache.org/docs/current/mod/mod_dir.html#DirectoryCheckHandler)
(precedence of handlers), index.php gets added to the URLs as soon as you navigate to the homepage of your site.
Further requests are then handled by index.php rather than `mod_rewrite` (`main.php`).
To fix this place the following within the `mod_rewrite` section of your .htaccess file:
```

View File

@ -27,11 +27,11 @@ Silverstripe. Replace "yoursite.com" and "/home/yoursite/public_html/" below.
# Rewrite URLs so they are nicer
url.rewrite-once = (
"^/.*\.[A-Za-z0-9]+.*?$" => "$0",
"^/(.*?)(\?|$)(.*)" => "/vendor/silverstripe/framework/main.php?url=$1&$3"
"^/(.*?)(\?|$)(.*)" => "/index.php?$3"
)
# Show SilverStripe error page
server.error-handler-404 = "/vendor/silverstripe/framework/main.php"
server.error-handler-404 = "/index.php"
}
@ -53,14 +53,14 @@ of Silverstripe on the same host, you can use something like this (be warned, it
url.rewrite-once = (
"(?i)(/copy1/.*\.([A-Za-z0-9]+))(.*?)$" => "$0",
"(?i)(/copy2/.*\.([A-Za-z0-9]+))(.*?)$" => "$0",
"^/copy1/(.*?)(\?|$)(.*)" => "/copy1/vendor/silverstripe/framework/main.php?url=$1&$3",
"^/copy2/(.*?)(\?|$)(.*)" => "/copy2/vendor/silverstripe/framework/main.php?url=$1&$3"
"^/copy1/(.*?)(\?|$)(.*)" => "/copy1/index.php?$3",
"^/copy2/(.*?)(\?|$)(.*)" => "/copy2/index.php?$3"
)
$HTTP["url"] =~ "^/copy1/" {
server.error-handler-404 = "/copy1/vendor/silverstripe/framework/main.php"
server.error-handler-404 = "/copy1/index.php"
}
$HTTP["url"] =~ "^/copy2/" {
server.error-handler-404 = "/copy2/vendor/silverstripe/framework/main.php"
server.error-handler-404 = "/copy2/index.php"
}
}

View File

@ -30,7 +30,7 @@ But enough of the disclaimer, on to the actual configuration — typically in `n
}
location / {
try_files $uri vendor/silverstripe/framework/main.php?url=$uri&$query_string;
try_files $uri index.php?$query_string;
}
error_page 404 /assets/error-404.html;
@ -41,7 +41,7 @@ But enough of the disclaimer, on to the actual configuration — typically in `n
deny all;
}
sendfile on;
try_files $uri vendor/silverstripe/framework/main.php?url=$uri&$query_string;
try_files $uri index.php?$query_string;
}
location ~ /framework/.*(main|rpc|tiny_mce_gzip)\.php$ {

View File

@ -48,7 +48,7 @@ Create `/etc/nginx/silverstripe.conf` and add this configuration:
fastcgi_buffers 4 32k;
location / {
try_files $uri /vendor/silverstripe/framework/main.php?url=$uri&$query_string;
try_files $uri /index.php?$query_string;
}
error_page 404 /assets/error-404.html;
@ -87,7 +87,7 @@ Create `/etc/nginx/silverstripe.conf` and add this configuration:
deny all;
}
The above script passes all non-static file requests to `/framework/main.php` in the webroot which relies on
The above script passes all non-static file requests to `/index.php` in the webroot which relies on
`hhvm.conf` being included prior so that php requests are handled.
Now in your nginx `server` configuration you can then include the `hhvm.conf` and `silverstripe.conf` files

View File

@ -362,7 +362,7 @@ bypasses PHP requests for files that do exist. The default template
# Non existant files passed to requesthandler
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../vendor/silverstripe/framework/main.php?url=%1 [QSA]
RewriteRule .* ../index.php [QSA]
```
You will need to ensure that your core apache configuration has the necessary `AllowOverride`
@ -381,9 +381,9 @@ The default rule for IIS is as below (only partial configuration displayed):
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="../vendor/silverstripe/framework/main.php" matchType="IsFile" />
<add input="../index.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="../vendor/silverstripe/framework/main.php?url={R:1}" appendQueryString="true" />
<action type="Rewrite" url="../index.php" appendQueryString="true" />
</rule>
```
@ -402,6 +402,6 @@ dynamic requests are processed via the Framework:
```
location ^~ /assets/ {
sendfile on;
try_files $uri vendor/silverstripe/framework/main.php?url=$uri&$query_string;
try_files $uri index.php?$query_string;
}
```

View File

@ -65,56 +65,29 @@ The role of the application is to:
The HTTPApplication provides a specialised application implementation for handling HTTP Requests.
This class provides basic support for HTTP Middleware, such as [ErrorControlChainMiddleware](api:SilverStripe\Core\Startup\ErrorControlChainMiddleware).
`main.php` contains the default application implementation.
The `index.php` file in your project root contains the default application implementation.
You can customise it as required.
```php
use SilverStripe\Control\HTTPApplication;
use SilverStripe\Control\HTTPRequestBuilder;
use SilverStripe\Core\CoreKernel;
use SilverStripe\Core\Startup\ErrorControlChainMiddleware;
require __DIR__ . '/src/includes/autoload.php';
// Build request and detect flush
$request = HTTPRequestBuilder::createFromEnvironment();
// Default application
$kernel = new CoreKernel(BASE_PATH);
$app = new HTTPApplication($kernel);
$app->addMiddleware(new ErrorControlChainMiddleware($app));
$response = $app->handle($request);
$response->output();
```
<?php
Users can customise their own application by coping the above to a file in `mysite/main.php`, and
updating their `.htaccess` to point to the new file.
use SilverStripe\Control\HTTPApplication;
use SilverStripe\Control\HTTPRequestBuilder;
use SilverStripe\Core\CoreKernel;
use SilverStripe\Core\Startup\ErrorControlChainMiddleware;
:::
<IfModule mod_rewrite.c>
# ...
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* mysite/main.php?url=%1 [QSA]
# ...
</IfModule>
require __DIR__ . '/vendor/autoload.php';
// Build request and detect flush
$request = HTTPRequestBuilder::createFromEnvironment();
Note: This config must also be duplicated in the below template which provide asset routing:
`silverstripe-assets/templates/SilverStripe/Assets/Flysystem/PublicAssetAdapter_HTAccess.ss`:
```ss
<IfModule mod_rewrite.c>
# ...
# Non existant files passed to requesthandler
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../mysite/main.php?url=%1 [QSA]
</IfModule>
// Default application
$kernel = new CoreKernel(BASE_PATH);
$app = new HTTPApplication($kernel);
$app->addMiddleware(new ErrorControlChainMiddleware($app));
$response = $app->handle($request);
$response->output();
```
## Custom application actions

View File

@ -18,58 +18,10 @@ Check our [installation guides](/getting_started/installation) on how other web
The standard SilverStripe project ships with a `.htaccess` file in your webroot for this purpose.
By default, requests will be passed through for files existing on the filesystem.
Some access control is in place to deny access to potentially sensitive files in the webroot, such as YAML configuration files.
If no file can be directly matched, control is handed off to `framework/main.php`.
If no file can be directly matched, control is handed off to `index.php`.
### SILVERSTRIPE START ###
# Deny access to templates (but allow from localhost)
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
# Deny access to IIS configuration
<Files web.config>
Order deny,allow
Deny from all
</Files>
# Deny access to YAML configuration files which might include sensitive information
<Files ~ "\.ya?ml$">
Order allow,deny
Deny from all
</Files>
# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
# Non existant files passed to requesthandler
# Try finding the module in the vendor folder first
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../vendor/silverstripe/framework/main.php?url=%1 [QSA]
# If requesting the main script directly, rewrite to the installer
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
</IfModule>
### SILVERSTRIPE END ###
SilverStripe can also operate without this level of rewriting, in which case all dynamic requests go
through an `index.php` script in the webroot.
SilverStripe can also operate without this level of rewriting, in which case
you'll have `index.php` as part of the URL.
<div class="notice" markdown="1">
Running SilverStripe without web server based rewriting is not recommended since it
@ -86,7 +38,7 @@ tasks silently in the background.
[configuration file](/getting_started/environment_management) in the webroot.
* Sets constants based on the filesystem structure (e.g. `BASE_URL`, `BASE_PATH` and `TEMP_PATH`)
All requests go through `main.php`, which sets up the core [Kernel](api:SilverStripe\Core\Kernel) and [HTTPApplication](api:SilverStripe\Control\HTTPApplication)
All requests go through `index.php`, which sets up the core [Kernel](api:SilverStripe\Core\Kernel) and [HTTPApplication](api:SilverStripe\Control\HTTPApplication)
objects. See [/developer_guides/execution_pipeline/app_object_and_kernel] for details on this.
The main process follows:
@ -101,13 +53,12 @@ The main process follows:
While you usually don't need to modify the bootstrap on this level, some deeper customizations like
adding your own manifests or a performance-optimized routing might require it.
An example of this can be found in the ["staticpublisher" module](https://github.com/silverstripe-labs/silverstripe-staticpublisher/blob/master/main.php).
The modules instructs web servers to route through its own `main.php` to determine which requests can be cached
before handing control off to SilverStripe's own `main.php`.
An example of this can be found in the ["staticpublisher" module](https://github.com/silverstripe-labs/silverstripe-staticpublisher/).
## Routing and Request Handling
The `main.php` script relies on [Director](api:SilverStripe\Control\Director) to work out which [controller](../controllers/) should handle this request. It parses the URL, matching it to one of a number of patterns,
The `index.php` script relies on [Director](api:SilverStripe\Control\Director) to work out which [controller](../controllers/)
should handle this request. It parses the URL, matching it to one of a number of patterns,
and determines the controller, action and any argument to be used ([Routing](../controllers/routing)).
* Creates a [HTTPRequest](api:SilverStripe\Control\HTTPRequest) object containing all request and environment information