Project

General

Profile

Download (5.6 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 deteceted
33
if [ -f /var/log/dmesg.boot ]; then
34
	AVAILMEM=`cat /var/log/dmesg.boot | grep "memory" | grep "avail" | awk '{ print $5 }' | cut -d'(' -f2 | cut -d'M' -f1`
35
else 
36
	AVAILMEM=`dmesg -a | grep "memory" | grep "avail" | awk '{ print $5 }' | cut -d'(' -f2 | cut -d'M' -f1`
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
	curl \
71
	date \
72
	gettext \
73
	ldap \
74
	openssl \
75
	pcntl \
76
	pcre \
77
	posix \
78
	readline \
79
	session \
80
	standard \
81
	suhosin \
82
	libxml \
83
	xml \
84
	xmlreader \
85
	zlib"
86

    
87
# Modules previously included.
88
# can be turned on by touching
89
# /etc/php_dynamodules/$modulename
90
#	shmop \
91
#	sysvmsg \
92
#	sysvsem \
93
#	sysvshm \
94
#	bcmath \
95
#	sqlite \
96
#	tokenizer \
97
#	uploadprogress \
98
#	sockets \
99
#	Reflection \
100
#	mysql \
101
#	mhash \
102
#	mbstring \
103
#	bz2	\
104
#	ctype \
105
#	json \
106

    
107
# Get a loaded module list in the stock php
108
if [ -f /usr/local/etc/php.ini ]; then
109
	rm /usr/local/etc/php.ini
110
fi
111
if [ -f /usr/local/lib/php.ini ]; then
112
	rm /usr/local/lib/php.ini
113
fi
114
LOADED_MODULES=`php -m | grep -v "\["`
115

    
116
# Populate a dummy php.ini to avoid
117
# the file being clobbered and the firewall
118
# not being able to boot back up.
119
cat >/usr/local/lib/php.ini <<EOF
120
; File generated from /etc/rc.php_ini_setup
121
output_buffering = "0"
122
expose_php = Off
123
implicit_flush = true
124
magic_quotes_gpc = Off
125
max_execution_time = 99999999
126
max_input_time = 99999999
127
register_argc_argv = On
128
file_uploads = On
129
upload_tmp_dir = ${UPLOADTMPDIR}
130
upload_max_filesize = 100M
131
post_max_size = 100M
132
html_errors = Off
133
zlib.output_compression = On
134
zlib.output_compression_level = 1
135
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
136
extension_dir=${EXTENSIONSDIR}
137

    
138
; Extensions
139
EOF
140

    
141
if [ -d /etc/php_dynamodules ]; then
142
	DYNA_MODULES=`ls /etc/php_dynamodules/`
143
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
144
fi
145

    
146
# Loop through and generate modules to load.
147
# Take into account modules built into php.
148
for EXT in $PHPMODULES; do
149
	SHOULDADD="true"
150
	# Check to see if module is compiled into php statically
151
	for LM in $LOADED_MODULES; do
152
		if [ "$EXT" = "$LM" ]; then
153
			SHOULDADD="false"
154
		fi
155
	done
156
	if [ "$SHOULDADD" = "true" ]; then
157
		# Ensure extension exists before adding.
158
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
159
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
160
		fi
161
	fi
162
done
163

    
164
# Get amount of ram installed on this system
165
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
166
export RAM
167
if [  $RAM -gt 96 ]; then
168

    
169
	cat >>/usr/local/lib/php.ini <<EOF
170

    
171
; APC Settings
172
apc.enabled="1"
173
apc.enable_cli="1"
174
apc.shm_size="${APCSHMEMSIZE}"
175

    
176
EOF
177

    
178
else 
179

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

    
183
fi
184

    
185
# Copy php.ini file to etc/ too (cli)
186
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
187

    
188
# Remove old log file if it exists.
189
if [ -f /var/run/php_modules_load_errors.txt ]; then
190
	rm /var/run/php_modules_load_errors.txt
191
fi 
192

    
193
# Check loaded modules and remove anything that did not load correctly
194
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
195
for EXT in $PHPMODULES; do
196
	SHOULDREMOVE="true"
197
	for LM in $LOADED_MODULES; do
198
		if [ "$EXT" = "$LM" ]; then
199
			SHOULDREMOVE="false"
200
		fi		
201
	done
202
	if [ "$SHOULDREMOVE" = "true" ]; then
203
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
204
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
205
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
206
			mv /tmp/php.ini /usr/local/lib/php.ini
207
		fi
208
	fi
209
done
210

    
211
# Copy php.ini file to etc/ too (cli)
212
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
213

    
214

    
215

    
216

    
(70-70/89)