Web-server на базе Nginx, php5-fpm, mysql на Debian Wheezy — различия между версиями
Root (обсуждение | вклад) |
Root (обсуждение | вклад) |
||
Строка 6: | Строка 6: | ||
− | /etc/apt/sources.list | + | '''/etc/apt/sources.list''' |
deb http://nginx.org/packages/debian wheezy nginx | deb http://nginx.org/packages/debian wheezy nginx | ||
deb-src http://nginx.org/packages/debian wheezy nginx | deb-src http://nginx.org/packages/debian wheezy nginx | ||
Строка 27: | Строка 27: | ||
− | + | Правим конфиги | |
− | |||
+ | '''/etc/php5/fpm/conf.d/custom.ini''' | ||
+ | date.timezone = "Europe/Moscow" | ||
+ | display_errors = Off | ||
+ | log_errors = On | ||
+ | display_startup_errors = Off | ||
+ | error_log = /var/log/php5/php5-errors.log | ||
+ | error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT | ||
+ | upload_max_filesize = 1024M | ||
+ | memory_limit = 512M | ||
+ | max_execution_time = 360 | ||
+ | max_file_uploads = 64 | ||
+ | max_input_time = 360 | ||
+ | cgi.fix_pathinfo = 0 | ||
+ | post_max_size = 512M | ||
+ | max_input_vars = 65535 | ||
+ | max_input_nesting_level = 128 | ||
− | |||
− | |||
− | |||
+ | '''/etc/php5/fpm/pool.d/site.conf''' | ||
+ | [site] | ||
+ | prefix = /srv/www/$pool | ||
+ | listen = 127.0.0.1:10001 | ||
+ | listen.allowed_clients = 127.0.0.1 | ||
+ | listen.owner = www-data | ||
+ | listen.group = www-data | ||
+ | listen.mode = 0660 | ||
+ | user = www-data | ||
+ | group = www-data | ||
+ | pm = dynamic | ||
+ | pm.max_children = 35 | ||
+ | pm.start_servers = 5 | ||
+ | pm.min_spare_servers = 2 | ||
+ | pm.min_spare_servers = 2 | ||
+ | pm.max_spare_servers = 8 | ||
+ | pm.max_requests = 1000 | ||
+ | pm.status_path = /status/php-fpm/$pool | ||
+ | request_terminate_timeout = 0 | ||
+ | request_slowlog_timeout = 2m | ||
+ | slowlog = /var/log/php5/$pool.slow.log | ||
− | |||
+ | Ставим nginx | ||
+ | # aptitude install nginx | ||
+ | Создаём директорию для сайта и даём права | ||
+ | # /srv/www/site | ||
+ | # chown -R www-data:www-data /srv/www/site | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | Правим конфиги (сам nginx начинает читать файл '''/etc/nginx/nginx.conf''', все остальные подключаются директивой include. ) | ||
− | ''' | + | '''/etc/nginx/nginx.conf''' |
− | + | user www-data; | |
− | + | worker_processes 4; | |
− | + | error_log /var/log/nginx/error.log; | |
− | |||
− | user | ||
− | |||
− | worker_processes | ||
− | |||
pid /var/run/nginx.pid; | pid /var/run/nginx.pid; | ||
− | |||
− | |||
events { | events { | ||
− | + | worker_connections 1024; | |
} | } | ||
http { | http { | ||
− | + | access_log /var/log/nginx/access.log; | |
− | + | include /etc/nginx/mime.types; | |
− | + | default_type application/octet-stream; | |
− | + | sendfile on; | |
− | + | tcp_nopush on; | |
− | + | tcp_nodelay on; | |
− | + | keepalive_timeout 65; | |
− | + | gzip on; | |
− | + | gzip_http_version 1.0; | |
− | + | gzip_comp_level 2; | |
− | + | gzip_proxied any; | |
− | + | gzip_vary off; | |
− | + | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml; | |
− | + | gzip_min_length 1000; | |
− | + | gzip_disable "MSIE [1-6]."; | |
− | + | client_max_body_size 10m; | |
− | + | server_names_hash_bucket_size 64; | |
− | + | types_hash_max_size 2048; | |
− | + | types_hash_bucket_size 64; | |
+ | include /etc/nginx/conf.d/*.conf; | ||
} | } | ||
− | + | Теперь конфиг проекта | |
+ | '''/etc/nginx/conf.d/site.conf''' | ||
server { | server { | ||
− | + | listen 80; | |
− | + | server_name site.ru; | |
− | + | root /srv/www/site; | |
− | + | index index.php index.html index.htm; | |
− | + | access_log /var/log/nginx/racks.access.log; | |
− | + | error_log /var/log/nginx/racks.error.log; | |
− | + | location ~ \.php$ { | |
− | + | root /srv/www/site; | |
− | + | fastcgi_pass 127.0.0.1:10001; | |
− | + | fastcgi_index index.php; | |
− | + | fastcgi_param SCRIPT_FILENAME /srv/www/site/$fastcgi_script_name; | |
− | + | include fastcgi_params; | |
− | + | fastcgi_intercept_errors on; | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Версия 21:08, 27 февраля 2014
Добавляем ключи и репозитории
# wget http://nginx.org/keys/nginx_signing.key # apt-key add nginx_signing.key # apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
/etc/apt/sources.list
deb http://nginx.org/packages/debian wheezy nginx deb-src http://nginx.org/packages/debian wheezy nginx deb http://repo.percona.com/apt wheezy main deb http://packages.dotdeb.org squeeze all deb-src http://packages.dotdeb.org squeeze all
Обновляемся
# aptitude update
Ставим php и модули(по мере надобности)
# aptitude install php5-fpm php5-cli php5-common php5-mysql php5-dev php5-gd php5-curl php5-mcrypt php5-xdebug php-pear
Создаём папки
# mkdir /var/log/php5 # mkdir /srv/www
Правим конфиги
/etc/php5/fpm/conf.d/custom.ini
date.timezone = "Europe/Moscow" display_errors = Off log_errors = On display_startup_errors = Off error_log = /var/log/php5/php5-errors.log error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT upload_max_filesize = 1024M memory_limit = 512M max_execution_time = 360 max_file_uploads = 64 max_input_time = 360 cgi.fix_pathinfo = 0 post_max_size = 512M max_input_vars = 65535 max_input_nesting_level = 128
/etc/php5/fpm/pool.d/site.conf
[site] prefix = /srv/www/$pool listen = 127.0.0.1:10001 listen.allowed_clients = 127.0.0.1 listen.owner = www-data listen.group = www-data listen.mode = 0660 user = www-data group = www-data pm = dynamic pm.max_children = 35 pm.start_servers = 5 pm.min_spare_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 8 pm.max_requests = 1000 pm.status_path = /status/php-fpm/$pool request_terminate_timeout = 0 request_slowlog_timeout = 2m slowlog = /var/log/php5/$pool.slow.log
Ставим nginx
# aptitude install nginx
Создаём директорию для сайта и даём права
# /srv/www/site # chown -R www-data:www-data /srv/www/site
Правим конфиги (сам nginx начинает читать файл /etc/nginx/nginx.conf, все остальные подключаются директивой include. )
/etc/nginx/nginx.conf
user www-data; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { access_log /var/log/nginx/access.log; include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; gzip on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_vary off; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml; gzip_min_length 1000; gzip_disable "MSIE [1-6]."; client_max_body_size 10m; server_names_hash_bucket_size 64; types_hash_max_size 2048; types_hash_bucket_size 64; include /etc/nginx/conf.d/*.conf; }
Теперь конфиг проекта
/etc/nginx/conf.d/site.conf
server { listen 80; server_name site.ru; root /srv/www/site; index index.php index.html index.htm; access_log /var/log/nginx/racks.access.log; error_log /var/log/nginx/racks.error.log; location ~ \.php$ { root /srv/www/site; fastcgi_pass 127.0.0.1:10001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/site/$fastcgi_script_name; include fastcgi_params; fastcgi_intercept_errors on; } }
Стандартным способом проверяем работоспособность php
<?php phpinfo(); ?>
Отключаем уязвимость: http://forum.antichat.ru/thread222063-php-fpm.html
прописываем в /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
Если все работает, то на этом этапе мы имеем рабочий web-сервер с поддержкой php.
Далее плюшки