Refactor CyberPanel installation logic to streamline PHP version handling

- Removed local installation function in favor of a direct installation approach.
- Updated installation script to prioritize the development branch for downloading CyberPanel, with a fallback to stable if unavailable.
- Adjusted PHP version lists across various scripts to exclude PHP 8.6 and ensure compatibility with existing versions.
- Enhanced error handling and feedback during installation to improve user experience.
This commit is contained in:
Master3395
2025-10-16 22:34:18 +02:00
parent 293550c588
commit 05bcb46fd6
5 changed files with 48 additions and 116 deletions

View File

@@ -572,31 +572,6 @@ cleanup_existing_cyberpanel() {
echo " ✅ Cleanup completed" echo " ✅ Cleanup completed"
} }
# Function to install CyberPanel from local repository
install_cyberpanel_local() {
echo " 🔄 Using local CyberPanel repository..."
# Check if we're running from a cloned repository
if [ -d "install" ] && [ -f "install/install.py" ]; then
echo " ✓ Found local installation files"
echo " 🔄 Starting CyberPanel installation from local repository..."
echo ""
# Run the Python installer directly
if [ "$DEBUG_MODE" = true ]; then
python3 install/install.py --debug
else
python3 install/install.py
fi
return $?
else
echo " ⚠️ Local installation files not found"
echo " 🔄 Falling back to download method..."
install_cyberpanel_direct
fi
}
# Function to install CyberPanel directly using the working method # Function to install CyberPanel directly using the working method
install_cyberpanel_direct() { install_cyberpanel_direct() {
echo " 🔄 Downloading CyberPanel installation files..." echo " 🔄 Downloading CyberPanel installation files..."
@@ -636,20 +611,15 @@ install_cyberpanel_direct() {
# Download the working CyberPanel installation files # Download the working CyberPanel installation files
echo "Downloading from: https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh" echo "Downloading from: https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh"
# Default to stable branch, but use development if BRANCH_NAME is set # Try development branch first, fallback to stable
local installer_url="https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh" local installer_url="https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/cyberpanel.sh"
# If BRANCH_NAME is set to v2.5.5-dev, try to use it # Test if the development branch exists
if [ "$BRANCH_NAME" = "v2.5.5-dev" ]; then if ! curl -s --head "$installer_url" | grep -q "200 OK"; then
echo " Attempting to use development branch (v2.5.5-dev)..."
if curl -s -f -o /dev/null "https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/README.md"; then
echo " Using development branch (v2.5.5-dev)"
installer_url="https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/cyberpanel.sh"
else
echo " Development branch not available, falling back to stable" echo " Development branch not available, falling back to stable"
fi installer_url="https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh"
else else
echo " Using stable branch" echo " Using development branch (v2.5.5-dev)"
fi fi
curl --silent -o cyberpanel_installer.sh "$installer_url" 2>/dev/null curl --silent -o cyberpanel_installer.sh "$installer_url" 2>/dev/null
@@ -662,9 +632,9 @@ install_cyberpanel_direct() {
# Download the install directory # Download the install directory
echo "Downloading installation files..." echo "Downloading installation files..."
local archive_url="https://github.com/usmannasir/cyberpanel/archive/stable.tar.gz" local archive_url="https://github.com/usmannasir/cyberpanel/archive/v2.5.5-dev.tar.gz"
if [ "$BRANCH_NAME" = "v2.5.5-dev" ] && [ "$installer_url" = "https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/cyberpanel.sh" ]; then if [ "$installer_url" = "https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh" ]; then
archive_url="https://github.com/usmannasir/cyberpanel/archive/v2.5.5-dev.tar.gz" archive_url="https://github.com/usmannasir/cyberpanel/archive/stable.tar.gz"
fi fi
curl --silent -L -o install_files.tar.gz "$archive_url" 2>/dev/null curl --silent -L -o install_files.tar.gz "$archive_url" 2>/dev/null
@@ -681,12 +651,12 @@ install_cyberpanel_direct() {
fi fi
# Copy install directory to current location # Copy install directory to current location
if [ "$BRANCH_NAME" = "v2.5.5-dev" ] && [ "$installer_url" = "https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.5.5-dev/cyberpanel.sh" ]; then if [ "$installer_url" = "https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/cyberpanel.sh" ]; then
cp -r cyberpanel-v2.5.5-dev/install . 2>/dev/null || true
cp -r cyberpanel-v2.5.5-dev/install.sh . 2>/dev/null || true
else
cp -r cyberpanel-stable/install . 2>/dev/null || true cp -r cyberpanel-stable/install . 2>/dev/null || true
cp -r cyberpanel-stable/install.sh . 2>/dev/null || true cp -r cyberpanel-stable/install.sh . 2>/dev/null || true
else
cp -r cyberpanel-v2.5.5-dev/install . 2>/dev/null || true
cp -r cyberpanel-v2.5.5-dev/install.sh . 2>/dev/null || true
fi fi
echo " ✓ CyberPanel installation files downloaded" echo " ✓ CyberPanel installation files downloaded"
@@ -727,9 +697,9 @@ install_cyberpanel_direct() {
# Run installer and show live output, capturing the password # Run installer and show live output, capturing the password
if [ "$DEBUG_MODE" = true ]; then if [ "$DEBUG_MODE" = true ]; then
./cyberpanel_installer.sh --debug --branch "$BRANCH_NAME" 2>&1 | tee /var/log/CyberPanel/install_output.log ./cyberpanel_installer.sh --debug 2>&1 | tee /var/log/CyberPanel/install_output.log
else else
./cyberpanel_installer.sh --branch "$BRANCH_NAME" 2>&1 | tee /var/log/CyberPanel/install_output.log ./cyberpanel_installer.sh 2>&1 | tee /var/log/CyberPanel/install_output.log
fi fi
local install_exit_code=${PIPESTATUS[0]} local install_exit_code=${PIPESTATUS[0]}
@@ -2035,14 +2005,7 @@ start_reinstall() {
# Install CyberPanel # Install CyberPanel
echo "Step 5/6: Installing CyberPanel..." echo "Step 5/6: Installing CyberPanel..."
# Try local installation first if available if ! install_cyberpanel; then
if [ -d "install" ] && [ -f "install/install.py" ]; then
install_cyberpanel_local
else
install_cyberpanel_direct
fi
if [ $? -ne 0 ]; then
print_status "ERROR: CyberPanel installation failed" print_status "ERROR: CyberPanel installation failed"
exit 1 exit 1
fi fi
@@ -2083,14 +2046,7 @@ start_installation() {
# Install CyberPanel # Install CyberPanel
echo "Step 3/6: Installing CyberPanel..." echo "Step 3/6: Installing CyberPanel..."
# Try local installation first if available if ! install_cyberpanel; then
if [ -d "install" ] && [ -f "install/install.py" ]; then
install_cyberpanel_local
else
install_cyberpanel_direct
fi
if [ $? -ne 0 ]; then
print_status "ERROR: CyberPanel installation failed" print_status "ERROR: CyberPanel installation failed"
echo "" echo ""
echo "Would you like to see troubleshooting help? (y/n) [y]: " echo "Would you like to see troubleshooting help? (y/n) [y]: "
@@ -2309,14 +2265,7 @@ main() {
install_dependencies install_dependencies
# Install CyberPanel # Install CyberPanel
# Try local installation first if available if ! install_cyberpanel; then
if [ -d "install" ] && [ -f "install/install.py" ]; then
install_cyberpanel_local
else
install_cyberpanel_direct
fi
if [ $? -ne 0 ]; then
print_status "ERROR: CyberPanel installation failed" print_status "ERROR: CyberPanel installation failed"
echo "" echo ""
echo "Would you like to see troubleshooting help? (y/n) [y]: " echo "Would you like to see troubleshooting help? (y/n) [y]: "

View File

@@ -4504,25 +4504,14 @@ milter_default_action = accept
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
# Install PHP 8.6
if not os.path.exists('/usr/local/lsws/lsphp86/bin/php'):
logging.InstallLog.writeToFile("[setupPHPSymlink] PHP 8.6 not found, ensuring it's installed...")
if self.distro == centos or self.distro == cent8 or self.distro == openeuler:
command = 'dnf install lsphp86 lsphp86-* -y --skip-broken --nobest'
else:
command = 'DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp86 lsphp86-*'
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
# Remove existing PHP symlink if it exists # Remove existing PHP symlink if it exists
if os.path.exists('/usr/bin/php'): if os.path.exists('/usr/bin/php'):
os.remove('/usr/bin/php') os.remove('/usr/bin/php')
# Create symlink to the best available PHP version # Create symlink to the best available PHP version
# Try to find and use the best available PHP version # Try to find and use the best available PHP version
# Priority: 86, 85, 84, 83, 82, 81, 80, 74 (newest to oldest, 7.4+ only for AlmaLinux 8+ compatibility) # Priority: 85 (beta), 84, 83, 82, 81, 80, 74 (newest to oldest)
php_versions = ['86', '85', '84', '83', '82', '81', '80', '74'] php_versions = ['85', '84', '83', '82', '81', '80', '74']
php_symlink_source = None php_symlink_source = None
for php_ver in php_versions: for php_ver in php_versions:
@@ -4572,8 +4561,8 @@ milter_default_action = accept
logging.InstallLog.writeToFile("[setup_lsphp_symlink] Removed existing lsphp file/symlink") logging.InstallLog.writeToFile("[setup_lsphp_symlink] Removed existing lsphp file/symlink")
# Try to find and use the best available PHP version # Try to find and use the best available PHP version
# Priority: 86, 85, 84, 83, 82, 81, 80, 74 (newest to oldest) # Priority: 85 (beta), 84, 83, 82, 81, 80, 74 (newest to oldest)
php_versions = ['86', '85', '84', '83', '82', '81', '80', '74'] php_versions = ['85', '84', '83', '82', '81', '80', '74']
lsphp_source = None lsphp_source = None
for php_ver in php_versions: for php_ver in php_versions:

View File

@@ -58,7 +58,7 @@ class PHPManager:
# Method 2: Check system-wide PHP installations # Method 2: Check system-wide PHP installations
try: try:
# Check for system PHP versions # Check for system PHP versions
system_php_versions = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6'] system_php_versions = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
for version in system_php_versions: for version in system_php_versions:
formatted_version = f'PHP {version}' formatted_version = f'PHP {version}'
if formatted_version not in finalPHPVersions: if formatted_version not in finalPHPVersions:
@@ -117,7 +117,7 @@ class PHPManager:
# Method 4: Fallback to checking common PHP versions # Method 4: Fallback to checking common PHP versions
if not finalPHPVersions: if not finalPHPVersions:
fallback_versions = ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5', 'PHP 8.6'] fallback_versions = ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5']
for version in fallback_versions: for version in fallback_versions:
try: try:
phpString = PHPManager.getPHPString(version) phpString = PHPManager.getPHPString(version)
@@ -145,12 +145,12 @@ class PHPManager:
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
logging.writeToFile(f'Final PHP versions found: {finalPHPVersions}') logging.writeToFile(f'Final PHP versions found: {finalPHPVersions}')
return finalPHPVersions if finalPHPVersions else ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5', 'PHP 8.6'] return finalPHPVersions if finalPHPVersions else ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5']
except BaseException as msg: except BaseException as msg:
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
logging.writeToFile(f'Error while finding php versions on system: {str(msg)}') logging.writeToFile(f'Error while finding php versions on system: {str(msg)}')
return ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5', 'PHP 8.6'] return ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5']
@staticmethod @staticmethod
def findApachePHPVersions(): def findApachePHPVersions():
@@ -222,7 +222,7 @@ class PHPManager:
except BaseException as msg: except BaseException as msg:
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
logging.writeToFile(f'Error while finding php versions on system: {str(msg)}') logging.writeToFile(f'Error while finding php versions on system: {str(msg)}')
return ['PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5', 'PHP 8.6'] return ['PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1', 'PHP 8.2', 'PHP 8.3', 'PHP 8.4', 'PHP 8.5']
@staticmethod @staticmethod
def getPHPString(phpVersion): def getPHPString(phpVersion):
@@ -338,7 +338,7 @@ class PHPManager:
return 'PHP 8.3' # Default recommendation return 'PHP 8.3' # Default recommendation
# Priority order for recommendations # Priority order for recommendations
recommended_order = ['PHP 8.3', 'PHP 8.2', 'PHP 8.4', 'PHP 8.5', 'PHP 8.6', 'PHP 8.1', 'PHP 8.0', 'PHP 7.4'] recommended_order = ['PHP 8.3', 'PHP 8.2', 'PHP 8.4', 'PHP 8.5', 'PHP 8.1', 'PHP 8.0', 'PHP 7.4']
for recommended in recommended_order: for recommended in recommended_order:
if recommended in all_versions: if recommended in all_versions:

View File

@@ -373,12 +373,6 @@ class phpUtilities:
ubuntuPHP = 'php8.5' ubuntuPHP = 'php8.5'
phpPath = ApacheVhost.DecidePHPPath('86', virtualHostName)
if os.path.exists(phpPath):
centOSPHP = 'php86'
ubuntuPHP = 'php8.6'
###### ######

View File

@@ -3630,16 +3630,19 @@ echo $oConfig->Save() ? 'Done' : 'Error';
content = f.read() content = f.read()
if 'release 9' in content or 'release 10' in content: if 'release 9' in content or 'release 10' in content:
Upgrade.stdOut("AlmaLinux 9+ detected - checking available PHP versions", 1) Upgrade.stdOut("AlmaLinux 9+ detected - checking available PHP versions", 1)
# AlmaLinux 9+ and 8+ only support PHP 7.4+ # AlmaLinux 9+ doesn't have PHP 7.1, 7.2, 7.3
php_versions = ['74', '80', '81', '82', '83', '84', '85', '86'] php_versions = ['74', '80', '81', '82', '83', '84', '85']
else: else:
php_versions = ['74', '80', '81', '82', '83', '84', '85', '86'] php_versions = ['71', '72', '73', '74', '80', '81', '82', '83', '84', '85']
except: except:
php_versions = ['74', '80', '81', '82', '83', '84', '85', '86'] php_versions = ['71', '72', '73', '74', '80', '81', '82', '83', '84', '85']
else: else:
# Check other OS versions - all modern systems support PHP 7.4+ # Check other OS versions
os_info = Upgrade.findOperatingSytem() os_info = Upgrade.findOperatingSytem()
php_versions = ['74', '80', '81', '82', '83', '84', '85', '86'] if os_info in [Ubuntu24, CENTOS8, Debian13]:
php_versions = ['74', '80', '81', '82', '83', '84', '85']
else:
php_versions = ['71', '72', '73', '74', '80', '81', '82', '83', '84', '85']
# Check availability of each version # Check availability of each version
available_versions = [] available_versions = []
@@ -4116,8 +4119,8 @@ echo $oConfig->Save() ? 'Done' : 'Error';
package_list = f"lsphp{version} " + " ".join([f"lsphp{version}-{ext}" for ext in extensions]) package_list = f"lsphp{version} " + " ".join([f"lsphp{version}-{ext}" for ext in extensions])
command = f"yum install -y {package_list}" command = f"yum install -y {package_list}"
Upgrade.executioner(command, f'Install PHP {version}', 0) Upgrade.executioner(command, f'Install PHP {version}', 0)
elif version in ['80', '81', '82', '83', '84', '85', '86']: elif version in ['80', '81', '82', '83', '84', '85']:
# PHP 8.x versions (including 8.5 and 8.6) # PHP 8.x versions (including 8.5 beta)
if Upgrade.installedOutput.find(f'lsphp{version}') == -1: if Upgrade.installedOutput.find(f'lsphp{version}') == -1:
command = f"yum install lsphp{version}* -y" command = f"yum install lsphp{version}* -y"
subprocess.call(command, shell=True) subprocess.call(command, shell=True)
@@ -4152,9 +4155,6 @@ echo $oConfig->Save() ? 'Done' : 'Error';
command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp85*' command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp85*'
os.system(command) os.system(command)
command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp86*'
os.system(command)
CentOSPath = '/etc/redhat-release' CentOSPath = '/etc/redhat-release'
openEulerPath = '/etc/openEuler-release' openEulerPath = '/etc/openEuler-release'
@@ -4726,8 +4726,8 @@ slowlog = /var/log/php{version}-fpm-slow.log
This ensures that ImunifyAV/Imunify360 installation will work properly. This ensures that ImunifyAV/Imunify360 installation will work properly.
""" """
try: try:
# Define all possible PHP versions (7.4+ for AlmaLinux 8+ compatibility) # Define all possible PHP versions
php_versions = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6'] php_versions = ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
restarted_count = 0 restarted_count = 0
total_count = 0 total_count = 0
@@ -4774,8 +4774,8 @@ slowlog = /var/log/php{version}-fpm-slow.log
def setupPHPSymlink(): def setupPHPSymlink():
try: try:
# Try to find available PHP version (prioritize modern stable versions) # Try to find available PHP version (prioritize modern stable versions)
# Priority: 8.3 (recommended), 8.2, 8.6, 8.5, 8.4, 8.1, 8.0, 7.4 (AlmaLinux 8+ compatible only) # Priority: 8.3 (recommended), 8.2, 8.4, 8.5, 8.1, 8.0, then older versions
php_versions = ['83', '82', '86', '85', '84', '81', '80', '74'] php_versions = ['83', '82', '84', '85', '81', '80', '74', '73', '72', '71']
selected_php = None selected_php = None
for version in php_versions: for version in php_versions:
@@ -4995,8 +4995,8 @@ slowlog = /var/log/php{version}-fpm-slow.log
except: except:
pass pass
# Try to find available PHP binary in order of preference (modern stable first, AlmaLinux 8+ compatible) # Try to find available PHP binary in order of preference (modern stable first)
php_versions = ['83', '82', '86', '85', '84', '81', '80', '74'] php_versions = ['83', '82', '84', '85', '81', '80', '74', '73', '72', '71']
php_binary_found = False php_binary_found = False
for version in php_versions: for version in php_versions: