I’ve been using PHP 5.2 for a long time now. I’m not so apt towards change but PHP 5.3 has some cool features which I needed very much for my projects. So yesterday I decided to do that conversion. The process was not at all so simple and it took lots of googling and searching the forums, especially for removing the post-installation bugs. Finally, at Dec 27 12:45 AM I achieved 100% transformation to PHP 5.3. As my usual habit, I like documenting the stuff I do, so here it goes.
First thing before starting the process is to make sure that none of my existing projects would break. Because as the developers have said, PHP 5.3 is a major release with lots of changes. Many new features were added while many were removed or deprecated. And to avoid getting unnecessary warnings or notices, it was better to recheck my codes for compatibility with PHP 5.3. The PHP developers have written a good page in the PHP Manual which tells in detail about the things to take care of when migrating to 5.3 from 5.2. You can check it here : http://php.net/manual/en/migration53.php
So don’t forget to go through that page once, at the least the section which tells about the “removed and deprecated” features in PHP 5.3 and use the alternatives as suggested. Now you’re ready to upgrade. BUT, before that, you’ve to know that any software you use like phpMyAdmin or ldapPhpAdmin which uses PHP might broke. Well, you cannot do anything about it but you’ll have to reinstall them. Anyways, moving ahead, take a backup copy of your php.ini configuration file. You may need it for reconfiguring your PHP 5.3. If you’re using Apache 2, it can be found in /etc/php5/apache2/php.ini
Now, just run the following commands one by one,
wget http://us.archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb53_1.6.dfsg.4~beta1-5ubuntu2_i386.deb sudo dpkg -i libkrb53_1.6.dfsg.4~beta1-5ubuntu2_i386.deb wget http://us.archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu0.2_i386.deb sudo dpkg -i libicu38_3.8-6ubuntu0.2_i386.deb
Now open sources.list using the following command :
sudo vim /etc/apt/sources.list
Add the following sources and save the file-
deb http://php53.dotdeb.org stable all deb-src http://php53.dotdeb.org stable all
Now rest of the commands :
sudo apt-get update sudo apt-get install php5-cli sudo /etc/init.d/apache2 restart
It may ask what to do about the new php.ini file. Choose to use the packager’s version of it. If its asks about removing phpmyadmin and would you like to use db-common, select NO if you want to preserver your databases. Thats it.
You’re done! Congratulations. You can check the version number from the output of
phpinfo(); or in your command prompt type
php -v to assure yourself. But the game is not over yet 🙂 for the post-installation bugs are still roaming everywhere in your PHP installation. The bugs may vary for you, as it depends on the exact installation specifications, but I’ll tell you about the bugs I faced and if you have something in common, you can use the solution that worked for me. Lets refer to Post-Installation Bug as “PIB“.
PIB 1 : phpMyAdmin got uninstalled during the process of upgrading ! And when trying to install using “sudo apt-get install phpmyadmin”, it failed as it required php-mcrypt module which it seems cannot be installed in PHP 5.3.
Solution : Manual installation and configuration of phpMyAdmin. Let’s talk :
First download the latest phpMyAdmin from here : http://www.phpmyadmin.net/home_page/downloads.php
Extract the contents to a folder inside your webserver folder, say /var/www/phpMyAdmin
The extracted files and folders should be directly inside /var/www/phpMyAdmin folder and not inside some other folder within it like /var/www/phpMyAdmin/phpMyAdmin-3.*.*/.
Now you’ve to create a config folder inside it with world writable permissions. You can run the following commands :
cd phpMyAdmin mkdir config chmod o+rw config
Now, from your browser, goto location http://localhost/phpMyAdmin/setup and fill out the information. You’ll have to create new server entry and use the default settings only. Also in auth_user, and auth_password, leave as it is. Nowhere you should write any username and passwords. And auth_type should be cookie. Now click on SAVE button below and a config.inc.php file would be generated inside the config folder you just created. If its not for some reason, then you can click the DOWNLOAD button and download the file. Then move the file to phpMyAdmin folder and remove the world-writable permission. Here’s the code (assuming you’re inside the phpMyAdmin folder) :
mv config/config.inc.php . chmod o-rw config.inc.php
Now you’re done, phpMyAdmin should be up and running at http://localhost/phpMyAdmin
The sourcecode of phpMyAdmin is right now inside your webserver’s folder. I didn’t like that and may be you too. It was supposed to be at location /usr/share/phpmyadmin. Well there’s a simple way to do it. Just copy the entire phpMyAdmin folder to /usr/share and rename it to ‘phpmyadmin’ (all small caps). Now, open an editor and copy the following code :
# phpMyAdmin default Apache configuration Alias /phpmyadmin /usr/share/phpmyadmin <Directory /usr/share/phpmyadmin> Options Indexes FollowSymLinks DirectoryIndex index.php <IfModule mod_php5.c> AddType application/x-httpd-php .php php_flag magic_quotes_gpc Off php_flag track_vars On php_flag register_globals Off php_value include_path . </IfModule> </Directory> # Authorize for setup <Directory /usr/share/phpmyadmin/setup> <IfModule mod_authn_file.c> AuthType Basic AuthName "phpMyAdmin Setup" AuthUserFile /etc/phpmyadmin/htpasswd.setup </IfModule> Require valid-user </Directory> # Disallow web access to directories that don't need it <Directory /usr/share/phpmyadmin/libraries> Order Deny,Allow Deny from All </Directory> <Directory /usr/share/phpmyadmin/setup/lib> Order Deny,Allow Deny from All </Directory>
Save the file as phpmyadmin.conf and copy it to your apache’s configuration folder. In my case, its /etc/apache2/conf.d (You will require root permissions).
Then, just reload your apache :
sudo /etc/init.d/apache2 reload
Then goto http://localhost/phpmyadmin and it will work smoothly. I didn’t do anything about the mcrypt extension problem because I was only using it on my local computer. However, if you’re some corporate guy and doing this for some online application, then I won’t recommend the above method.
PIB 2 : PHP PECL Extensions not working properly.
Solution : Install them again. But as with phpmyadmin, it was not so easy.
This is how I installed the HTTP PECL Extension in PHP 5.2
sudo apt-get install php-pear sudo apt-get install php5-dev sudo apt-get install libcurl3-openssl-dev sudo pecl install pecl_http
Add “extension=http.so” in php.ini
sudo /etc/init.d/apache2 restart
So we’ll try to do that again. But first you’ve to uninstall the packages which may already installed. So just do :
sudo apt-get remove php-pear sudo apt-get remove php5-dev sudo apt-get remove libcurl3-openssl-dev sudo pecl uninstall pecl_http
And now when you’ll do the same process in PHP 5.3, it will generate the error :
The following packages have unmet dependencies:
php5-dev: Conflicts: libtool (>= 2.2) but 2.2.6a-4 is to be installed
E: Broken packages
cd /tmp wget http://cz.archive.ubuntu.com/ubuntu/pool/main/libt/libtool/libtool_1.5.26-1ubuntu1_i386.deb sudo apt-get remove libtool sudo dpkg -i libtool_1.5.26-1ubuntu1_i386.deb
Now after you’ve done this, do that process again and the PECL HTTP extension would get installed. Now you can install any other PECL extension using the command :
sudo pecl install pecl_
Also after you install the extension you’ve to add the following line in your php.ini file :
extension = .so
PIB 3 : Lots of warning generated wherever I used the date() function.
Solution : The default timezone is not set because your previous ini file was overwritten. So just add this line in your php.ini file :
date.timezone = Asia/Calcutta
or whatever your time-zone’s name is. Just restart apache again and you’re good to go.
These are the problems I faced and their solutions. You may face other problems, you can if you want, leave a comment telling about your problem and I’ll try to answer it. Anyways, hope it worked for you and welcome to PHP 5.3 !