Project

General

Profile

Download (9.6 KB) Statistics
| Branch: | Tag: | Revision:
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 51d0f816 Ermal
PLATFORM=`/bin/cat /etc/platform`
30 c44417f8 Scott Ullrich
31 79454450 Scott Ullrich
if [ -d /usr/local/lib/php/20090626 ]; then
32
	EXTENSIONSDIR="/usr/local/lib/php/20090626/"
33
else
34
	EXTENSIONSDIR="/usr/local/lib/php/20060613/"
35
fi
36
37 0d60f50a Seth Mos
# Grab amount of memory that is detected
38 47eee8fa Scott Ullrich
if [ -f /var/log/dmesg.boot ]; then
39 839cad07 smos
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
40 47eee8fa Scott Ullrich
else 
41 839cad07 smos
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
42 47eee8fa Scott Ullrich
fi
43 c44417f8 Scott Ullrich
44 b713d790 Scott Ullrich
if [ -z "$AVAILMEM" ]; then
45 51d0f816 Ermal
	MEM=`/sbin/sysctl hw.physmem | cut -d':' -f2`
46
	AVAILMEM=`/bin/expr $MEM / 1048576`
47 b713d790 Scott Ullrich
fi
48
49 2b11ff4d Scott Ullrich
# Calculate APC SHM size according 
50
# to detected memory values
51 7ba99a6c Ermal
if [ "$AVAILMEM" -gt "135" ]; then
52
	APCSHMEMSIZE="10M"
53 2b11ff4d Scott Ullrich
fi
54
if [ "$AVAILMEM" -gt "256" ]; then
55 eebccaca Erik Fonnesbeck
	APCSHMEMSIZE="20M"
56 2b11ff4d Scott Ullrich
fi
57
if [ "$AVAILMEM" -gt "384" ]; then
58 eebccaca Erik Fonnesbeck
	APCSHMEMSIZE="25M"
59 2b11ff4d Scott Ullrich
fi
60
if [ "$AVAILMEM" -gt "512" ]; then
61 eebccaca Erik Fonnesbeck
	APCSHMEMSIZE="30M"
62 2b11ff4d Scott Ullrich
fi
63
if [ "$AVAILMEM" -gt "784" ]; then
64 7ba99a6c Ermal
	APCSHMEMSIZE="50M"
