Project

General

Profile

Download (4.69 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
APCSHMEMSIZE="25"
32

    
33
# Set upload directory
34
if [ "$PLATFORM" = "embedded" ]; then
35
	UPLOADTMPDIR="/root"
36
else 
37
	UPLOADTMPDIR="/tmp"
38
fi
39

    
40
# Define php modules.  Do not add .so, it will  
41
# be done automatically by the script below.
42
PHPMODULES="apc \
43
	bcmath \
44
	bz2 \
45
	ctype \
46
	curl \
47
	date \
48
	json \
49
	gettext \
50
	ldap \
51
	libxml \
52
	mbstring \
53
	mhash \
54
	mysql \
55
	openssl \
56
	pcntl \
57
	pcre \
58
	posix \
59
	readline \
60
	Reflection \
61
	session \
62
	shmop \
63
	standard \
64
	sysvmsg \
65
	sysvsem \
66
	sysvshm \
67
	sqlite \
68
	tokenizer \ 
69
	uploadprogress \
70
	xml \
71
	zlib"
72

    
73
# Get a loaded module list in the stock php
74
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

    
82
# 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
; File generated from /etc/rc.php_ini_setup
87
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
upload_tmp_dir = ${UPLOADTMPDIR}
96
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
extension_dir=${EXTENSIONSDIR}
104

    
105
; Extensions
106
EOF
107

    
108
# 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
	# Check to see if module is compiled into php statically
113
	for LM in $LOADED_MODULES; do
114
		if [ "$EXT" = "$LM" ]; then
115
			SHOULDADD="false"
116
		fi
117
	done
118
	if [ "$SHOULDADD" = "true" ]; then
119
		# Ensure extension exists before adding.
120
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
121
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
122
		fi
123
	fi
124
done
125

    
126
# Get amount of ram installed on this system
127
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
128
export RAM
129
if [  $RAM -gt 96 ]; then
130

    
131
	cat >>/usr/local/lib/php.ini <<EOF
132

    
133
; APC Settings
134
apc.enabled="1"
135
apc.enable_cli="1"
136
apc.shm_size="${APCSHMEMSIZE}"
137

    
138
EOF
139

    
140
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
fi
146

    
147
# Copy php.ini file to etc/ too (cli)
148
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
149

    
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

    
178

    
(68-68/87)