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 |
c44417f8
|
Scott Ullrich
|
|
32 |
0d60f50a
|
Seth Mos
|
# Grab amount of memory that is detected
|
33 |
47eee8fa
|
Scott Ullrich
|
if [ -f /var/log/dmesg.boot ]; then
|
34 |
839cad07
|
smos
|
AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
|
35 |
47eee8fa
|
Scott Ullrich
|
else
|
36 |
839cad07
|
smos
|
AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
|
37 |
47eee8fa
|
Scott Ullrich
|
fi
|
38 |
c44417f8
|
Scott Ullrich
|
|
39 |
2b11ff4d
|
Scott Ullrich
|
# Calculate APC SHM size according
|
40 |
|
|
# to detected memory values
|
41 |
|
|
if [ "$AVAILMEM" -lt "128" ]; then
|
42 |
f82be9e4
|
Scott Ullrich
|
APCSHMEMSIZE="10"
|
43 |
2b11ff4d
|
Scott Ullrich
|
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 |
40e46009
|
Scott Ullrich
|
|
60 |
31c96a14
|
Scott Ullrich
|
# Set upload directory
|
61 |
dee5d2fb
|
Renato Botelho
|
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
|
62 |
800b73e6
|
Scott Ullrich
|
UPLOADTMPDIR="/root"
|
63 |
31c96a14
|
Scott Ullrich
|
else
|
64 |
|
|
UPLOADTMPDIR="/tmp"
|
65 |
|
|
fi
|
66 |
|
|
|
67 |
de96a790
|
Scott Ullrich
|
# Define php modules. Do not add .so, it will
|
68 |
|
|
# be done automatically by the script below.
|
69 |
0997e8f3
|
Scott Ullrich
|
PHPMODULES="apc \
|
70 |
be1db1d3
|
Scott Ullrich
|
# Downloading via HTTP/FTP (pkg mgr, etc)
|
71 |
f1b64d5e
|
Scott Ullrich
|
curl \
|
72 |
|
|
date \
|
73 |
be1db1d3
|
Scott Ullrich
|
# Internationalization
|
74 |
f1b64d5e
|
Scott Ullrich
|
gettext \
|
75 |
be1db1d3
|
Scott Ullrich
|
# User manager
|
76 |
f1b64d5e
|
Scott Ullrich
|
ldap \
|
77 |
8a44206b
|
Scott Ullrich
|
openssl \
|
78 |
f1b64d5e
|
Scott Ullrich
|
pcntl \
|
79 |
be1db1d3
|
Scott Ullrich
|
# Regexs, PERL style!
|
80 |
f1b64d5e
|
Scott Ullrich
|
pcre \
|
81 |
be1db1d3
|
Scott Ullrich
|
# The mighty posix!
|
82 |
f1b64d5e
|
Scott Ullrich
|
posix \
|
83 |
|
|
readline \
|
84 |
be1db1d3
|
Scott Ullrich
|
# Login sessions
|
85 |
f1b64d5e
|
Scott Ullrich
|
session \
|
86 |
|
|
standard \
|
87 |
be1db1d3
|
Scott Ullrich
|
# Extra sanity seatbelts
|
88 |
27798303
|
Scott Ullrich
|
suhosin \
|
89 |
b8e3b043
|
Ermal Lu?i
|
pfSense \
|
90 |
fca48a65
|
Scott Ullrich
|
# Firewall rules edit
|
91 |
|
|
ctype \
|
92 |
be1db1d3
|
Scott Ullrich
|
# Config read/write
|
93 |
f1b64d5e
|
Scott Ullrich
|
xml \
|
94 |
caea0c47
|
Ermal Lu?i
|
xmlreader \
|
95 |
a669395c
|
Ermal
|
xmlwriter \
|
96 |
be1db1d3
|
Scott Ullrich
|
libxml \
|
97 |
d4ac1b88
|
Scott Ullrich
|
# user manager
|
98 |
|
|
mhash \
|
99 |
16058a05
|
Scott Ullrich
|
# firewall_rules_edit.php
|
100 |
|
|
mbstring \
|
101 |
8eae944e
|
Ermal
|
shmop \
|
102 |
be1db1d3
|
Scott Ullrich
|
# Page compression
|
103 |
f1b64d5e
|
Scott Ullrich
|
zlib"
|
104 |
e83dca8c
|
Scott Ullrich
|
|
105 |
80d887d1
|
Scott Ullrich
|
# Modules previously included.
|
106 |
fcdf9492
|
Scott Ullrich
|
# can be turned on by touching
|
107 |
80d887d1
|
Scott Ullrich
|
# /etc/php_dynamodules/$modulename
|
108 |
|
|
# sysvmsg \
|
109 |
|
|
# sysvsem \
|
110 |
|
|
# sysvshm \
|
111 |
|
|
# bcmath \
|
112 |
|
|
# sqlite \
|
113 |
|
|
# tokenizer \
|
114 |
|
|
# uploadprogress \
|
115 |
|
|
# sockets \
|
116 |
|
|
# Reflection \
|
117 |
|
|
# mysql \
|
118 |
16058a05
|
Scott Ullrich
|
|
119 |
80d887d1
|
Scott Ullrich
|
# bz2 \
|
120 |
|
|
# json \
|
121 |
|
|
|
122 |
de96a790
|
Scott Ullrich
|
# Get a loaded module list in the stock php
|
123 |
69b27c16
|
Scott Ullrich
|
if [ -f /usr/local/etc/php.ini ]; then
|
124 |
|
|
rm /usr/local/etc/php.ini
|
125 |
|
|
fi
|
126 |
|
|
if [ -f /usr/local/lib/php.ini ]; then
|
127 |
|
|
rm /usr/local/lib/php.ini
|
128 |
|
|
fi
|
129 |
|
|
LOADED_MODULES=`php -m | grep -v "\["`
|
130 |
e83dca8c
|
Scott Ullrich
|
|
131 |
2ed3203c
|
Scott Ullrich
|
# Populate a dummy php.ini to avoid
|
132 |
|
|
# the file being clobbered and the firewall
|
133 |
|
|
# not being able to boot back up.
|
134 |
|
|
cat >/usr/local/lib/php.ini <<EOF
|
135 |
4b29393a
|
Scott Ullrich
|
; File generated from /etc/rc.php_ini_setup
|
136 |
40e46009
|
Scott Ullrich
|
output_buffering = "0"
|
137 |
|
|
expose_php = Off
|
138 |
|
|
implicit_flush = true
|
139 |
|
|
magic_quotes_gpc = Off
|
140 |
|
|
max_execution_time = 99999999
|
141 |
|
|
max_input_time = 99999999
|
142 |
c720fffc
|
Scott Ullrich
|
set_time_limit = 0
|
143 |
40e46009
|
Scott Ullrich
|
register_argc_argv = On
|
144 |
|
|
file_uploads = On
|
145 |
31c96a14
|
Scott Ullrich
|
upload_tmp_dir = ${UPLOADTMPDIR}
|
146 |
40e46009
|
Scott Ullrich
|
upload_max_filesize = 100M
|
147 |
|
|
post_max_size = 100M
|
148 |
|
|
html_errors = Off
|
149 |
9444761e
|
sullrich
|
zlib.output_compression = Off
|
150 |
40e46009
|
Scott Ullrich
|
zlib.output_compression_level = 1
|
151 |
|
|
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
|
152 |
0804f515
|
Scott Ullrich
|
extension_dir=${EXTENSIONSDIR}
|
153 |
40e46009
|
Scott Ullrich
|
|
154 |
4b29393a
|
Scott Ullrich
|
; Extensions
|
155 |
a8e61346
|
Ermal
|
|
156 |
40e46009
|
Scott Ullrich
|
EOF
|
157 |
|
|
|
158 |
7f16265a
|
Scott Ullrich
|
# Ensure directory exists
|
159 |
|
|
if [ ! -d /etc/php_dynamodules ]; then
|
160 |
|
|
mkdir /etc/php_dynamodules
|
161 |
|
|
fi
|
162 |
|
|
|
163 |
|
|
# Read in dynamodules
|
164 |
c44417f8
|
Scott Ullrich
|
if [ -d /etc/php_dynamodules ]; then
|
165 |
|
|
DYNA_MODULES=`ls /etc/php_dynamodules/`
|
166 |
|
|
PHPMODULES="$PHPMODULES $DYNA_MODULES"
|
167 |
|
|
fi
|
168 |
|
|
|
169 |
e83dca8c
|
Scott Ullrich
|
# Loop through and generate modules to load.
|
170 |
|
|
# Take into account modules built into php.
|
171 |
|
|
for EXT in $PHPMODULES; do
|
172 |
|
|
SHOULDADD="true"
|
173 |
de96a790
|
Scott Ullrich
|
# Check to see if module is compiled into php statically
|
174 |
e83dca8c
|
Scott Ullrich
|
for LM in $LOADED_MODULES; do
|
175 |
|
|
if [ "$EXT" = "$LM" ]; then
|
176 |
|
|
SHOULDADD="false"
|
177 |
|
|
fi
|
178 |
|
|
done
|
179 |
|
|
if [ "$SHOULDADD" = "true" ]; then
|
180 |
de96a790
|
Scott Ullrich
|
# Ensure extension exists before adding.
|
181 |
69b27c16
|
Scott Ullrich
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
182 |
0804f515
|
Scott Ullrich
|
echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
|
183 |
|
|
fi
|
184 |
e83dca8c
|
Scott Ullrich
|
fi
|
185 |
|
|
done
|
186 |
|
|
|
187 |
de96a790
|
Scott Ullrich
|
# Get amount of ram installed on this system
|
188 |
40e46009
|
Scott Ullrich
|
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
|
189 |
|
|
export RAM
|
190 |
2ed3203c
|
Scott Ullrich
|
if [ $RAM -gt 96 ]; then
|
191 |
40e46009
|
Scott Ullrich
|
|
192 |
2ed3203c
|
Scott Ullrich
|
cat >>/usr/local/lib/php.ini <<EOF
|
193 |
e83dca8c
|
Scott Ullrich
|
|
194 |
4b29393a
|
Scott Ullrich
|
; APC Settings
|
195 |
40e46009
|
Scott Ullrich
|
apc.enabled="1"
|
196 |
|
|
apc.enable_cli="1"
|
197 |
de96a790
|
Scott Ullrich
|
apc.shm_size="${APCSHMEMSIZE}"
|
198 |
40e46009
|
Scott Ullrich
|
|
199 |
a8e61346
|
Ermal
|
[suhosin]
|
200 |
|
|
suhosin.get.max_array_depth = 5000
|
201 |
|
|
suhosin.get.max_array_index_length = 256
|
202 |
|
|
suhosin.get.max_vars = 5000
|
203 |
|
|
suhosin.post.max_array_depth = 5000
|
204 |
|
|
suhosin.post.max_array_index_length = 256
|
205 |
|
|
suhosin.post.max_vars = 5000
|
206 |
|
|
suhosin.request.max_array_depth = 5000
|
207 |
|
|
suhosin.request.max_array_index_length = 256
|
208 |
|
|
suhosin.request.max_vars = 5000
|
209 |
|
|
|
210 |
40e46009
|
Scott Ullrich
|
EOF
|
211 |
|
|
|
212 |
de96a790
|
Scott Ullrich
|
else
|
213 |
|
|
|
214 |
|
|
echo ">>> WARNING! under 128 megabytes of ram detected. Not enabling APC."
|
215 |
|
|
echo ">>> WARNING! under 128 megabytes of ram detected. Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
|
216 |
|
|
|
217 |
40e46009
|
Scott Ullrich
|
fi
|
218 |
|
|
|
219 |
de96a790
|
Scott Ullrich
|
# Copy php.ini file to etc/ too (cli)
|
220 |
40e46009
|
Scott Ullrich
|
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
|
221 |
e1fda0c0
|
Scott Ullrich
|
|
222 |
|
|
# Remove old log file if it exists.
|
223 |
|
|
if [ -f /var/run/php_modules_load_errors.txt ]; then
|
224 |
|
|
rm /var/run/php_modules_load_errors.txt
|
225 |
|
|
fi
|
226 |
|
|
|
227 |
|
|
# Check loaded modules and remove anything that did not load correctly
|
228 |
|
|
LOADED_MODULES=`php -m 2>/dev/null | grep -v "\["`
|
229 |
|
|
for EXT in $PHPMODULES; do
|
230 |
|
|
SHOULDREMOVE="true"
|
231 |
|
|
for LM in $LOADED_MODULES; do
|
232 |
|
|
if [ "$EXT" = "$LM" ]; then
|
233 |
|
|
SHOULDREMOVE="false"
|
234 |
|
|
fi
|
235 |
|
|
done
|
236 |
|
|
if [ "$SHOULDREMOVE" = "true" ]; then
|
237 |
|
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
238 |
|
|
echo ">>> ${EXT} did not load correctly. Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
|
239 |
|
|
cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
|
240 |
|
|
mv /tmp/php.ini /usr/local/lib/php.ini
|
241 |
|
|
fi
|
242 |
|
|
fi
|
243 |
|
|
done
|
244 |
|
|
|
245 |
|
|
# Copy php.ini file to etc/ too (cli)
|
246 |
|
|
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|