65 2b11ff4d Scott Ullrich
fi
66 40e46009 Scott Ullrich
67 31c96a14 Scott Ullrich
# Set upload directory
68 dee5d2fb Renato Botelho
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
69 7ff663d3 Warren Baker
	UPLOADTMPDIR=`/usr/bin/grep upload_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
70 31c96a14 Scott Ullrich
else 
71
	UPLOADTMPDIR="/tmp"
72
fi
73
74 de96a790 Scott Ullrich
# Define php modules.  Do not add .so, it will  
75
# be done automatically by the script below.
76 a4fc6ec7 Ermal
PHPMODULES="standard"
77
if [  "$AVAILMEM" -gt 135 ]; then
78
	PHPMODULES="$PHPMODULES apc"
79
fi
80 c25197ba smos
# Config read/write
81
PHPMODULES="$PHPMODULES xml libxml dom"
82
PHPMODULES="$PHPMODULES simplexml xmlreader xmlwriter"
83 be1db1d3 Scott Ullrich
# Downloading via HTTP/FTP (pkg mgr, etc)
84 5556f3a1 Ermal
PHPMODULES="$PHPMODULES curl date"
85 be1db1d3 Scott Ullrich
# Internationalization 
86 5556f3a1 Ermal
PHPMODULES="$PHPMODULES gettext"
87 be1db1d3 Scott Ullrich
# User manager
88 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ldap openssl pcntl"
89 d9867431 jim-p
PHPMODULES="$PHPMODULES hash"
90 b3765f4c Roberto Nunnari
PHPMODULES="$PHPMODULES mcrypt"
91 be1db1d3 Scott Ullrich
# Regexs, PERL style!
92 5556f3a1 Ermal
PHPMODULES="$PHPMODULES pcre"
93 be1db1d3 Scott Ullrich
# The mighty posix!
94 5556f3a1 Ermal
PHPMODULES="$PHPMODULES posix"
95
PHPMODULES="$PHPMODULES readline"
96 be1db1d3 Scott Ullrich
# Login sessions
97 5556f3a1 Ermal
PHPMODULES="$PHPMODULES session"
98 be1db1d3 Scott Ullrich
# Extra sanity seatbelts
99 c25197ba smos
PHPMODULES="$PHPMODULES suhosin"
100 fca48a65 Scott Ullrich
# Firewall rules edit
101 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ctype"
102 16058a05 Scott Ullrich
# firewall_rules_edit.php
103 5556f3a1 Ermal
PHPMODULES="$PHPMODULES mbstring"
104
# Synchronization primitives
105
PHPMODULES="$PHPMODULES shmop"
106 be1db1d3 Scott Ullrich
# Page compression
107 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zlib"
108
# SQLlite & Database
109
PHPMODULES="$PHPMODULES spl"
110
PHPMODULES="$PHPMODULES pdo"
111
PHPMODULES="$PHPMODULES sqlite"
112 04747c75 Warren Baker
# RADIUS
113
PHPMODULES="$PHPMODULES radius"
114 e929c925 Scott Ullrich
# ZeroMQ
115 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zmq"
116 c88ff708 Scott Ullrich
# SSH2
117
PHPMODULES="$PHPMODULES ssh2"
118 5556f3a1 Ermal
# pfSense extensions
119
PHPMODULES="$PHPMODULES pfSense"
120 a1f77238 Darren Embry
# json
121
PHPMODULES="$PHPMODULES json"
122 c1993935 jim-p
# bcmath
123
PHPMODULES="$PHPMODULES bcmath"
124 e83dca8c Scott Ullrich
125 277ee858 lgcosta
PHP_ZEND_MODULES="ioncube_loader"
126
PHP_ZEND_MODULES_TS="ioncube_loader_ts"
127 8ef700da Scott Ullrich
128 80d887d1 Scott Ullrich
# Modules previously included.
129 fcdf9492 Scott Ullrich
# can be turned on by touching
130 80d887d1 Scott Ullrich
# /etc/php_dynamodules/$modulename
131
#	sysvmsg \
132
#	sysvsem \
133
#	sysvshm \
134
#	bcmath \
135
#	tokenizer \
136
#	uploadprogress \
137
#	sockets \
138
#	Reflection \
139
#	mysql \
140
#	bz2	\
141
142 5556f3a1 Ermal
# Clear the .ini file to make sure we are clean
143 69b27c16 Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
144 51d0f816 Ermal
	/bin/rm /usr/local/etc/php.ini
145 69b27c16 Scott Ullrich
fi
146
if [ -f /usr/local/lib/php.ini ]; then
147 51d0f816 Ermal
	/bin/rm /usr/local/lib/php.ini
148 69b27c16 Scott Ullrich
fi
149 51d0f816 Ermal
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/grep -v "\["`
150 e83dca8c Scott Ullrich
151 9d0be827 smos
# Fetch the timezone from the XML and set it here. We set it later too in the running scripts
152
TIMEZONE=`cat /conf/config.xml | egrep -E '<timezone>(.*?)</timezone>' | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
153
154 5556f3a1 Ermal
# Get a loaded module list in the stock php
155 2ed3203c Scott Ullrich
# Populate a dummy php.ini to avoid
156
# the file being clobbered and the firewall
157
# not being able to boot back up.
158 51d0f816 Ermal
/bin/cat >/usr/local/lib/php.ini <<EOF
159 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
160 40e46009 Scott Ullrich
output_buffering = "0"
161
expose_php = Off
162
implicit_flush = true
163
magic_quotes_gpc = Off
164 9d0be827 smos
max_execution_time = 900
165 7e824233 smos
max_input_time = 1800
166 40e46009 Scott Ullrich
register_argc_argv = On
167
file_uploads = On
168 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
169 96325dba Warren Baker
upload_max_filesize = 200M
170
post_max_size = 200M
171 40e46009 Scott Ullrich
html_errors = Off
172 f4015bd7 Scott Ullrich
zlib.output_compression = Off
173 40e46009 Scott Ullrich
zlib.output_compression_level = 1
174
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
175 8919256f Scott Ullrich
display_startup_errors=on
176
display_errors=on
177 baa2dba2 Scott Ullrich
log_errors=on
178
error_log=/tmp/PHP_errors.log
179 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
180 9d0be827 smos
date.timezone="${TIMEZONE}"
181 40e46009 Scott Ullrich
182 4b29393a Scott Ullrich
; Extensions
183 a8e61346 Ermal
184 40e46009 Scott Ullrich
EOF
185
186 5556f3a1 Ermal
# Copy php.ini file to etc/ too (cli)
187 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
188 5556f3a1 Ermal
189 7f16265a Scott Ullrich
# Ensure directory exists
190
if [ ! -d /etc/php_dynamodules ]; then
191 51d0f816 Ermal
	/bin/mkdir /etc/php_dynamodules
192 7f16265a Scott Ullrich
fi
193 5b9afe1e Scott Ullrich
if [ ! -d /etc/php_dynamodules_zend ]; then
194
	/bin/mkdir /etc/php_dynamodules_zend
195
fi
196
if [ ! -d /etc/php_dynamodules_zend_ts ]; then
197
	/bin/mkdir /etc/php_dynamodules_zend_ts
198
fi
199 7f16265a Scott Ullrich
200
# Read in dynamodules
201 c44417f8 Scott Ullrich
if [ -d /etc/php_dynamodules ]; then
202 fd3e19f3 Scott Ullrich
	DYNA_MODULES=`/bin/ls -Utr /etc/php_dynamodules/`
203 c44417f8 Scott Ullrich
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
204
fi
205
206 8ef700da Scott Ullrich
# Read in zend modules
207
if [ -d /etc/php_dynamodules_zend ]; then
208 f81cbdad Scott Ullrich
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend/`
209 8ef700da Scott Ullrich
	PHP_ZEND_MODULES="$PHP_ZEND_MODULES $DYNA_MODULES"
