Skip to content

Instantly share code, notes, and snippets.

@othercodes
Created April 15, 2019 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save othercodes/cf88b8a8fe369fd691574dc6a28491c2 to your computer and use it in GitHub Desktop.
Save othercodes/cf88b8a8fe369fd691574dc6a28491c2 to your computer and use it in GitHub Desktop.
Reconfigure the Apache Mod PHP.
#!/usr/bin/env bash
#
# PHP Mod Apache Installer (RH)
#
# Reconfigure the Apache Mod PHP.
#
# Tested on CentOS Linux release 7.5.1804 (Core)
#
# Execution:
# $ sudo ./morphpeus.sh
#
# You can also move the script into the /usr/bin directory
# $ mv morphpeus.sh /usr/bin/morphpeus
# $ chmod +x /usr/bin/morphpeus
# $ sudo morphpeus
#
# include the os release info to check the OS version
if [ "$EUID" -ne 0 ]; then
echo "PermissinonError: Please run as root or with sudo."
exit -1
fi
if [ ! -f /etc/os-release ]; then
echo "UndefinedOSError: Unable to determine the OS version."
exit -1
fi
source /etc/os-release
if [ $ID != "centos" ] && [ $VERSION_ID == 7 ]; then
echo "Unsupported OS version."
exit -1
fi
MORPHPEUS_VERSION=1.3.0
while getopts xirvh options; do
case $options in
v) echo "v${MORPHPEUS_VERSION}"
exit 0;;
?|h) printf "Choose and enable PHP Mod Default + RH + Remi\n\n"
printf "Usage: %s: [-h] [5.6|7.0|7.1|7.2|7.3 [rh|remi]]\n" $0
printf " -v Display current version.\n"
printf " -h Display help information.\n\n"
exit 2;;
esac
done
PHP_VER=${1:-7.2}
PHP_VEN=${2:-rh}
echo ""
echo "========================================================================================================================="
echo " MORPHPEUS: DEV FAST ENVIRONMENT AUTO SETUP SCRIPT (PHP RH 5.4, 7.0, 7.1 and 7.3)"
echo "========================================================================================================================"
echo "Disabling all the PHP modules."
for MOD_PHP in `find /etc/httpd/conf.d/ | grep -iE "php\.conf"`; do
mv ${MOD_PHP} ${MOD_PHP//.conf/.off}
done
echo "Disabling all the PHP module configuration."
for MOD_PHP_CFG in `find /etc/httpd/conf.modules.d/ | grep -iE "php\.conf"`; do
mv ${MOD_PHP_CFG} ${MOD_PHP_CFG//.conf/.off}
done
echo "Enabling Mod PHP: ${PHP_VER} ${PHP_VEN}."
case $PHP_VER in
5.4)
if [ -f /etc/httpd/conf.d/php.off ]; then
mv /etc/httpd/conf.d/php.off /etc/httpd/conf.d/php.conf
fi
if [ -f /etc/httpd/conf.modules.d/10-php.off ]; then
mv /etc/httpd/conf.modules.d/10-php.off /etc/httpd/conf.modules.d/10-php.conf
fi
;;
7.0|7.1|7.2|7.3)
case $PHP_VEN in
rh)
ln -s /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php${PHP_VER//./}-php.conf /etc/httpd/conf.d/
ln -s /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php${PHP_VER//./}-php.conf /etc/httpd/conf.modules.d/
;;
remi)
mv /etc/httpd/conf.d/php${PHP_VER//./}-php.off /etc/httpd/conf.d/php${PHP_VER//./}-php.conf
mv /etc/httpd/conf.modules.d/15-php${PHP_VER//./}-php.off /etc/httpd/conf.modules.d/15-php${PHP_VER//./}-php.conf
;;
esac
esac
if [ `apachectl -M 2>/dev/null | grep -iE "php[5|7]_module" | wc -l` -ge 1 ]; then
echo "> Enabled: "`apachectl -M 2>/dev/null | grep -m 1 -iE "php[5|7]_module" | cut -d ' ' -f 2`
else
echo "> Something has gone wrong, mod php is not being loaded, check it manually!"
fi
echo "Restarting Apache (httpd)"
systemctl restart httpd 2>/dev/null
echo "Done! have a nice day :D"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment