1 |
40e46009
|
Scott Ullrich
|
#!/bin/sh
|
2 |
de96a790
|
Scott Ullrich
|
#
|
3 |
|
|
# rc.php_ini_setup
|
4 |
1e86e897
|
Scott Ullrich
|
# Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
|
5 |
de96a790
|
Scott Ullrich
|
# All rights reserved.
|
6 |
|
|
#
|
7 |
|
|
# Redistribution and use in source and binary forms, with or without
|
8 |
|
|
# modification, are permitted provided that the following conditions are met:
|
9 |
|
|
#
|
10 |
|
|
# 1. Redistributions of source code must retain the above copyright notice,
|
11 |
|
|
# this list of conditions and the following disclaimer.
|
12 |
|
|
#
|
13 |
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
14 |
|
|
# notice, this list of conditions and the following disclaimer in the
|
15 |
|
|
# documentation and/or other materials provided with the distribution.
|
16 |
|
|
#
|
17 |
|
|
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18 |
|
|
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19 |
|
|
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20 |
|
|
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26 |
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
27 |
40e46009
|
Scott Ullrich
|
|
28 |
|
|
# Set our operating platform
|
29 |
|
|
PLATFORM=`cat /etc/platform`
|
30 |
0804f515
|
Scott Ullrich
|
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
|
31 |
c44417f8
|
Scott Ullrich
|
|
32 |
0d60f50a
|
Seth Mos
|
# Grab amount of memory that is detected
|
33 |
47eee8fa
|
Scott Ullrich
|
if [ -f /var/log/dmesg.boot ]; then
|
34 |
839cad07
|
smos
|
AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
|
35 |
47eee8fa
|
Scott Ullrich
|
else
|
36 |
839cad07
|
smos
|
AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
|
37 |
47eee8fa
|
Scott Ullrich
|
fi
|
38 |
c44417f8
|
Scott Ullrich
|
|
39 |
b713d790
|
Scott Ullrich
|
if [ -z "$AVAILMEM" ]; then
|
40 |
|
|
MEM=`sysctl hw.physmem | cut -d':' -f2`
|
41 |
|
|
AVAILMEM=`expr $MEM / 1048576`
|
42 |
|
|
fi
|
43 |
|
|
|
44 |
2b11ff4d
|
Scott Ullrich
|
# Calculate APC SHM size according
|
45 |
|
|
# to detected memory values
|
46 |
cddedb40
|
Scott Ullrich
|
if [ "$AVAILMEM" -lt "65" ]; then
|
47 |
|
|
APCSHMEMSIZE="1"
|
48 |
|
|
fi
|
49 |
|
|
if [ "$AVAILMEM" -lt "96" ]; then
|
50 |
|
|
APCSHMEMSIZE="10"
|
51 |
|
|
fi
|
52 |
2b11ff4d
|
Scott Ullrich
|
if [ "$AVAILMEM" -lt "128" ]; then
|
53 |
f82be9e4
|
Scott Ullrich
|
APCSHMEMSIZE="10"
|
54 |
2b11ff4d
|
Scott Ullrich
|
fi
|
55 |
|
|
if [ "$AVAILMEM" -gt "128" ]; then
|
56 |
1e86e897
|
Scott Ullrich
|
APCSHMEMSIZE="15"
|
57 |
2b11ff4d
|
Scott Ullrich
|
fi
|
58 |
|
|
if [ "$AVAILMEM" -gt "256" ]; then
|
59 |
1e86e897
|
Scott Ullrich
|
APCSHMEMSIZE="20"
|
60 |
2b11ff4d
|
Scott Ullrich
|
fi
|
61 |
|
|
if [ "$AVAILMEM" -gt "384" ]; then
|
62 |
1e86e897
|
Scott Ullrich
|
APCSHMEMSIZE="25"
|
63 |
2b11ff4d
|
Scott Ullrich
|
fi
|
64 |
|
|
if [ "$AVAILMEM" -gt "512" ]; then
|
65 |
1e86e897
|
Scott Ullrich
|
APCSHMEMSIZE="30"
|
66 |
2b11ff4d
|
Scott Ullrich
|
fi
|
67 |
|
|
if [ "$AVAILMEM" -gt "784" ]; then
|
68 |
1e86e897
|
Scott Ullrich
|
APCSHMEMSIZE="35"
|
69 |
2b11ff4d
|
Scott Ullrich
|
fi
|
70 |
40e46009
|
Scott Ullrich
|
|
71 |
31c96a14
|
Scott Ullrich
|
# Set upload directory
|
72 |
dee5d2fb
|
Renato Botelho
|
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
|
73 |
800b73e6
|
Scott Ullrich
|
UPLOADTMPDIR="/root"
|
74 |
31c96a14
|
Scott Ullrich
|
else
|
75 |
|
|
UPLOADTMPDIR="/tmp"
|
76 |
|
|
fi
|
77 |
|
|
|
78 |
de96a790
|
Scott Ullrich
|
# Define php modules. Do not add .so, it will
|
79 |
|
|
# be done automatically by the script below.
|
80 |
0997e8f3
|
Scott Ullrich
|
PHPMODULES="apc \
|
81 |
be1db1d3
|
Scott Ullrich
|
# Downloading via HTTP/FTP (pkg mgr, etc)
|
82 |
f1b64d5e
|
Scott Ullrich
|
curl \
|
83 |
|
|
date \
|
84 |
be1db1d3
|
Scott Ullrich
|
# Internationalization
|
85 |
f1b64d5e
|
Scott Ullrich
|
gettext \
|
86 |
be1db1d3
|
Scott Ullrich
|
# User manager
|
87 |
f1b64d5e
|
Scott Ullrich
|
ldap \
|
88 |
8a44206b
|
Scott Ullrich
|
openssl \
|
89 |
f1b64d5e
|
Scott Ullrich
|
pcntl \
|
90 |
be1db1d3
|
Scott Ullrich
|
# Regexs, PERL style!
|
91 |
f1b64d5e
|
Scott Ullrich
|
pcre \
|
92 |
be1db1d3
|
Scott Ullrich
|
# The mighty posix!
|
93 |
f1b64d5e
|
Scott Ullrich
|
posix \
|
94 |
|
|
readline \
|
95 |
be1db1d3
|
Scott Ullrich
|
# Login sessions
|
96 |
f1b64d5e
|
Scott Ullrich
|
session \
|
97 |
|
|
standard \
|
98 |
be1db1d3
|
Scott Ullrich
|
# Extra sanity seatbelts
|
99 |
27798303
|
Scott Ullrich
|
suhosin \
|
100 |
b8e3b043
|
Ermal Lu?i
|
pfSense \
|
101 |
fca48a65
|
Scott Ullrich
|
# Firewall rules edit
|
102 |
|
|
ctype \
|
103 |
be1db1d3
|
Scott Ullrich
|
# Config read/write
|
104 |
f1b64d5e
|
Scott Ullrich
|
xml \
|
105 |
caea0c47
|
Ermal Lu?i
|
xmlreader \
|
106 |
a669395c
|
Ermal
|
xmlwriter \
|
107 |
be1db1d3
|
Scott Ullrich
|
libxml \
|
108 |
d4ac1b88
|
Scott Ullrich
|
# user manager
|
109 |
|
|
mhash \
|
110 |
16058a05
|
Scott Ullrich
|
# firewall_rules_edit.php
|
111 |
|
|
mbstring \
|
112 |
8eae944e
|
Ermal
|
shmop \
|
113 |
be1db1d3
|
Scott Ullrich
|
# Page compression
|
114 |
f1b64d5e
|
Scott Ullrich
|
zlib"
|
115 |
e83dca8c
|
Scott Ullrich
|
|
116 |
80d887d1
|
Scott Ullrich
|
# Modules previously included.
|
117 |
fcdf9492
|
Scott Ullrich
|
# can be turned on by touching
|
118 |
80d887d1
|
Scott Ullrich
|
# /etc/php_dynamodules/$modulename
|
119 |
|
|
# sysvmsg \
|
120 |
|
|
# sysvsem \
|
121 |
|
|
# sysvshm \
|
122 |
|
|
# bcmath \
|
123 |
|
|
# sqlite \
|
124 |
|
|
# tokenizer \
|
125 |
|
|
# uploadprogress \
|
126 |
|
|
# sockets \
|
127 |
|
|
# Reflection \
|
128 |
|
|
# mysql \
|
129 |
|
|
# bz2 \
|
130 |
|
|
# json \
|
131 |
|
|
|
132 |
de96a790
|
Scott Ullrich
|
# Get a loaded module list in the stock php
|
133 |
69b27c16
|
Scott Ullrich
|
if [ -f /usr/local/etc/php.ini ]; then
|
134 |
|
|
rm /usr/local/etc/php.ini
|
135 |
|
|
fi
|
136 |
|
|
if [ -f /usr/local/lib/php.ini ]; then
|
137 |
|
|
rm /usr/local/lib/php.ini
|
138 |
|
|
fi
|
139 |
|
|
LOADED_MODULES=`php -m | grep -v "\["`
|
140 |
e83dca8c
|
Scott Ullrich
|
|
141 |
2ed3203c
|
Scott Ullrich
|
# Populate a dummy php.ini to avoid
|
142 |
|
|
# the file being clobbered and the firewall
|
143 |
|
|
# not being able to boot back up.
|
144 |
|
|
cat >/usr/local/lib/php.ini <<EOF
|
145 |
4b29393a
|
Scott Ullrich
|
; File generated from /etc/rc.php_ini_setup
|
146 |
40e46009
|
Scott Ullrich
|
output_buffering = "0"
|
147 |
|
|
expose_php = Off
|
148 |
|
|
implicit_flush = true
|
149 |
|
|
magic_quotes_gpc = Off
|
150 |
|
|
max_execution_time = 99999999
|
151 |
|
|
max_input_time = 99999999
|
152 |
c720fffc
|
Scott Ullrich
|
set_time_limit = 0
|
153 |
40e46009
|
Scott Ullrich
|
register_argc_argv = On
|
154 |
|
|
file_uploads = On
|
155 |
31c96a14
|
Scott Ullrich
|
upload_tmp_dir = ${UPLOADTMPDIR}
|
156 |
40e46009
|
Scott Ullrich
|
upload_max_filesize = 100M
|
157 |
|
|
post_max_size = 100M
|
158 |
|
|
html_errors = Off
|
159 |
9444761e
|
sullrich
|
zlib.output_compression = Off
|
160 |
40e46009
|
Scott Ullrich
|
zlib.output_compression_level = 1
|
161 |
|
|
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
|
162 |
0804f515
|
Scott Ullrich
|
extension_dir=${EXTENSIONSDIR}
|
163 |
40e46009
|
Scott Ullrich
|
|
164 |
4b29393a
|
Scott Ullrich
|
; Extensions
|
165 |
a8e61346
|
Ermal
|
|
166 |
40e46009
|
Scott Ullrich
|
EOF
|
167 |
|
|
|
168 |
7f16265a
|
Scott Ullrich
|
# Ensure directory exists
|
169 |
|
|
if [ ! -d /etc/php_dynamodules ]; then
|
170 |
|
|
mkdir /etc/php_dynamodules
|
171 |
|
|
fi
|
172 |
|
|
|
173 |
|
|
# Read in dynamodules
|
174 |
c44417f8
|
Scott Ullrich
|
if [ -d /etc/php_dynamodules ]; then
|
175 |
|
|
DYNA_MODULES=`ls /etc/php_dynamodules/`
|
176 |
|
|
PHPMODULES="$PHPMODULES $DYNA_MODULES"
|
177 |
|
|
fi
|
178 |
|
|
|
179 |
e83dca8c
|
Scott Ullrich
|
# Loop through and generate modules to load.
|
180 |
|
|
# Take into account modules built into php.
|
181 |
|
|
for EXT in $PHPMODULES; do
|
182 |
|
|
SHOULDADD="true"
|
183 |
de96a790
|
Scott Ullrich
|
# Check to see if module is compiled into php statically
|
184 |
e83dca8c
|
Scott Ullrich
|
for LM in $LOADED_MODULES; do
|
185 |
|
|
if [ "$EXT" = "$LM" ]; then
|
186 |
|
|
SHOULDADD="false"
|
187 |
|
|
fi
|
188 |
|
|
done
|
189 |
|
|
if [ "$SHOULDADD" = "true" ]; then
|
190 |
de96a790
|
Scott Ullrich
|
# Ensure extension exists before adding.
|
191 |
69b27c16
|
Scott Ullrich
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
192 |
0804f515
|
Scott Ullrich
|
echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
|
193 |
|
|
fi
|
194 |
e83dca8c
|
Scott Ullrich
|
fi
|
195 |
|
|
done
|
196 |
|
|
|
197 |
de96a790
|
Scott Ullrich
|
# Get amount of ram installed on this system
|
198 |
40e46009
|
Scott Ullrich
|
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
|
199 |
|
|
export RAM
|
200 |
8ee1dc80
|
Scott Ullrich
|
export LOWMEM
|
201 |
|
|
if [ "$RAM" -lt "97" ]; then
|
202 |
|
|
LOWMEM="TRUE"
|
203 |
cddedb40
|
Scott Ullrich
|
cat >>/usr/local/lib/php.ini <<EOF
|
204 |
|
|
|
205 |
|
|
[suhosin]
|
206 |
|
|
suhosin.get.max_array_depth = 5000
|
207 |
|
|
suhosin.get.max_array_index_length = 256
|
208 |
|
|
suhosin.get.max_vars = 5000
|
209 |
|
|
suhosin.post.max_array_depth = 5000
|
210 |
|
|
suhosin.post.max_array_index_length = 256
|
211 |
|
|
suhosin.post.max_vars = 5000
|
212 |
|
|
suhosin.request.max_array_depth = 5000
|
213 |
|
|
suhosin.request.max_array_index_length = 256
|
214 |
|
|
suhosin.request.max_vars = 5000
|
215 |
|
|
|
216 |
|
|
EOF
|
217 |
|
|
|
218 |
|
|
fi
|
219 |
2ed3203c
|
Scott Ullrich
|
if [ $RAM -gt 96 ]; then
|
220 |
40e46009
|
Scott Ullrich
|
|
221 |
2ed3203c
|
Scott Ullrich
|
cat >>/usr/local/lib/php.ini <<EOF
|
222 |
e83dca8c
|
Scott Ullrich
|
|
223 |
4b29393a
|
Scott Ullrich
|
; APC Settings
|
224 |
40e46009
|
Scott Ullrich
|
apc.enabled="1"
|
225 |
|
|
apc.enable_cli="1"
|
226 |
de96a790
|
Scott Ullrich
|
apc.shm_size="${APCSHMEMSIZE}"
|
227 |
40e46009
|
Scott Ullrich
|
|
228 |
a8e61346
|
Ermal
|
[suhosin]
|
229 |
|
|
suhosin.get.max_array_depth = 5000
|
230 |
|
|
suhosin.get.max_array_index_length = 256
|
231 |
|
|
suhosin.get.max_vars = 5000
|
232 |
|
|
suhosin.post.max_array_depth = 5000
|
233 |
|
|
suhosin.post.max_array_index_length = 256
|
234 |
|
|
suhosin.post.max_vars = 5000
|
235 |
|
|
suhosin.request.max_array_depth = 5000
|
236 |
|
|
suhosin.request.max_array_index_length = 256
|
237 |
|
|
suhosin.request.max_vars = 5000
|
238 |
|
|
|
239 |
40e46009
|
Scott Ullrich
|
EOF
|
240 |
|
|
|
241 |
de96a790
|
Scott Ullrich
|
else
|
242 |
|
|
|
243 |
|
|
echo ">>> WARNING! under 128 megabytes of ram detected. Not enabling APC."
|
244 |
|
|
echo ">>> WARNING! under 128 megabytes of ram detected. Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
|
245 |
|
|
|
246 |
40e46009
|
Scott Ullrich
|
fi
|
247 |
|
|
|
248 |
de96a790
|
Scott Ullrich
|
# Copy php.ini file to etc/ too (cli)
|
249 |
40e46009
|
Scott Ullrich
|
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
|
250 |
e1fda0c0
|
Scott Ullrich
|
|
251 |
|
|
# Remove old log file if it exists.
|
252 |
|
|
if [ -f /var/run/php_modules_load_errors.txt ]; then
|
253 |
|
|
rm /var/run/php_modules_load_errors.txt
|
254 |
|
|
fi
|
255 |
|
|
|
256 |
|
|
# Check loaded modules and remove anything that did not load correctly
|
257 |
|
|
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
|
258 |
|
|
for EXT in $PHPMODULES; do
|
259 |
|
|
SHOULDREMOVE="true"
|
260 |
|
|
for LM in $LOADED_MODULES; do
|
261 |
|
|
if [ "$EXT" = "$LM" ]; then
|
262 |
|
|
SHOULDREMOVE="false"
|
263 |
|
|
fi
|
264 |
|
|
done
|
265 |
1e86e897
|
Scott Ullrich
|
# Handle low memory situations
|
266 |
8ee1dc80
|
Scott Ullrich
|
if [ "$LOWMEM" = "TRUE" ]; then
|
267 |
|
|
if [ "$EXT" = "apc" ]; then
|
268 |
|
|
SHOULDREMOVE="true"
|
269 |
|
|
fi
|
270 |
|
|
if [ "$EXT" = "xcache" ]; then
|
271 |
|
|
SHOULDREMOVE="true"
|
272 |
|
|
fi
|
273 |
|
|
fi
|
274 |
e1fda0c0
|
Scott Ullrich
|
if [ "$SHOULDREMOVE" = "true" ]; then
|
275 |
|
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
276 |
|
|
echo ">>> ${EXT} did not load correctly. Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
|
277 |
|
|
cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
|
278 |
|
|
mv /tmp/php.ini /usr/local/lib/php.ini
|
279 |
|
|
fi
|
280 |
|
|
fi
|
281 |
|
|
done
|
282 |
|
|
|
283 |
|
|
# Copy php.ini file to etc/ too (cli)
|
284 |
|
|
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|