210
fi
211
212
# Read in zend threaded modules
213
if [ -d /etc/php_dynamodules_zend_ts ]; then
214 f81cbdad Scott Ullrich
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend_ts/`
215 14033103 Scott Ullrich
	PHP_ZEND_MODULES_TS="$PHP_ZEND_MODULES_TS $DYNA_MODULES"
216 8ef700da Scott Ullrich
fi
217
218 e83dca8c Scott Ullrich
# Loop through and generate modules to load.
219
# Take into account modules built into php.
220
for EXT in $PHPMODULES; do
221
	SHOULDADD="true"
222 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
223 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
224
		if [ "$EXT" = "$LM" ]; then
225
			SHOULDADD="false"
226
		fi
227
	done
228
	if [ "$SHOULDADD" = "true" ]; then
229 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
230 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
231 0804f515 Scott Ullrich
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
232
		fi
233 e83dca8c Scott Ullrich
	fi
234
done
235
236 8ef700da Scott Ullrich
# Zend modules
237
for EXT in $PHP_ZEND_MODULES; do
238
	# Ensure extension exists before adding.
239 5c52cd56 lgcosta
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
240
		echo "zend_extension=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
241 8ef700da Scott Ullrich
	fi
242
done
243
244
# Zend threaded modules
245
for EXT in $PHP_ZEND_MODULES_TS; do
246
	# Ensure extension exists before adding.
247 5c52cd56 lgcosta
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
248
		echo "zend_extension_ts=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
249 8ef700da Scott Ullrich
	fi
250
done
251
252 de96a790 Scott Ullrich
# Get amount of ram installed on this system
253 51d0f816 Ermal
RAM=`/sbin/sysctl hw.realmem | /usr/bin/awk '{print $2/1000000}' | /usr/bin/awk -F '.' '{print $1}'`
254 40e46009 Scott Ullrich
export RAM
255 8ee1dc80 Scott Ullrich
export LOWMEM
256 430b921b Irving Popovetsky
if [  "$RAM" -gt 135 ]; then
257 40e46009 Scott Ullrich
258 51d0f816 Ermal
	/bin/cat >>/usr/local/lib/php.ini <<EOF
259 e83dca8c Scott Ullrich
260 4b29393a Scott Ullrich
; APC Settings
261 40e46009 Scott Ullrich
apc.enabled="1"
262 59218e22 Scott Ullrich
apc.enable_cli="0"
263 de96a790 Scott Ullrich
apc.shm_size="${APCSHMEMSIZE}"
264 40e46009 Scott Ullrich
265 5556f3a1 Ermal
EOF
266
267
else
268
	LOWMEM="TRUE"
269
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
270 51d0f816 Ermal
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
271 5556f3a1 Ermal
fi
272
273 51d0f816 Ermal
	/bin/cat >>/usr/local/lib/php.ini <<EOF
274 5556f3a1 Ermal
275 a8e61346 Ermal
[suhosin]
276
suhosin.get.max_array_depth = 5000
277
suhosin.get.max_array_index_length = 256
278
suhosin.get.max_vars = 5000
279 4f1bace5 Ermal
suhosin.get.max_value_length = 500000
280 a8e61346 Ermal
suhosin.post.max_array_depth = 5000
281
suhosin.post.max_array_index_length = 256
282
suhosin.post.max_vars = 5000
283 4f1bace5 Ermal
suhosin.post.max_value_length = 500000
284 a8e61346 Ermal
suhosin.request.max_array_depth = 5000
285
suhosin.request.max_array_index_length = 256
286
suhosin.request.max_vars = 5000
287 4f1bace5 Ermal
suhosin.request.max_value_length = 500000
288 b9bc333b Scott Ullrich
suhosin.memory_limit = 512435456
289 a8e61346 Ermal
290 40e46009 Scott Ullrich
EOF
291
292
293 de96a790 Scott Ullrich
# Copy php.ini file to etc/ too (cli)
294 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
295 e1fda0c0 Scott Ullrich
296
# Remove old log file if it exists.
297
if [ -f /var/run/php_modules_load_errors.txt ]; then
298 51d0f816 Ermal
	/bin/rm /var/run/php_modules_load_errors.txt
299 e1fda0c0 Scott Ullrich
fi 
300
301 7030262c Scott Ullrich
for EXT in $PHPMODULES; do
302 51d0f816 Ermal
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
303 7030262c Scott Ullrich
done
304
305 e1fda0c0 Scott Ullrich
# Check loaded modules and remove anything that did not load correctly
306 51d0f816 Ermal
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
307 7030262c Scott Ullrich
for EXT in $PHPMODULESLC; do
308 e1fda0c0 Scott Ullrich
	SHOULDREMOVE="true"
309
	for LM in $LOADED_MODULES; do
310
		if [ "$EXT" = "$LM" ]; then
311
			SHOULDREMOVE="false"
312
		fi		
313
	done
314 1e86e897 Scott Ullrich
	# Handle low memory situations
315 8ee1dc80 Scott Ullrich
	if [ "$LOWMEM" = "TRUE" ]; then
316
		if [ "$EXT" = "apc" ]; then
317
			SHOULDREMOVE="true"
318
		fi
319
		if [ "$EXT" = "xcache" ]; then
320
			SHOULDREMOVE="true"
321
		fi
322
	fi
323 e1fda0c0 Scott Ullrich
	if [ "$SHOULDREMOVE" = "true" ]; then
324
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
325
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
326 51d0f816 Ermal
			/bin/cat /usr/local/lib/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
327
			/bin/rm -f /usr/local/lib/php.ini
328
			/bin/mv /tmp/php.ini /usr/local/lib/php.ini
329 e1fda0c0 Scott Ullrich
		fi
330
	fi
331
done
332
333
# Copy php.ini file to etc/ too (cli)
334 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini