Skip to content

Instantly share code, notes, and snippets.

@gustavomcarmo
Created July 18, 2018 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavomcarmo/327038e0c4034da4b7324ecc1182169b to your computer and use it in GitHub Desktop.
Save gustavomcarmo/327038e0c4034da4b7324ecc1182169b to your computer and use it in GitHub Desktop.
Shell script to define the post_max_size and the upload_max_filesize values in the php.ini file.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "One parameter expected:"
echo "- the new size limit (in Mb)"
exit 1
fi
SIZE_IN_MB=$1
if [[ ! $SIZE_IN_MB =~ ^[0-9]+$ || $SIZE_IN_MB -eq 0 ]]; then
echo "$SIZE_IN_MB is not a positive integer"
exit 1
fi
setValue()
{
PHP_PARAM=$1
sed -ri 's/^('$PHP_PARAM' = ).*$/\1'$SIZE_IN_MB'M/1' /etc/php/7.2/apache2/php.ini
if [ $? -ne 0 ]; then
echo "Error on setting the $PHP_PARAM value"
exit 1
fi
echo "Parameter $PHP_PARAM set to $SIZE_IN_MB"
}
setValue "post_max_size"
setValue "upload_max_filesize"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment