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