From 3b8160be783cbdd4dcabf51a792016a9a54b5dec Mon Sep 17 00:00:00 2001 From: WhatTheServer Date: Mon, 7 Sep 2020 08:52:40 -0400 Subject: [PATCH] Create setup_php_sessions.sh --- CPScripts/setup_php_sessions.sh | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 CPScripts/setup_php_sessions.sh diff --git a/CPScripts/setup_php_sessions.sh b/CPScripts/setup_php_sessions.sh new file mode 100644 index 000000000..4e00e2868 --- /dev/null +++ b/CPScripts/setup_php_sessions.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +## Author: Michael Ramsey +## Objective Fix session issues on CyberPanel and standardized session paths. +# Fixes #430 +# https://github.com/usmannasir/cyberpanel/issues/430 + + +# Create the session path directories and chmod it for security to 1733 like the existing one is. +mkdir -p /var/lib/lsphp/session/lsphp{53,54,55,56,70,71,72,73,74} +chmod -R 1733 /var/lib/lsphp/session/lsphp{53,54,55,56,70,71,72,73,74} + + +YUM_CMD=$(which yum) +APT_GET_CMD=$(which apt-get) + +if [[ -n $YUM_CMD ]]; then + # Centos + for version in $(ls /usr/local/lsws|grep lsphp); do echo ""; echo "PHP $version"; sed -i -e "s|^;session.save_path.*|session.save_path = '/var/lib/lsphp/session/${version}'|g" -e "s|^session.save_path.*|session.save_path = '/var/lib/lsphp/session/${version}'|g" /usr/local/lsws/${version}/etc/php.ini; /usr/local/lsws/${version}/bin/php -i |grep -Ei 'date.timezone' && echo "" ; done; service lsws restart; killall lsphp; + + + + +elif [[ -n $APT_GET_CMD ]]; then + # Ubuntu + for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed 's/lsphp//g') ; do echo ""; echo "LSPHP $phpver" ; lsphpver=$(echo $phpver | sed 's/^\(.\{1\}\)/\1./'); sed -i -e "s|^;session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp${phpver}'|g" -e "s|^session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp${phpver}'|g" /usr/local/lsws/lsphp${phpver}/etc/php/${lsphpver}/litespeed/php.ini ; /usr/local/lsws/lsphp${phpver}/bin/php -i |grep -Ei 'session.save_path' && echo "" ; done; service lsws restart; killall lsphp; + +else + echo "error can't install required packages. Unsupported OS" + exit 1; +fi + + +# Setup a cron to clear stuff older then session.gc_maxlifetime currently set in the php.ini for each version + +# Create cron file if missing. +if [[ ! -e /usr/local/CyberCP/bin/cleansessions ]]; then + touch /usr/local/CyberCP/bin/cleansessions + chmod +x /usr/local/CyberCP/bin/cleansessions + cat >> /usr/local/CyberCP/bin/cleansessions <