ADD: Статья «Настройка сервера»

This commit is contained in:
Evg 2022-04-03 09:37:38 +03:00
parent 67c286c185
commit 82545920da
7 changed files with 281 additions and 6 deletions

View File

@ -8,7 +8,6 @@
The `app` directory contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.
### The Config Directory
The `config` directory, as the name implies, contains all of your application's configuration files. It's a great idea to read through all of these files and familiarize yourself with all of the options available to you.
@ -17,8 +16,7 @@ The `config` directory, as the name implies, contains all of your application's
The `public` directory contains the `index.php` file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.
### Каталог (resources)
### The Resources Directory
The `resources` directory contains your site templates as well as raw, uncompiled assets like LESS, SASS.
@ -26,7 +24,6 @@ The `resources` directory contains your site templates as well as raw, uncompile
The `routes` directory contains all of the route definitions for your application. By default, several route files are included with LibArea: `main.php`, `admin.php` and `radjax.php`.
### The Storage Directory
The `storage` directory contains compiled templates, file-based sessions, file caches, error logs, and other files generated by the site.

View File

@ -0,0 +1,138 @@
# Configuring a Web Server
This article describes several ways to use LibArea with Apache or Nginx. When using Apache, you can set up PHP as an Apache module or with FastCGI using PHP FPM. FastCGI is also the preferred way to use PHP with Nginx.
## Публичный каталог (public)
The public directory (`/public`) is the home of all public and static files in your application, including images, style sheets, and JavaScript files. There is also `index.php`.
The `public` directory serves as the document root when setting up your web server. In the examples below, the `public/` directory will be the document root. This directory is `/var/www/project/public/`.
## Apache с mod_php/PHP-CGI
The minimum configuration to get your application running under Apache is:
```php
<VirtualHost *:80>
ServerName domain.ru
ServerAlias www.domain.ru
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
```
## Использование mod_php/PHP-CGI с Apache 2.4
In Apache 2.4, Order Allow,Deny has been replaced by Require all granted. Hence, you need to modify your Directory permission settings as follows:
```php
<Directory /var/www/project/public>
Require all granted
# ...
</Directory>
```
For advanced Apache configuration options, read the official [Apache documentation](https://httpd.apache.org/docs/).
## Nginx
The minimum configuration to get your application running under Nginx is:
```php
server {
server_name domain.ru www.domain.ru;
root /var/www/project/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
# optionally disable falling back to PHP script for the asset directories;
# nginx will return a 404 error when files are not found instead of passing the
# request to LibArea (improves performance but LibArea's 404 page is not displayed)
# location /bundles {
# try_files $uri =404;
# }
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# optionally set the value of the environment variables used in the application
# fastcgi_param APP_ENV prod;
# fastcgi_param APP_SECRET <app-secret-id>;
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
# Caveat: When PHP-FPM is hosted on a different machine from nginx
# $realpath_root may not resolve as you expect! In this case try using
# $document_root instead.
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.ru/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
```
For advanced Nginx configuration options, read the official *Nginx documentation*.
## Locally (XAMPP)
Configuration example for XAMPP, PHP 8.1.2, `httpd-xampp.conf`:
```php
<VirtualHost *:80>
ServerAdmin webmaster@lib.loc
DocumentRoot "d:/xampp/htdocs/lib.loc/public"
ServerName lib.loc
ServerAlias www.lib.loc
ErrorLog "d:/xampp/htdocs/lib.loc/error.log"
CustomLog "d:/xampp/htdocs/lib.loc/access.log"
<Directory "d:/xampp/htdocs/lib.loc/public">
Require all granted
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
```
Perhaps this was helpful...
—> [**Go to home page**](/en/)

View File

@ -16,5 +16,6 @@ GitHub: https://github.com/LibArea
* [Directory Structure](./structure)
* [Configuring a Web Server](./web-server-configuration)
*Documentation under development ...*

View File

@ -0,0 +1,136 @@
# Настройка веб-сервера
В этой статье описывается несколько способов использования LibArea с Apache или Nginx. При использовании Apache вы можете настроить PHP как модуль Apache или с FastCGI, используя PHP FPM . FastCGI также является предпочтительным способом использования PHP с Nginx.
## Публичный каталог (public)
Публичный каталог (`/public`) является домом для всех общедоступных и статических файлов вашего приложения, включая изображения, таблицы стилей и файлы JavaScript. Там же находится `index.php`.
`public` каталог служит корнем документа при настройке вашего веб-сервера. В приведенных ниже примерах `public/` каталог будет корнем документа. Этот каталог `/var/www/project/public/`.
## Apache с mod_php/PHP-CGI
Минимальная конфигурация для запуска вашего приложения под Apache:
```php
<VirtualHost *:80>
ServerName domain.ru
ServerAlias www.domain.ru
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
```
## Использование mod_php/PHP-CGI с Apache 2.4
В Apache 2.4 Order Allow,Denyбыл заменен на Require all granted. Следовательно, вам необходимо изменить Directoryнастройки разрешений следующим образом:
```php
<Directory /var/www/project/public>
Require all granted
# ...
</Directory>
```
Дополнительные параметры конфигурации Apache см. в официальной документации [Apache](https://httpd.apache.org/docs/).
## Nginx
Минимальная конфигурация для запуска вашего приложения под Nginx:
```php
server {
server_name domain.ru www.domain.ru;
root /var/www/project/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
# optionally disable falling back to PHP script for the asset directories;
# nginx will return a 404 error when files are not found instead of passing the
# request to LibArea (improves performance but LibArea's 404 page is not displayed)
# location /bundles {
# try_files $uri =404;
# }
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# optionally set the value of the environment variables used in the application
# fastcgi_param APP_ENV prod;
# fastcgi_param APP_SECRET <app-secret-id>;
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
# Caveat: When PHP-FPM is hosted on a different machine from nginx
# $realpath_root may not resolve as you expect! In this case try using
# $document_root instead.
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.ru/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
```
Дополнительные параметры конфигурации Nginx см. в *официальной документации Nginx*.
## Локально (XAMPP)
Пример конфигурации для XAMPP, PHP 8.1.2, `httpd-xampp.conf`:
```php
<VirtualHost *:80>
ServerAdmin webmaster@lib.loc
DocumentRoot "d:/xampp/htdocs/lib.loc/public"
ServerName lib.loc
ServerAlias www.lib.loc
ErrorLog "d:/xampp/htdocs/lib.loc/error.log"
CustomLog "d:/xampp/htdocs/lib.loc/access.log"
<Directory "d:/xampp/htdocs/lib.loc/public">
Require all granted
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
```
Возможно, это было полезно...
—> [**Перейти на главную страницу**](/ru/)

View File

@ -15,6 +15,8 @@ http://libarea.ru
* [Структура каталогов](./structure)
* [Настройка веб-сервера](./web-server-configuration)
* [Как добавить код счетчика Яндекс.Метрики?](./metrica)
На GitHub: https://github.com/LibArea

View File

@ -5,4 +5,5 @@ Route::get('/')->controller('HomeController', ['index']);
Route::get('/{lang}')->controller('ArticleController', ['welcome'])->name('welcome');
Route::get('/{lang}/philosophy')->controller('ArticleController', ['philosophy']);
Route::get('/{lang}/metrica')->controller('ArticleController', ['metrica']);
Route::get('/{lang}/structure')->controller('ArticleController', ['structure']);
Route::get('/{lang}/structure')->controller('ArticleController', ['structure']);
Route::get('/{lang}/web-server-configuration')->controller('ArticleController', ['web-server-configuration']);

View File

@ -178,7 +178,7 @@ error_reporting(E_ALL);
| Изначально: "/^[a-z0-9а-яё\_\-\/\.\@]+$/u"
|
*/
define( 'HLEB_PROJECT_VALIDITY_URL', "/^[a-z0-9а-яё\_\-\/\.\@]+$/u" );
define( 'HLEB_PROJECT_VALIDITY_URL', "/^[a-z0-9\_\-\/\.\@]+$/u" );