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
	gettext \
49
	ldap \
50
	libxml \
51
	mbstring \
52
	mhash \
53
	mysql \
54
	openssl \
55
	pcntl \
56
	pcre \
57
	posix \
58
	readline \
59
	Reflection \
60
	session \
61
	shmop \
62
	standard \
63
	sysvmsg \
64
	sysvsem \
65
	sysvshm \
66
	sqlite \
67
	tokenizer \ 
68
	uploadprogress \
69
	xml \
70
	zlib"
71

    
72
# Get a loaded module list in the stock php
73
if [ -f /usr/local/etc/php.ini ]; then
74
	rm /usr/local/etc/php.ini
75
fi
76
if [ -f /usr/local/lib/php.ini ]; then
77
	rm /usr/local/lib/php.ini
78
fi
79
LOADED_MODULES=`php -m | grep -v "\["`
80

    
81
# Populate a dummy php.ini to avoid
82
# the file being clobbered and the firewall
83
# not being able to boot back up.
84
cat >/usr/local/lib/php.ini <<EOF
85
; File generated from /etc/rc.php_ini_setup
86
output_buffering = "0"
87
expose_php = Off
88
implicit_flush = true
89
magic_quotes_gpc = Off
90
max_execution_time = 99999999
91
max_input_time = 99999999
92
register_argc_argv = On
93
file_uploads = On
94
upload_tmp_dir = ${UPLOADTMPDIR}
95
upload_max_filesize = 100M
96
post_max_size = 100M
97
html_errors = Off
98
zlib.output_compression = On
99
zlib.output_compression_level = 1
100
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
101
uploadprogress.file.filename_template = /tmp/uploadprogress_%s.txt
102
extension_dir=${EXTENSIONSDIR}
103

    
104
; Extensions
105
EOF
106

    
107
# Loop through and generate modules to load.
108
# Take into account modules built into php.
109
for EXT in $PHPMODULES; do
110
	SHOULDADD="true"
111
	# Check to see if module is compiled into php statically
112
	for LM in $LOADED_MODULES; do
113
		if [ "$EXT" = "$LM" ]; then
114
			SHOULDADD="false"
115
		fi
116
	done
117
	if [ "$SHOULDADD" = "true" ]; then
118
		# Ensure extension exists before adding.
119
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
120
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
121
		fi
122
	fi
123
done
124

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

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

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

    
137
EOF
138

    
139
else 
140

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

    
144
fi
145

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

    
149
# Remove old log file if it exists.
150
if [ -f /var/run/php_modules_load_errors.txt ]; then
151
	rm /var/run/php_modules_load_errors.txt
152
fi 
153

    
154
# Check loaded modules and remove anything that did not load correctly
155
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
156
for EXT in $PHPMODULES; do
157
	SHOULDREMOVE="true"
158
	for LM in $LOADED_MODULES; do
159
		if [ "$EXT" = "$LM" ]; then
160
			SHOULDREMOVE="false"
161
		fi		
162
	done
163
	if [ "$SHOULDREMOVE" = "true" ]; then
164
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
165
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
166
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
167
			mv /tmp/php.ini /usr/local/lib/php.ini
168
		fi
169
	fi
170
done
171

    
172
# Copy php.ini file to etc/ too (cli)
173
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
174

    
175

    
176

    
177

    
(66-66/84)