-
Notifications
You must be signed in to change notification settings - Fork 0
/
php.sh
82 lines (77 loc) · 2.57 KB
/
php.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# PHP #
phplowmem='2097152'
check_phplowmem=$(expr $server_ram_total \< $phplowmem)
max_children=`echo "scale=0;$server_ram_mb*0.4/30" | bc`
if [ "$check_phplowmem" == "1" ]; then
lessphpmem=y
fi
if [[ "$lessphpmem" = [yY] ]]; then
echo "$(<php/php-fpm-min.conf)"> /etc/php-fpm.conf
echo "$(<php/www-min.conf)"> /etc/php-fpm.d/www.conf
else
echo "$(<php/php-fpm.conf)"> /etc/php-fpm.conf
echo "$(<php/www.conf)"> /etc/php-fpm.d/www.conf
fi
sed -i "s/server_name_here/$server_name/g" /etc/php-fpm.conf
sed -i "s/server_name_here/$server_name/g" /etc/php-fpm.d/www.conf
sed -i "s/max_children_here/$max_children/g" /etc/php-fpm.d/www.conf
# dynamic PHP memory_limit calculation
if [[ "$server_ram_total" -le '262144' ]]; then
php_memorylimit='48M'
php_uploadlimit='48M'
php_realpathlimit='256k'
php_realpathttl='14400'
elif [[ "$server_ram_total" -gt '262144' && "$server_ram_total" -le '393216' ]]; then
php_memorylimit='96M'
php_uploadlimit='96M'
php_realpathlimit='320k'
php_realpathttl='21600'
elif [[ "$server_ram_total" -gt '393216' && "$server_ram_total" -le '524288' ]]; then
php_memorylimit='128M'
php_uploadlimit='128M'
php_realpathlimit='384k'
php_realpathttl='28800'
elif [[ "$server_ram_total" -gt '524288' && "$server_ram_total" -le '1049576' ]]; then
php_memorylimit='160M'
php_uploadlimit='160M'
php_realpathlimit='384k'
php_realpathttl='28800'
elif [[ "$server_ram_total" -gt '1049576' && "$server_ram_total" -le '2097152' ]]; then
php_memorylimit='256M'
php_uploadlimit='256M'
php_realpathlimit='384k'
php_realpathttl='28800'
elif [[ "$server_ram_total" -gt '2097152' && "$server_ram_total" -le '3145728' ]]; then
php_memorylimit='320M'
php_uploadlimit='320M'
php_realpathlimit='512k'
php_realpathttl='43200'
elif [[ "$server_ram_total" -gt '3145728' && "$server_ram_total" -le '4194304' ]]; then
php_memorylimit='512M'
php_uploadlimit='512M'
php_realpathlimit='512k'
php_realpathttl='43200'
elif [[ "$server_ram_total" -gt '4194304' ]]; then
php_memorylimit='800M'
php_uploadlimit='800M'
php_realpathlimit='640k'
php_realpathttl='86400'
fi
cat > "/etc/php.d/00-custom.ini" <<END
date.timezone = Asia/Ho_Chi_Minh
max_execution_time = 180
short_open_tag = On
realpath_cache_size = $php_realpathlimit
realpath_cache_ttl = $php_realpathttl
memory_limit = $php_memorylimit
upload_max_filesize = $php_uploadlimit
post_max_size = $php_uploadlimit
expose_php = Off
mail.add_x_header = Off
max_input_nesting_level = 128
max_input_vars = 2000
mysqlnd.net_cmd_buffer_size = 16384
always_populate_raw_post_data=-1
END
mkdir -p /var/lib/php/session