Project

General

Profile

Download (4.69 KB) Statistics
| Branch: | Tag: | Revision:
1 40e46009 Scott Ullrich
#!/bin/sh
2 de96a790 Scott Ullrich
#
3
#	rc.php_ini_setup
4 3937f149 Scott Ullrich
#	Copyright (C)2008 Scott K 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 de96a790 Scott Ullrich
APCSHMEMSIZE="25"
32 40e46009 Scott Ullrich
33 31c96a14 Scott Ullrich
# Set upload directory
34
if [ "$PLATFORM" = "embedded" ]; then
35
	UPLOADTMPDIR="/root"
36
else 
37
	UPLOADTMPDIR="/tmp"
38
fi
39
40 de96a790 Scott Ullrich
# Define php modules.  Do not add .so, it will  
41
# be done automatically by the script below.
42 0997e8f3 Scott Ullrich
PHPMODULES="apc \
43
	bcmath \
44 f1b64d5e Scott Ullrich
	bz2 \
45
	ctype \
46
	curl \
47
	date \
48 e70cc23b Scott Ullrich
	json \
49 f1b64d5e Scott Ullrich
	gettext \
50
	ldap \
51
	libxml \
52
	mbstring \
53
	mhash \
54 9980cd72 Scott Ullrich
	mysql \
55 8a44206b Scott Ullrich
	openssl \
56 f1b64d5e Scott Ullrich
	pcntl \
57
	pcre \
58
	posix \
59
	readline \
60
	Reflection \
61
	session \
62
	shmop \
63
	standard \
64
	sysvmsg \
65
	sysvsem \
66
	sysvshm \
67 e1fda0c0 Scott Ullrich
	sqlite \
68 073ab2c8 Scott Ullrich
	tokenizer \ 
69 f1b64d5e Scott Ullrich
	uploadprogress \
70
	xml \
71
	zlib"
72 e83dca8c Scott Ullrich
73 de96a790 Scott Ullrich
# Get a loaded module list in the stock php
74 69b27c16 Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
75
	rm /usr/local/etc/php.ini
76
fi
77
if [ -f /usr/local/lib/php.ini ]; then
78
	rm /usr/local/lib/php.ini
79
fi
80
LOADED_MODULES=`php -m | grep -v "\["`
81 e83dca8c Scott Ullrich
82 2ed3203c Scott Ullrich
# Populate a dummy php.ini to avoid
83
# the file being clobbered and the firewall
84
# not being able to boot back up.
85
cat >/usr/local/lib/php.ini <<EOF
86 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
87 40e46009 Scott Ullrich
output_buffering = "0"
88
expose_php = Off
89
implicit_flush = true
90
magic_quotes_gpc = Off
91
max_execution_time = 99999999
92
max_input_time = 99999999
93
register_argc_argv = On
94
file_uploads = On
95 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
96 40e46009 Scott Ullrich
upload_max_filesize = 100M
97
post_max_size = 100M
98
html_errors = Off
99
zlib.output_compression = On
100
zlib.output_compression_level = 1
101
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
102
uploadprogress.file.filename_template = /tmp/uploadprogress_%s.txt
103 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
104 40e46009 Scott Ullrich
105 4b29393a Scott Ullrich
; Extensions
106 40e46009 Scott Ullrich
EOF
107
108 e83dca8c Scott Ullrich
# Loop through and generate modules to load.
109
# Take into account modules built into php.
110
for EXT in $PHPMODULES; do
111
	SHOULDADD="true"
112 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
113 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
114
		if [ "$EXT" = "$LM" ]; then
115
			SHOULDADD="false"
116
		fi
117
	done
118
	if [ "$SHOULDADD" = "true" ]; then
119 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
120 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
121 0804f515 Scott Ullrich
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
122
		fi
123 e83dca8c Scott Ullrich
	fi
124
done
125
126 de96a790 Scott Ullrich
# Get amount of ram installed on this system
127 40e46009 Scott Ullrich
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
128
export RAM
129 2ed3203c Scott Ullrich
if [  $RAM -gt 96 ]; then
130 40e46009 Scott Ullrich
131 2ed3203c Scott Ullrich
	cat >>/usr/local/lib/php.ini <<EOF
132 e83dca8c Scott Ullrich
133 4b29393a Scott Ullrich
; APC Settings
134 40e46009 Scott Ullrich
apc.enabled="1"
135
apc.enable_cli="1"
136 de96a790 Scott Ullrich
apc.shm_size="${APCSHMEMSIZE}"
137 40e46009 Scott Ullrich
138
EOF
139
140 de96a790 Scott Ullrich
else 
141
142
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
143
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
144
145 40e46009 Scott Ullrich
fi
146
147 de96a790 Scott Ullrich
# Copy php.ini file to etc/ too (cli)
148 40e46009 Scott Ullrich
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
149 e1fda0c0 Scott Ullrich
150
# Remove old log file if it exists.
151
if [ -f /var/run/php_modules_load_errors.txt ]; then
152
	rm /var/run/php_modules_load_errors.txt
153
fi 
154
155
# Check loaded modules and remove anything that did not load correctly
156
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
157
for EXT in $PHPMODULES; do
158
	SHOULDREMOVE="true"
159
	for LM in $LOADED_MODULES; do
160
		if [ "$EXT" = "$LM" ]; then
161
			SHOULDREMOVE="false"
162
		fi		
163
	done
164
	if [ "$SHOULDREMOVE" = "true" ]; then
165
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
166
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
167
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
168
			mv /tmp/php.ini /usr/local/lib/php.ini
169
		fi
170
	fi
171
done
172
173
# Copy php.ini file to etc/ too (cli)
174
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
175
176
177