When maintaining legacy Debian Wheezy (7.x) servers, you might encounter situations where you need PHP 5.6 features but are stuck with the default PHP 5.4 packages. The standard Debian repositories don't provide PHP 5.6 for Wheezy, requiring alternative approaches.
First, ensure your system is up-to-date:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
The repository configuration in your original attempt might be incomplete. Here's the proper way to add Dotdeb for PHP 5.6:
sudo echo "deb http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list
sudo echo "deb-src http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list
Many users miss this critical step:
wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
rm dotdeb.gpg
With the repository properly configured, you can now upgrade PHP:
sudo apt-get update
sudo apt-get install php5 php5-cli php5-common php5-curl php5-gd \
php5-mysql php5-mcrypt php5-xmlrpc php5-xsl
After installation, check your PHP version:
php -v
You should see output similar to:
PHP 5.6.x (cli) (built: [date])
If you encounter dependency problems, try:
sudo apt-get -f install
For conflicting packages, you might need to remove them first:
sudo apt-get remove php5-common
Don't forget to adjust your php.ini settings. The new location might be:
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
For Apache users, restart the service:
sudo service apache2 restart
Before proceeding, verify your current PHP version:
php -v
# Expected output for Debian 7:
# PHP 5.4.39-0+deb7u2 (cli)
First, import Dotdeb's GPG key:
wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
Then modify your /etc/apt/sources.list
:
# PHP 5.6 repository for Wheezy
deb http://packages.dotdeb.org wheezy-php56 all
deb-src http://packages.dotdeb.org wheezy-php56 all
# Optional: Add main Dotdeb repository for other packages
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
Update package lists and install PHP 5.6:
sudo apt-get update
sudo apt-get install php5 php5-cli php5-common php5-mysql
For a complete upgrade, you might need to specify additional modules:
sudo apt-get install php5-curl php5-gd php5-json php5-mcrypt php5-xmlrpc
Check the new PHP version:
php -v
# Should now show:
# PHP 5.6.x (cli) (built: ...)
If you encounter dependency conflicts:
sudo apt-get -f install
sudo apt-get dist-upgrade
For web server integration (Apache example):
sudo apt-get install libapache2-mod-php5
sudo service apache2 restart
Compare your old php.ini with new defaults:
sudo cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
sudo nano /etc/php5/apache2/php.ini
- Test all PHP applications for compatibility
- Review error logs:
tail -f /var/log/apache2/error.log
- Check loaded modules:
php -m