#!/bin/bash
#Filename: php_optimize.sh

PHP_INI_FILE=$(php -i|grep "Loaded Configuration File"|awk '{print $5}')

function IS_ROOT() {
	if [[ $(id -u) -ne 0 ]]; then
			echo "Run as root role"
			exit 1;
	fi
}

function Modify() {

	# php extensions
	sed -i 's#output_buffering = Off#output_buffering = On#' ${PHP_INI_FILE}
	sed -i 's/post_max_size = 8M/post_max_size = 20M/g' ${PHP_INI_FILE}
	sed -i 's/expose_php = On/expose_php = Off/g' ${PHP_INI_FILE}
	sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 30M/g' ${PHP_INI_FILE}
	sed -i 's/;date.timezone =/date.timezone = PRC/g' ${PHP_INI_FILE}
	sed -i 's/short_open_tag = Off/short_open_tag = On/g' ${PHP_INI_FILE}
	sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${PHP_INI_FILE}
	sed -i 's/max_execution_time = 30/max_execution_time = 300/g' ${PHP_INI_FILE}
	sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' ${PHP_INI_FILE}

}

IS_ROOT
Modify
