PHP 7.3 brought significant performance improvements, bug fixes, and new features to web development. This comprehensive guide walks you through the complete process of upgrading PHP to version 7.3 on Debian 9 and Debian 8 systems.
Before starting this upgrade process, ensure your applications are compatible with PHP 7.3. This version deprecated several functions and changed certain behaviors that might affect older codebases.
Prerequisites and System Preparation
Start by updating your Debian system to ensure all packages are current. This prevents potential conflicts during the PHP installation process.
sudo apt update
sudo apt upgrade -yCheck your current PHP version to understand what you\'re upgrading from:
php -vIf you\'re running a VPS server, ensure you have sufficient disk space and backup your current configuration before proceeding.
Adding the Sury PHP Repository
Debian\'s default repositories don\'t always include the latest PHP versions. The Sury repository provides updated PHP packages for Debian systems.
Install the required packages for repository management:
sudo apt -y install lsb-release apt-transport-https ca-certificates wgetAdd the GPG key for the Sury repository:
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpgAdd the repository to your system\'s sources list:
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.listInstalling PHP 7.3
Update your package list to include the new repository:
sudo apt updateInstall PHP 7.3 with essential modules:
sudo apt install php7.3 php7.3-cli php7.3-common php7.3-curl php7.3-mbstring php7.3-mysql php7.3-xmlFor web hosting environments, you\'ll also need the Apache or Nginx module:
# For Apache
sudo apt install php7.3-fpm libapache2-mod-php7.3
# For Nginx
sudo apt install php7.3-fpmConfiguring Multiple PHP Versions
If you need to maintain multiple PHP versions, use the update-alternatives system to manage them:
sudo update-alternatives --install /usr/bin/php php /usr/bin/php7.3 73
sudo update-alternatives --config phpThis allows you to switch between PHP versions easily. Select the desired version from the interactive menu.
Essential PHP Extensions
Install commonly required extensions for modern web development:
sudo apt install php7.3-gd php7.3-json php7.3-zip php7.3-intl php7.3-bcmath php7.3-soapFor database connectivity:
sudo apt install php7.3-pgsql php7.3-sqlite3 php7.3-redisVerifying the Installation
Confirm PHP 7.3 is properly installed and configured:
php -vExpected output should show:
PHP 7.3.29-1+0~20210701.86+debian9~1.gbp7ad6eb (cli) (built: Jul 1 2021 16:11:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.29-1+0~20210701.86+debian9~1.gbp7ad6eb, Copyright (c) 1999-2018, by Zend TechnologiesCheck loaded extensions:
php -mWeb Server Configuration
Restart your web server to load the new PHP version:
# For Apache
sudo systemctl restart apache2
# For Nginx with PHP-FPM
sudo systemctl restart nginx
sudo systemctl restart php7.3-fpmCreate a test file to verify web functionality:
Performance Optimization
PHP 7.3 includes OPcache by default, but you should configure it for optimal performance. Edit the OPcache configuration:
sudo nano /etc/php/7.3/cli/conf.d/10-opcache.iniRecommended OPcache settings:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2Troubleshooting Common Issues
If you encounter permission errors, check file ownership:
sudo chown -R www-data:www-data /var/www/htmlFor memory limit issues, edit php.ini:
sudo nano /etc/php/7.3/apache2/php.iniIncrease the memory limit:
memory_limit = 256MSecurity Considerations
Remove or disable unused PHP extensions to reduce attack surface. Review your php.ini security settings:
expose_php = Off
allow_url_fopen = Off
allow_url_include = OffKeep your PHP installation updated with security patches by running regular system updates.
Comments
0Sign in to leave a comment
Sign inSé el primero en comentar