Project

General

Profile

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