Skip to content

Commit c00e7d3

Browse files
authored
add $var for php fpm dir (#971)
1 parent 6d9fc07 commit c00e7d3

4 files changed

+29
-28
lines changed

lib.sh

+13-12
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ HTTPS_CONF="/etc/apache2/sites-available/$SUBDOMAIN.conf"
8686
HTTP2_CONF="/etc/apache2/mods-available/http2.conf"
8787
# PHP-FPM
8888
PHPVER=7.2
89-
PHP_INI=/etc/php/$PHPVER/fpm/php.ini
90-
PHP_POOL_DIR=/etc/php/$PHPVER/fpm/pool.d
89+
PHP_FPM_DIR=/etc/php/$PHPVER/fpm
90+
PHP_INI=$PHP_FPM/php.ini
91+
PHP_POOL_DIR=$PHP_FPM/pool.d
9192
# Adminer
9293
ADMINERDIR=/usr/share/adminer
9394
ADMINER_CONF=/etc/apache2/conf-available/adminer.conf
@@ -297,9 +298,9 @@ min_start_servers=20
297298
min_max_spare_servers=35
298299

299300
# Calculate the sum of the current values
300-
CURRENT_START="$(grep pm.start_servers $PHP_POOL_DIR/nextcloud.conf | awk '{ print $3}')"
301-
CURRENT_MAX="$(grep pm.max_spare_servers $PHP_POOL_DIR/nextcloud.conf | awk '{ print $3}')"
302-
CURRENT_MIN="$(grep pm.min_spare_servers $PHP_POOL_DIR/nextcloud.conf | awk '{ print $3}')"
301+
CURRENT_START="$(grep pm.start_servers "$PHP_POOL_DIR"/nextcloud.conf | awk '{ print $3}')"
302+
CURRENT_MAX="$(grep pm.max_spare_servers "$PHP_POOL_DIR"/nextcloud.conf | awk '{ print $3}')"
303+
CURRENT_MIN="$(grep pm.min_spare_servers "$PHP_POOL_DIR"/nextcloud.conf | awk '{ print $3}')"
303304
CURRENT_SUM="$((CURRENT_START + CURRENT_MAX + CURRENT_MIN))"
304305

305306
# Calculate max_children depending on RAM
@@ -331,17 +332,17 @@ The installation was not successful, sorry for the inconvenience.
331332
If you think this is a bug, please report it to $ISSUES"
332333
exit 1
333334
else
334-
check_command sed -i "s|pm.max_children.*|pm.max_children = $PHP_FPM_MAX_CHILDREN|g" $PHP_POOL_DIR/nextcloud.conf
335+
check_command sed -i "s|pm.max_children.*|pm.max_children = $PHP_FPM_MAX_CHILDREN|g" "$PHP_POOL_DIR"/nextcloud.conf
335336
print_text_in_color "$IGreen" "pm.max_children was set to $PHP_FPM_MAX_CHILDREN"
336337
# Check if the sum of all the current values are more than $PHP_FPM_MAX_CHILDREN and only continue it is
337338
if [ $PHP_FPM_MAX_CHILDREN -gt $CURRENT_SUM ]
338339
then
339340
# Set pm.max_spare_servers
340341
if [ $PHP_FPM_MAX_CHILDREN -ge $min_max_spare_servers ]
341342
then
342-
if [ "$(grep pm.start_servers $PHP_POOL_DIR/nextcloud.conf | awk '{ print $3}')" -lt $min_start_servers ]
343+
if [ "$(grep pm.start_servers "$PHP_POOL_DIR"/nextcloud.conf | awk '{ print $3}')" -lt $min_start_servers ]
343344
then
344-
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = $((PHP_FPM_MAX_CHILDREN - 30))|g" $PHP_POOL_DIR/nextcloud.conf
345+
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = $((PHP_FPM_MAX_CHILDREN - 30))|g" "$PHP_POOL_DIR"/nextcloud.conf
345346
print_text_in_color "$IGreen" "pm.max_spare_servers was set to $((PHP_FPM_MAX_CHILDREN - 30))"
346347
fi
347348
fi
@@ -351,10 +352,10 @@ fi
351352
# If $PHP_FPM_MAX_CHILDREN is lower than the current sum of all values, revert to default settings
352353
if [ $PHP_FPM_MAX_CHILDREN -lt $CURRENT_SUM ]
353354
then
354-
check_command sed -i "s|pm.max_children.*|pm.max_children = $PHP_FPM_MAX_CHILDREN|g" $PHP_POOL_DIR/nextcloud.conf
355-
check_command sed -i "s|pm.start_servers.*|pm.start_servers = 3|g" $PHP_POOL_DIR/nextcloud.conf
356-
check_command sed -i "s|pm.min_spare_servers.*|pm.min_spare_servers = 2|g" $PHP_POOL_DIR/nextcloud.conf
357-
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = 3|g" $PHP_POOL_DIR/nextcloud.conf
355+
check_command sed -i "s|pm.max_children.*|pm.max_children = $PHP_FPM_MAX_CHILDREN|g" "$PHP_POOL_DIR"/nextcloud.conf
356+
check_command sed -i "s|pm.start_servers.*|pm.start_servers = 3|g" "$PHP_POOL_DIR"/nextcloud.conf
357+
check_command sed -i "s|pm.min_spare_servers.*|pm.min_spare_servers = 2|g" "$PHP_POOL_DIR"/nextcloud.conf
358+
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = 3|g" "$PHP_POOL_DIR"/nextcloud.conf
358359
print_text_in_color "$ICyan" "All PHP-INI values were set back to default values as the value for pm.max_children ($PHP_FPM_MAX_CHILDREN) was lower than the sum of all the current values ($CURRENT_SUM)"
359360
print_text_in_color "$ICyan" "Please run this again to set optimal values"
360361
fi

nextcloud-startup-script.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,10 @@ restart_webserver
537537
if home_sme_server
538538
then
539539
# Add specific values to PHP-FPM based on 16 GB RAM
540-
check_command sed -i "s|pm.max_children.*|pm.max_children = 307|g" $PHP_POOL_DIR/nextcloud.conf
541-
check_command sed -i "s|pm.start_servers.*|pm.start_servers = 30|g" $PHP_POOL_DIR/nextcloud.conf
542-
check_command sed -i "s|pm.min_spare_servers.*|pm.min_spare_servers = 20|g" $PHP_POOL_DIR/nextcloud.conf
543-
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = 257|g" $PHP_POOL_DIR/nextcloud.conf
540+
check_command sed -i "s|pm.max_children.*|pm.max_children = 307|g" "$PHP_POOL_DIR"/nextcloud.conf
541+
check_command sed -i "s|pm.start_servers.*|pm.start_servers = 30|g" "$PHP_POOL_DIR"/nextcloud.conf
542+
check_command sed -i "s|pm.min_spare_servers.*|pm.min_spare_servers = 20|g" "$PHP_POOL_DIR"/nextcloud.conf
543+
check_command sed -i "s|pm.max_spare_servers.*|pm.max_spare_servers = 257|g" "$PHP_POOL_DIR"/nextcloud.conf
544544
restart_webserver
545545
else
546546
# Calculate the values of PHP-FPM based on the amount of RAM available (minimum 2 GB or 8 children)

nextcloud_install_production.sh

+11-11
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ a2enmod http2
295295
restart_webserver
296296

297297
# Set up a php-fpm pool with a unixsocket
298-
cat << POOL_CONF > "$PHP_POOL_DIR/nextcloud.conf"
298+
cat << POOL_CONF > "$PHP_POOL_DIR"/nextcloud.conf
299299
[Nextcloud]
300300
user = www-data
301301
group = www-data
@@ -321,7 +321,7 @@ php_admin_value [cgi.fix_pathinfo] = 1
321321
POOL_CONF
322322

323323
# Disable the idling example pool.
324-
mv $PHP_POOL_DIR/www.conf $PHP_POOL_DIR/www.conf.backup
324+
mv "$PHP_POOL_DIR"/www.conf "$PHP_POOL_DIR"/www.conf.backup
325325

326326
# Enable the new php-fpm config
327327
restart_webserver
@@ -375,15 +375,15 @@ crontab -u www-data -l | { cat; echo "*/5 * * * * php -f $NCPATH/cron.php >
375375

376376
# Change values in php.ini (increase max file size)
377377
# max_execution_time
378-
sed -i "s|max_execution_time =.*|max_execution_time = 3500|g" $PHP_INI
378+
sed -i "s|max_execution_time =.*|max_execution_time = 3500|g" "$PHP_INI"
379379
# max_input_time
380-
sed -i "s|max_input_time =.*|max_input_time = 3600|g" $PHP_INI
380+
sed -i "s|max_input_time =.*|max_input_time = 3600|g" "$PHP_INI"
381381
# memory_limit
382-
sed -i "s|memory_limit =.*|memory_limit = 512M|g" $PHP_INI
382+
sed -i "s|memory_limit =.*|memory_limit = 512M|g" "$PHP_INI"
383383
# post_max
384-
sed -i "s|post_max_size =.*|post_max_size = 1100M|g" $PHP_INI
384+
sed -i "s|post_max_size =.*|post_max_size = 1100M|g" "$PHP_INI"
385385
# upload_max
386-
sed -i "s|upload_max_filesize =.*|upload_max_filesize = 1000M|g" $PHP_INI
386+
sed -i "s|upload_max_filesize =.*|upload_max_filesize = 1000M|g" "$PHP_INI"
387387

388388
# Set loggging
389389
occ_command config:system:set log_type --value=file
@@ -424,7 +424,7 @@ echo "opcache.memory_consumption=256"
424424
echo "opcache.save_comments=1"
425425
echo "opcache.revalidate_freq=1"
426426
echo "opcache.validate_timestamps=1"
427-
} >> $PHP_INI
427+
} >> "$PHP_INI"
428428

