- Локальный веб-сервер под Linux, с автоматическим поднятием хостов и переключением версий PHP
- kgriffs / sysctl.conf
- This comment has been minimized.
- tunnckoCore commented Mar 29, 2014
- This comment has been minimized.
- kgriffs commented May 1, 2014
- This comment has been minimized.
- hrchu commented Jan 30, 2016
- This comment has been minimized.
- hrchu commented Jan 30, 2016
- This comment has been minimized.
- Namsep commented Feb 18, 2016
- This comment has been minimized.
- jensk commented Aug 14, 2020
- hrchu / 99-network-tuning.conf
- This comment has been minimized.
- IgorOhrimenko commented Feb 21, 2019
Локальный веб-сервер под Linux, с автоматическим поднятием хостов и переключением версий PHP
Скорее всего какие-то части этой статьи уже знакомы многим хаброжителям, но в связи с покупкой нового рабочего ноутбука я решил собрать все крупинки воедино и организовать удобное средство для разработки. Мне часто приходится работать со множеством маленьких проектов, с разными версиями PHP, часто переводить старые проекты на новые версии. В далёком прошлом, когда я был пользователем Windows то использовал OpenServer. Но с переходом на Linux мне нехватало той простоты создания хостов и переключений версий которые были в нём. Поэтому пришлось сделать еще более удобное решение на Linux =)
будет запущен тот же файл но уже с версией PHP 7.2.7
Другие версии доставляются аналогичным описанным ниже способом.
Для создания еще одного сайта просто создаем в /var/www/ папку имеющую окончание .loc, внутри которой должна быть папка public_html являющаяся корнем сайта
Вот собственно и все. Как без дополнительных мучений, перезапусков, и редактирований конфигов имеем автоматическую систему для работы с сайтами.
Всё это я проверну на LinuxMint19, он на базе Ubuntu18.04, так что с ним все будет аналогично.
Для начала поставим необходимые пакеты
Postfix ставим в качестве плюшки, как простое решение(в мастере установки, всё по умолчанию выбираем) для отправки почты с локальной машины.
Так как это локальная разработка и я единственный пользователь. То мне удобней перенести папку с проектами в мою домашнюю дерикторию. Она у меня маунтится отдельным диском и мигрирует при переустановке системы. Самый простой способ это создать ссылку, тогда не нужно менять пути в настройках да и путь привычный для всех.
Скопируем папку созданную апачем в домашний каталог, создадим на ее месте ссылку, не забыв поменять пользователя на себя и обменяться группами с апачем.
Создадим папку в которой будем собирать исходники PHP для разных версий
Также нам понадобится папки для CGI скриптов
И runtime папка для этих же скриптов, с правами
И так как каталог у нас находится в оперативной памяти, добавим его создание при старте системы, для этого добавим в /etc/tmpfiles.d/fcgid.conf
У меня dnsmasq-base идет с коробки, если нет то его всегда можно доставить.
Добавим правило в его конфигурацию. Найти файл конфигурации dnsmasq.conf можно так
Либо если он как и у меня является частью NetworkManager то создать новый файл конфигурации в /etc/NetworkManager/dnsmasq.d/local.conf
Добавим в него строчку для перенаправление нашего локального домена на локальную машину.
Также нужно включить необходимые модули апача
Предварительная подготовка завершена, приступаем к сборке различных локальных версий PHP. Для каждой версии PHP проделываем следующие 4 шага. На примере 5.6.36
1. Скачиваем исходники нужной версии и распаковываем их
2. Cобираем из исходников нужную версию PHP, и помещаем ее в /opt/php-5.6.36
3. Создаем CGI для обработки этой версии в /var/www/cgi-bin/php-5.6.36.fcgi
4. Делаем файл исполняемым
5. Добавляем экшен для обработки каждой версии в /etc/apache2/mods-available/fcgid.conf
6. Добавляем правило для обработки каждой версии в /etc/apache2/sites-available/000-default.conf
Ну вот и всё. Осталось только перезапустить apache и dnsmasq и пользоваться
Источник
kgriffs / sysctl.conf
# Configuration file for runtime kernel parameters. |
# See sysctl.conf(5) for more information. |
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for |
# an explanation about some of these parameters, and instructions for |
# a few other tweaks outside this file. |
# |
# See also: https://gist.github.com/kgriffs/4027835 |
# |
# Assumes a beefy machine with lots of network bandwidth |
# Protection from SYN flood attack. |
net.ipv4.tcp_syncookies = 1 |
# See evil packets in your logs. |
net.ipv4.conf.all.log_martians = 1 |
# Enable source validation by reversed path, as specified in RFC1812 |
net.ipv4.conf.all.rp_filter = 1 |
# Ignore all ICMP ECHO and TIMESTAMP requests sent to it via broadcast/multicast |
net.ipv4.icmp_echo_ignore_broadcasts = 1 |
net.ipv4.icmp_ignore_bogus_error_responses = 1 |
# Discourage Linux from swapping idle server processes to disk (default = 60) |
vm.swappiness = 1 |
# Be less aggressive about reclaiming cached directory and inode objects |
# in order to improve filesystem performance. |
vm.vfs_cache_pressure = 50 |
# Tweak how the flow of kernel messages is throttled. |
#kernel.printk_ratelimit_burst = 10 |
#kernel.printk_ratelimit = 5 |
# ——————————————————————— |
# The following allow the server to handle lots of connection requests |
# ——————————————————————— |
# Increase number of incoming connections that can queue up |
# before dropping |
net.core.somaxconn = 5000 |
# Handle SYN floods and large numbers of valid HTTPS connections |
net.ipv4.tcp_max_syn_backlog = 3000 |
# Increase the length of the network device input queue |
net.core.netdev_max_backlog = 5000 |
# Increase system file descriptor limit so we will (probably) |
# never run out under lots of concurrent requests. |
# (Per-process limit is set in /etc/security/limits.conf) |
fs.file-max = 184028 |
# Widen the port range used for outgoing connections |
net.ipv4.ip_local_port_range = 10000 65000 |
# If your servers talk UDP, also up these limits |
#net.ipv4.udp_rmem_min = 8192 |
#net.ipv4.udp_wmem_min = 8192 |
# ——————————————————————— |
# The following help the server efficiently pipe large amounts of data |
# ——————————————————————— |
# Disable source routing and redirects |
net.ipv4.conf.all.send_redirects = 0 |
net.ipv4.conf.all.accept_redirects = 0 |
net.ipv4.conf.all.accept_source_route = 0 |
net.ipv4.conf.all.secure_redirects = 0 |
# Disable packet forwarding. |
net.ipv4.ip_forward = 0 |
net.ipv6.conf.all.forwarding = 0 |
# Disable TCP slow start on idle connections |
net.ipv4.tcp_slow_start_after_idle = 0 |
# Increase Linux autotuning TCP buffer limits |
# Set max to 16MB for 1GE and 32M (33554432) or 54M (56623104) for 10GE |
# Don’t set tcp_mem itself! Let the kernel scale it based on RAM. |
net.core.rmem_max = 16777216 |
net.core.wmem_max = 16777216 |
net.core.rmem_default = 16777216 |
net.core.wmem_default = 16777216 |
net.core.optmem_max = 40960 |
net.ipv4.tcp_rmem = 4096 87380 16777216 |
net.ipv4.tcp_wmem = 4096 65536 16777216 |
# Enable BBR; requires Linux kernel version 4.9 or higher |
net.core.default_qdisc=fq |
net.ipv4.tcp_congestion_control=bbr |
# ——————————————————————— |
# The following allow the server to handle lots of connection churn |
# ——————————————————————— |
# Disconnect dead TCP connections after 1 minute |
net.ipv4.tcp_keepalive_time = 60 |
# Wait a maximum of 5 * 2 = 10 seconds in the TIME_WAIT state after a FIN, to handle |
# any remaining packets in the network. |
# net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 5 |
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 5 |
# Allow a high number of timewait sockets |
net.ipv4.tcp_max_tw_buckets = 40960 |
# Timeout broken connections faster (amount of time to wait for FIN) |
net.ipv4.tcp_fin_timeout = 10 |
# Let the networking stack reuse TIME_WAIT connections when it thinks it’s safe to do so |
net.ipv4.tcp_tw_reuse = 1 |
# Determines the wait time between isAlive interval probes (reduce from 75 sec to 15) |
net.ipv4.tcp_keepalive_intvl = 15 |
# Determines the number of probes before timing out (reduce from 9 sec to 5 sec) |
net.ipv4.tcp_keepalive_probes = 5 |
# ——————————————————————— |
# The following optimize connection setup |
# ——————————————————————— |
net.ipv4.tcp_fastopen = 3 |
This comment has been minimized.
Copy link Quote reply
tunnckoCore commented Mar 29, 2014
For what machine stats is that? RAM / Cores? 🙂
This comment has been minimized.
Copy link Quote reply
kgriffs commented May 1, 2014
The performance-oriented settings assume your box is capable of serving enough traffic to hit up against the defaults, so they are not going to be terribly useful unless you have, say, 4 or more cores and 4 GB or more RAM, plus enough network bandwidth to drive a heavy load.
This comment has been minimized.
Copy link Quote reply
hrchu commented Jan 30, 2016
Some articles describe the disadvantages of net.ipv4.tcp_syncookies. I think that only public servers need it . http://serverfault.com/questions/705504/better-alternative-for-tcp-syncookies-in-linux
This comment has been minimized.
Copy link Quote reply
hrchu commented Jan 30, 2016
Ubuntu 10.04 has default «sysctl.d/10-network-security.conf» setting below:
This comment has been minimized.
Copy link Quote reply
Namsep commented Feb 18, 2016
What about slow start (IPv6)and initcwnd for IPv4 and IPv6?
This comment has been minimized.
Copy link Quote reply
jensk commented Aug 14, 2020
be careful with these settings
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
hrchu / 99-network-tuning.conf
# Configuration file for runtime kernel parameters. |
# See sysctl.conf(5) for more information. |
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for |
# an explanation about some of these parameters, and instructions for |
# a few other tweaks outside this file. |
# See evil packets in your logs. |
net.ipv4.conf.all.log_martians = 1 |
# Discourage Linux from swapping idle server processes to disk (default = 60) |
vm.swappiness = 10 |
# Tweak how the flow of kernel messages is throttled. |
#kernel.printk_ratelimit_burst = 10 |
#kernel.printk_ratelimit = 5 |
# ——————————————————————— |
# The following allow the server to handle lots of connection requests |
# ——————————————————————— |
# Increase number of incoming connections that can queue up |
# before dropping |
net.core.somaxconn = 50000 |
# Handle SYN floods and large numbers of valid HTTPS connections |
net.ipv4.tcp_max_syn_backlog = 30000 |
# Increase the length of the network device input queue |
net.core.netdev_max_backlog = 5000 |
# Increase system file descriptor limit so we will (probably) |
# never run out under lots of concurrent requests. |
# (Per-process limit is set in /etc/security/limits.conf) |
fs.file-max = 100000 |
# Widen the port range used for outgoing connections |
#net.ipv4.ip_local_port_range = 10000 65000 |
# I have daemon run on 120XX, so let range start from 13000 |
net.ipv4.ip_local_port_range = 13000 65000 |
# If your servers talk UDP, also up these limits |
net.ipv4.udp_rmem_min = 8192 |
net.ipv4.udp_wmem_min = 8192 |
# ——————————————————————— |
# The following help the server efficiently pipe large amounts of data |
# ——————————————————————— |
# Disable source routing and redirects |
net.ipv4.conf.all.send_redirects = 0 |
net.ipv4.conf.all.accept_redirects = 0 |
net.ipv4.conf.all.accept_source_route = 0 |
# Disable packet forwarding. |
net.ipv4.ip_forward = 0 |
net.ipv6.conf.all.forwarding = 0 |
# Disable TCP slow start on idle connections |
net.ipv4.tcp_slow_start_after_idle = 0 |
# Increase Linux autotuning TCP buffer limits |
# Set max to 16MB for 1GE and 32M (33554432) or 54M (56623104) for 10GE |
# Don’t set tcp_mem itself! Let the kernel scale it based on RAM. |
net.core.rmem_max = 16777216 |
net.core.wmem_max = 16777216 |
net.core.rmem_default = 16777216 |
net.core.wmem_default = 16777216 |
net.core.optmem_max = 40960 |
net.ipv4.tcp_rmem = 4096 87380 16777216 |
net.ipv4.tcp_wmem = 4096 65536 16777216 |
# ——————————————————————— |
# The following allow the server to handle lots of connection churn |
# ——————————————————————— |
# Disconnect dead TCP connections after 1 minute |
net.ipv4.tcp_keepalive_time = 60 |
# Wait a maximum of 5 * 2 = 10 seconds in the TIME_WAIT state after a FIN, to handle |
# any remaining packets in the network. |
## for kernel 2.6/ubuntu 10.04 |
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 5 |
## for kernel 3.0/ubuntu 14.04 |
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 5 |
# Allow a high number of timewait sockets |
net.ipv4.tcp_max_tw_buckets = 2000000 |
# Timeout broken connections faster (amount of time to wait for FIN) |
net.ipv4.tcp_fin_timeout = 10 |
# Let the networking stack reuse TIME_WAIT connections when it thinks it’s safe to do so |
net.ipv4.tcp_tw_reuse = 1 |
# This option may cause problem and dropped after v4.12. Just don’t use it. |
# net.ipv4.tcp_tw_recycle = 0 |
# Determines the wait time between isAlive interval probes (reduce from 75 sec to 15) |
net.ipv4.tcp_keepalive_intvl = 15 |
# Determines the number of probes before timing out (reduce from 9 sec to 5 sec) |
net.ipv4.tcp_keepalive_probes = 5 |
# ——————————————————————— |
# Fix nf_contrack table full problem |
# You may encounter this problem if you use iptable based firewall. |
# ref http://lists.firehol.org/pipermail/firehol-support/2007-December/002243.html |
# http://jaseywang.me/2012/08/16/%E8%A7%A3%E5%86%B3-nf_conntrack-table-full-dropping-packet-%E7%9A%84%E5%87%A0%E7%A7%8D%E6%80%9D%E8%B7%AF/ |
# ——————————————————————— |
## for kernel 2.6/ubuntu 10.04 |
net.ipv4.netfilter.ip_conntrack_max = 655360 |
## for kernel 3.0/ubuntu 14.04 |
net.netfilter.nf_conntrack_max = 655360 |
# read-only, set /sys/module/nf_conntrack/parameters/hashsize instead |
## for kernel 2.6/ubuntu 10.04 |
#net.ipv4.netfilter.ip_conntrack_buckets = 327680 |
## for kernel 3.0/ubuntu 14.04 |
net.netfilter.nf_conntrack_buckets = 327680 |
## for kernel 2.6/ubuntu 10.04 |
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 10800 |
## for kernel 3.0/ubuntu 14.04 |
net.netfilter.nf_conntrack_tcp_timeout_established = 10800 |
# ——————————————————————— |
# Prevent ipv6 problem |
# ——————————————————————— |
net.ipv6.conf.all.disable_ipv6 = 1 |
net.ipv6.conf.default.disable_ipv6 = 1 |
net.ipv6.conf.lo.disable_ipv6 = 1 |
# ————————————————————- |
* soft nofile 655360 |
* hard nofile 655360 |
root soft nofile 655360 |
root hard nofile 655360 |
# net.ipv4.netfilter.* in sysctl config file may not take effect due to the boot sequence. |
# Fix it by trigger sysctl to load the config again here. |
sysctl -p /etc/sysctl.d/99-network-tuning.conf |
# Cannot set this via sysctl. Set it here instead. |
echo 327680 > /sys/module/nf_conntrack/parameters/hashsize |
This comment has been minimized.
Copy link Quote reply
IgorOhrimenko commented Feb 21, 2019
If directives do not apply after reboot, try the command:
echo «nf_conntrack» >> /etc/modules
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник