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
|
elif [ "$PLATFORM" = "embedded" ] ; then
|
37
|
UPLOADTMPDIR="/root"
|
38
|
else
|
39
|
UPLOADTMPDIR="/tmp"
|
40
|
fi
|
41
|
|
42
|
# Define php modules. Do not add .so, it will
|
43
|
# be done automatically by the script below.
|
44
|
PHPMODULES="apc \
|
45
|
bcmath \
|
46
|
bz2 \
|
47
|
ctype \
|
48
|
curl \
|
49
|
date \
|
50
|
json \
|
51
|
gettext \
|
52
|
ldap \
|
53
|
libxml \
|
54
|
mbstring \
|
55
|
mhash \
|
56
|
mysql \
|
57
|
openssl \
|
58
|
pcntl \
|
59
|
pcre \
|
60
|
posix \
|
61
|
readline \
|
62
|
Reflection \
|
63
|
session \
|
64
|
shmop \
|
65
|
standard \
|
66
|
suhosin \
|
67
|
sysvmsg \
|
68
|
sysvsem \
|
69
|
sysvshm \
|
70
|
sqlite \
|
71
|
tokenizer \
|
72
|
uploadprogress \
|
73
|
xml \
|
74
|
zlib"
|
75
|
|
76
|
# Get a loaded module list in the stock php
|
77
|
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
|
|
85
|
# 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
|
; File generated from /etc/rc.php_ini_setup
|
90
|
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
|
upload_tmp_dir = ${UPLOADTMPDIR}
|
99
|
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
|
extension_dir=${EXTENSIONSDIR}
|
107
|
|
108
|
; Extensions
|
109
|
EOF
|
110
|
|
111
|
# 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
|
# Check to see if module is compiled into php statically
|
116
|
for LM in $LOADED_MODULES; do
|
117
|
if [ "$EXT" = "$LM" ]; then
|
118
|
SHOULDADD="false"
|
119
|
fi
|
120
|
done
|
121
|
if [ "$SHOULDADD" = "true" ]; then
|
122
|
# Ensure extension exists before adding.
|
123
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
124
|
echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
|
125
|
fi
|
126
|
fi
|
127
|
done
|
128
|
|
129
|
# Get amount of ram installed on this system
|
130
|
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
|
131
|
export RAM
|
132
|
if [ $RAM -gt 96 ]; then
|
133
|
|
134
|
cat >>/usr/local/lib/php.ini <<EOF
|
135
|
|
136
|
; APC Settings
|
137
|
apc.enabled="1"
|
138
|
apc.enable_cli="1"
|
139
|
apc.shm_size="${APCSHMEMSIZE}"
|
140
|
|
141
|
EOF
|
142
|
|
143
|
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
|
fi
|
149
|
|
150
|
# Copy php.ini file to etc/ too (cli)
|
151
|
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
|
152
|
|
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
|
|
181
|
|