429429
# PHP-FPM optimization
430430
# https://geekflare.com/php-fpm-optimization/
@@ -442,7 +442,7 @@ echo "pgsql.max_persistent = -1"
442442
echo "pgsql.max_links = -1"
443443
echo "pgsql.ignore_notice = 0"
444444
echo "pgsql.log_notice = 0"
445-
} >> /etc/php/$PHPVER/fpm/conf.d/20-pdo_pgsql.ini
445+
} >> "$PHP_FPM_DIR"/conf.d/20-pdo_pgsql.ini
446446

447447
# Install Redis (distrubuted cache)
448448
run_static_script redis-server-ubuntu
@@ -463,7 +463,7 @@ echo "# igbinary for PHP"
463463
echo "extension=igbinary.so"
464464
echo "session.serialize_handler=igbinary"
465465
echo "igbinary.compact_strings=On"
466-
} >> $PHP_INI
466+
} >> "$PHP_INI"
467467
restart_webserver
468468
fi
469469

@@ -494,7 +494,7 @@ echo "apc.use_request_time=1"
494494
echo "apc.serializer=igbinary"
495495
echo "apc.coredump_unmap=0"
496496
echo "apc.preload_path"
497-
} >> $PHP_INI
497+
} >> "$PHP_INI"
498498
restart_webserver
499499
fi
500500

static/redis-server-ubuntu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ install_if_not redis-server
3838

3939
# Setting direct to PHP-FPM as it's installed with PECL (globally doesn't work)
4040
print_text_in_color "$ICyan" "Adding extension=redis.so to $PHP_INI..."
41-
echo 'extension=redis.so' >> $PHP_INI
41+
echo 'extension=redis.so' >> "$PHP_INI"
4242

4343
# Prepare for adding redis configuration
4444
sed -i "s|);||g" $NCPATH/config/config.php

0 commit comments

Comments
 (0)