This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
<IfVersion < 2.4>
order allow,deny
deny from all
</IfVersion>
<IfVersion >= 2.4>
Require all denied
</IfVersion>
+62
View File
@@ -0,0 +1,62 @@
# PHP Built-in webserver
PHP has had a [built-in web sever](https://secure.php.net/manual/en/features.commandline.webserver.php) since version 5.4.
PHP's web server provides a router script for use with server rewrites. Magento, like many other applications and frameworks, requires server rewrites. The router script either:
- The web server executes the requested PHP script using a server-side include
- Returns `false`, which means the web server returns the file using file system lookup
Example:
requests to `/static/frontend/Magento/blank/en_US/mage/calendar.css` should deliver the file if it exists, or execute `/static.php` if not.
Without a router script, that is not possible via the php built-in server.
## How to install Magento
Please read how to install Magento using the [command line](https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/advanced.html). An example follows:
```php
php bin/magento setup:install --base-url=http://127.0.0.1:8082 \
--db-host=localhost --db-name=magento --db-user=magento --db-password=magento \
--admin-firstname=Magento --admin-lastname=User --admin-email=user@example.com \
--admin-user=admin --admin-password=admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--search-engine=elasticsearch7 --elasticsearch-host=es-host.example.com --elasticsearch-port=9200
```
Note: By default, Magento creates a random Admin URI for you. Make sure to write this value down because it's how you access the Magento Admin later. For example: `http://127.0.0.1:8082/index.php/admin_1vpn01`.
For more information about the installation process using the CLI, you can consult the dedicated documentation that can found in [the developer documentation](https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/composer.html).
### How to run Magento
Example usage:
```shell
php -S 127.0.0.1:8082 -t ./pub/ ./phpserver/router.php
```
### What exactly the script does
The `$debug` option provides low-level logging for debugging purposes.
Forwarding rules:
- Any request for `favicon.ico` or for any path that starts with `index.php`, `get.php`, `static.php` are processed normally.
- Requests for the path `pub/errors/default` are rewritten as `errors/default`. This is provided for compatibility with older versions.
- Files under request paths `media`, `opt`, or `static` are tested; if the file exists, the file is served. If the file does not exist, `static` files are forwarded to `static.php` and `media` files are forwarded to `get.php` ((How about `opt`?))
- If no rules are matched, return a 404 (Not Found).
Then rewrite paths for `pub/errors/default/` by removing the `pub/` part. (was at least needed for older versions)
Request starting with `media/`, `opt/`, `static/` test if the file exists. If Yes, then handle it, if not "forward" `static` to `static.php` and `media` to `get.php`
If none of the rules matched, return 404. You may instead include the index.php, if 404 should be handled by Magento or you want urls without `index.php/`.
### How to access to the admin dashboard
When the installation is finished, you can access Magento as follows:
- Storefront: `<your Magento base URL>`
- Magento Admin: `<your Magento base URL>/<admin URI>`
+121
View File
@@ -0,0 +1,121 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* this is a router file for the php Built-in web server
* https://secure.php.net/manual/en/features.commandline.webserver.php
*
* It provides the same "rewrites" as the .htaccess for apache,
* or the nginx.conf.sample for nginx.
*
* example usage: php -S 127.0.0.41:8082 -t ./pub/ ./router.php
*/
/**
* Set it to true to enable debug mode
*/
define('DEBUG_ROUTER', false);
$debug = function ($val) {
if (!DEBUG_ROUTER) {
return;
}
if (is_array($val)) {
$val = json_encode($val);
}
error_log('debug: '.$val);
};
/**
* Caution, this is very experimental stuff
* no guarantee for working result
* has tons of potential big security holes
*/
if (php_sapi_name() === 'cli-server') {
$debug("URI: {$_SERVER["REQUEST_URI"]}");
if (preg_match('/^\/(index|get|static)\.php(\/)?/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is.
}
$path = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$url = pathinfo(substr($_SERVER["REQUEST_URI"], 1));
$route = parse_url(substr($_SERVER["REQUEST_URI"], 1))["path"];
$pathinfo = pathinfo($route);
$ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
if ($path["basename"] == 'favicon.ico') {
return false;
}
$debug("route: $route");
if (strpos($route, 'pub/errors/default/') === 0) {
$route = preg_replace('#pub/errors/default/#', 'errors/default/', $route, 1);
}
$magentoPackagePubDir = __DIR__."/../pub";
if (strpos($route, 'media/') === 0 ||
strpos($route, 'opt/') === 0 ||
strpos($route, 'static/') === 0 ||
strpos($route, 'errors/default/css/') === 0 ||
strpos($route, 'errors/default/images/') === 0
) {
$origFile = $magentoPackagePubDir.'/'.$route;
if (strpos($route, 'static/version') === 0) {
$route = preg_replace('#static/(version\d+/)?#', 'static/', $route, 1);
}
$file = $magentoPackagePubDir.'/'.$route;
$debug("file: $file");
if (file_exists($origFile) || file_exists($file)) {
if (file_exists($origFile)) {
$file = $origFile;
}
$debug('file exists');
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'jpg' => 'image/jpg',
'png' => 'image/png',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'map' => 'application/json',
'woff' => 'application/x-woff',
'woff2' => 'application/font-woff2',
'html' => 'text/html',
];
if (isset($mimeTypes[$ext])) {
header("Content-Type: $mimeTypes[$ext]");
}
readfile($file);
return;
} else {
$debug('file does not exist');
if (strpos($route, 'static/') === 0) {
$route = preg_replace('#static/#', '', $route, 1);
$_GET['resource'] = $route;
$debug("static: $route");
include($magentoPackagePubDir.'/static.php');
exit;
} elseif (strpos($route, 'media/') === 0) {
$debug("media: $route");
include($magentoPackagePubDir.'/get.php');
exit;
}
}
} else {
$debug("thunk to index in $route");
include($magentoPackagePubDir.'/index.php');
}
}