Project

General

Profile

Download (5.96 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
#	rc.php_ini_setup
4
#	Copyright (C)2008 Scott K Ullrich <sullrich@gmail.com>
5
#	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

    
28
# Set our operating platform
29
PLATFORM=`cat /etc/platform`
30
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
31

    
32
# Grab amount of memory that is detected
33
if [ -f /var/log/dmesg.boot ]; then
34
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { print $5 }'| sed 's/(//g'|tail -1`
35
else 
36
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { print $5 }'| sed 's/(//g'|tail -1`
37
fi
38

    
39
# Calculate APC SHM size according 
40
# to detected memory values
41
if [ "$AVAILMEM" -lt "128" ]; then
42
	APCSHMEMSIZE="10"
43
fi
44
if [ "$AVAILMEM" -gt "128" ]; then
45
	APCSHMEMSIZE="25"
46
fi
47
if [ "$AVAILMEM" -gt "256" ]; then
48
	APCSHMEMSIZE="45"
49
fi
50
if [ "$AVAILMEM" -gt "384" ]; then
51
	APCSHMEMSIZE="65"
52
fi
53
if [ "$AVAILMEM" -gt "512" ]; then
54
	APCSHMEMSIZE="80"
55
fi
56
if [ "$AVAILMEM" -gt "784" ]; then
57
	APCSHMEMSIZE="100"
58
fi
59

    
60
# Set upload directory
61
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
62
	UPLOADTMPDIR="/root"
63
else 
64
	UPLOADTMPDIR="/tmp"
65
fi
66

    
67
# Define php modules.  Do not add .so, it will  
68
# be done automatically by the script below.
69
PHPMODULES="apc \
70
# Downloading via HTTP/FTP (pkg mgr, etc)
71
	curl \
72
	date \
73
# Internationalization 
74
	gettext \
75
# User manager
76
	ldap \
77
	openssl \
78
	pcntl \
79
# Regexs, PERL style!
80
	pcre \
81
# The mighty posix!
82
	posix \
83
	readline \
84
# Login sessions
85
	session \
86
	standard \
87
# Extra sanity seatbelts
88
	suhosin \
89
# Firewall rules edit
90
	ctype \
91
# Config read/write
92
	xml \
93
	xmlreader \
94
	libxml \
95
# user manager
96
	mhash \
97
# firewall_rules_edit.php
98
	mbstring \
99
# Page compression
100
	zlib"
101

    
102
# Modules previously included.
103
# can be turned on by touching
104
# /etc/php_dynamodules/$modulename
105
#	shmop \
106
#	sysvmsg \
107
#	sysvsem \
108
#	sysvshm \
109
#	bcmath \
110
#	sqlite \
111
#	tokenizer \
112
#	uploadprogress \
113
#	sockets \
114
#	Reflection \
115
#	mysql \
116

    
117
#	bz2	\
118
#	json \
119

    
120
# Get a loaded module list in the stock php
121
if [ -f /usr/local/etc/php.ini ]; then
122
	rm /usr/local/etc/php.ini
123
fi
124
if [ -f /usr/local/lib/php.ini ]; then
125
	rm /usr/local/lib/php.ini
126
fi
127
LOADED_MODULES=`php -m | grep -v "\["`
128

    
129
# Populate a dummy php.ini to avoid
130
# the file being clobbered and the firewall
131
# not being able to boot back up.
132
cat >/usr/local/lib/php.ini <<EOF
133
; File generated from /etc/rc.php_ini_setup
134
output_buffering = "0"
135
expose_php = Off
136
implicit_flush = true
137
magic_quotes_gpc = Off
138
max_execution_time = 99999999
139
max_input_time = 99999999
140
register_argc_argv = On
141
file_uploads = On
142
upload_tmp_dir = ${UPLOADTMPDIR}
143
upload_max_filesize = 100M
144
post_max_size = 100M
145
html_errors = Off
146
zlib.output_compression = Off
147
zlib.output_compression_level = 1
148
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
149
extension_dir=${EXTENSIONSDIR}
150

    
151
; Extensions
152
EOF
153

    
154
# Ensure directory exists
155
if [ ! -d /etc/php_dynamodules ]; then
156
	mkdir /etc/php_dynamodules
157
fi
158

    
159
# Read in dynamodules
160
if [ -d /etc/php_dynamodules ]; then
161
	DYNA_MODULES=`ls /etc/php_dynamodules/`
162
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
163
fi
164

    
165
# Loop through and generate modules to load.
166
# Take into account modules built into php.
167
for EXT in $PHPMODULES; do
168
	SHOULDADD="true"
169
	# Check to see if module is compiled into php statically
170
	for LM in $LOADED_MODULES; do
171
		if [ "$EXT" = "$LM" ]; then
172
			SHOULDADD="false"
173
		fi
174
	done
175
	if [ "$SHOULDADD" = "true" ]; then
176
		# Ensure extension exists before adding.
177
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
178
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
179
		fi
180
	fi
181
done
182

    
183
# Get amount of ram installed on this system
184
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
185
export RAM
186
if [  $RAM -gt 96 ]; then
187

    
188
	cat >>/usr/local/lib/php.ini <<EOF
189

    
190
; APC Settings
191
apc.enabled="1"
192
apc.enable_cli="1"
193
apc.shm_size="${APCSHMEMSIZE}"
194

    
195
EOF
196

    
197
else 
198

    
199
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
200
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
201

    
202
fi
203

    
204
# Copy php.ini file to etc/ too (cli)
205
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
206

    
207
# Remove old log file if it exists.
208
if [ -f /var/run/php_modules_load_errors.txt ]; then
209
	rm /var/run/php_modules_load_errors.txt
210
fi 
211

    
212
# Check loaded modules and remove anything that did not load correctly
213
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
214
for EXT in $PHPMODULES; do
215
	SHOULDREMOVE="true"
216
	for LM in $LOADED_MODULES; do
217
		if [ "$EXT" = "$LM" ]; then
218
			SHOULDREMOVE="false"
219
		fi		
220
	done
221
	if [ "$SHOULDREMOVE" = "true" ]; then
222
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
223
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
224
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
225
			mv /tmp/php.ini /usr/local/lib/php.ini
226
		fi
227
	fi
228
done
229

    
230
# Copy php.ini file to etc/ too (cli)
231
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
232

    
233

    
234

    
235

    
(71-71/90)