Updating Centos 5 to php 5.3

Updating centos 5 to php 5.3

The version of php shipped with Centos 5 is 5.1.6 , lots of programs now need php 5.2 or 5.3 to install. The latest version of WordPress for example will not install or update on servers running 5.1.6.

When Centos 5.6 came out it had the opportunity to install PHP 5.3 from Centos – the problem is not all the PHP rpms available at 5.1.6 are there in the Centos repository at 5.3 e.g. php-pear php-mcrypt

One way around this is use a different repository , a good one for PHP is IUS . IUS has some nice features such as an add on to yum to make replacing the Centos PHP very easy – also it names it’s RPMs differently to Centos so you don’t have to worry about it overwriting Centos RPMs when you do a yum update. You may need to upgrade tour PHP applications to work with PHP 5.3 so check them out before you upgrade.

The following upgrade procedure is taken mostly from here

wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-8.ius.el5.noarch.rpm

wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-5-4.noarch.rpm

rpm -Uvh ius-release*.rpm epel-release*.rpm

Check you can now see the  PHP 5.3 rpms from IUS

yum list | grep -w \.ius\.

Install the IUS add-on to yum :-

yum install yum-plugin-replace

Stop Apache

service httpd stop

List what php rpms you have installed

-bash-3.2# rpm -qa | grep php
Now replace those rpms with the ones from IUS using the IUS yum add-on

-bash-3.2# yum replace php –replace-with php53
Loaded plugins: fastestmirror, priorities, replace
Loading mirror speeds from cached hostfile
* addons: mirror.netrino.co.uk
* base: mirror.netrino.co.uk
* epel: mirror01.th.ifl.net
* extras: mirror.netrino.co.uk
* ius: mirror.rackspace.co.uk
* rpmforge: fr2.rpmfind.net
* updates: mirror.netrino.co.uk
1872 packages excluded due to repository priority protections
Replacing packages takes time, please be patient…

WARNING: Unable to resolve all providers: [‘config(php)’, ‘php’, ‘config(php-ldap)’, ‘php-ldap’, ‘config(php-mbstring)’, ‘php-mbstring’, ‘config(php-mysql)’, ‘php-mysql’, ‘config(php-pgsql)’, ‘php-pgsql’, ‘config(php-common)’, ‘dbase.so()(64bit)’, ‘php-dbase’, ‘php-mime_magic’, ‘php-pspell’, ‘php-common’, ‘config(php-pdo)’, ‘php-pdo’, ‘config(php-odbc)’, ‘php-odbc’, ‘config(php-gd)’, ‘php-gd’, ‘config(php-bcmath)’, ‘php-bcmath’]

This may be normal depending on the package.  Continue? [y/N]
Resolving Dependencies
Resolving Dependencies
–> Running transaction check
—> Package php.x86_64 0:5.1.6-27.el5_5.3 set to be erased
–> Processing Dependency: php >= 4.0.4 for package: squirrelmail
—> Package php-bcmath.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-cli.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-common.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-devel.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-gd.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-ldap.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-mbstring.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-mysql.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-odbc.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-pdo.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php-pgsql.x86_64 0:5.1.6-27.el5_5.3 set to be erased
—> Package php53.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-bcmath.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-cli.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-common.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-devel.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-gd.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-ldap.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-gd.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-ldap.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-mbstring.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-mysql.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-odbc.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-pdo.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-pgsql.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-process.x86_64 0:5.3.3-1.el5_6.1 set to be updated
—> Package php53-xml.x86_64 0:5.3.3-1.el5_6.1 set to be updated
–> Running transaction check
—> Package squirrelmail.noarch 0:1.4.8-5.el5.centos.10 set to be erased
–> Finished Dependency Resolution
–> Running transaction check
—> Package squirrelmail.noarch 0:1.4.8-5.el5.centos.10 set to be erased
–> Processing Dependency: php >= 4.0.4 for package: squirrelmail
–> Processing Dependency: php-mbstring for package: squirrelmail
–> Running transaction check
—> Package squirrelmail.noarch 0:1.4.8-5.el5.centos.10 set to be erased
–> Finished Dependency Resolution

Dependencies Resolved
Package             Arch        Version                    Repository      Size
php53               x86_64      5.3.3-1.el5_6.1            updates        1.3 M
php53-bcmath        x86_64      5.3.3-1.el5_6.1            updates         42 k
php53-cli           x86_64      5.3.3-1.el5_6.1            updates        2.4 M
php53-common        x86_64      5.3.3-1.el5_6.1            updates        605 k
php53-devel         x86_64      5.3.3-1.el5_6.1            updates        590 k
php53-gd            x86_64      5.3.3-1.el5_6.1            updates        109 k
php53-ldap          x86_64      5.3.3-1.el5_6.1            updates         37 k
php53-mbstring      x86_64      5.3.3-1.el5_6.1            updates        1.2 M
php53-mysql         x86_64      5.3.3-1.el5_6.1            updates         92 k
php53-odbc          x86_64      5.3.3-1.el5_6.1            updates         52 k
php53-pdo           x86_64      5.3.3-1.el5_6.1            updates         67 k
php53-pgsql         x86_64      5.3.3-1.el5_6.1            updates         74 k
php53-process       x86_64      5.3.3-1.el5_6.1            updates         38 k
php53-xml           x86_64      5.3.3-1.el5_6.1            updates        119 k
php                 x86_64      5.1.6-27.el5_5.3           installed      6.2 M
php-bcmath          x86_64      5.1.6-27.el5_5.3           installed       33 k
php-cli             x86_64      5.1.6-27.el5_5.3           installed      5.3 M
php-common          x86_64      5.1.6-27.el5_5.3           installed      397 k
php-devel           x86_64      5.1.6-27.el5_5.3           installed      2.5 M
php-gd              x86_64      5.1.6-27.el5_5.3           installed      333 k
php-ldap            x86_64      5.1.6-27.el5_5.3           installed       49 k
php-mbstring        x86_64      5.1.6-27.el5_5.3           installed      1.8 M
php-mysql           x86_64      5.1.6-27.el5_5.3           installed      196 k
php-odbc            x86_64      5.1.6-27.el5_5.3           installed       88 k
php-pdo             x86_64      5.1.6-27.el5_5.3           installed      114 k
php-pgsql           x86_64      5.1.6-27.el5_5.3           installed      128 k
Removing for dependencies:
squirrelmail        noarch      1.4.8-5.el5.centos.10      installed       14 M

Transaction Summary
Install      14 Package(s)
Upgrade       0 Package(s)
Remove       13 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Total download size: 6.7 M
Is this ok [y/N]:
Downloading Packages:
(1/14): php53-ldap-5.3.3-1.el5_6.1.x86_64.rpm             |  37 kB     00:00
(2/14): php53-process-5.3.3-1.el5_6.1.x86_64.rpm          |  38 kB     00:00
(3/14): php53-bcmath-5.3.3-1.el5_6.1.x86_64.rpm           |  42 kB     00:00
(4/14): php53-odbc-5.3.3-1.el5_6.1.x86_64.rpm             |  52 kB     00:00
(5/14): php53-pdo-5.3.3-1.el5_6.1.x86_64.rpm              |  67 kB     00:00
(6/14): php53-pgsql-5.3.3-1.el5_6.1.x86_64.rpm            |  74 kB     00:00
(7/14): php53-mysql-5.3.3-1.el5_6.1.x86_64.rpm            |  92 kB     00:00
(8/14): php53-gd-5.3.3-1.el5_6.1.x86_64.rpm               | 109 kB     00:00
(9/14): php53-xml-5.3.3-1.el5_6.1.x86_64.rpm              | 119 kB     00:00
(10/14): php53-devel-5.3.3-1.el5_6.1.x86_64.rpm           | 590 kB     00:00
(11/14): php53-common-5.3.3-1.el5_6.1.x86_64.rpm          | 605 kB     00:00
(12/14): php53-mbstring-5.3.3-1.el5_6.1.x86_64.rpm        | 1.2 MB     00:00
(13/14): php53-5.3.3-1.el5_6.1.x86_64.rpm                 | 1.3 MB     00:00
(14/14): php53-cli-5.3.3-1.el5_6.1.x86_64.rpm             | 2.4 MB     00:00

Total                                            3.2 MB/s | 6.7 MB     00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : php53-common                                             1/27
warning: /etc/php.d/json.ini created as /etc/php.d/json.ini.rpmnew
Installing     : php53-pdo                                                2/27
Installing     : php53-cli                                                3/27
Installing     : php53                                                    4/27
Installing     : php53-mbstring                                           5/27

Installing     : php53-bcmath                                             6/27
Installing     : php53-pgsql                                              7/27
Installing     : php53-mysql                                              8/27
Installing     : php53-ldap                                               9/27
Installing     : php53-xml                                               10/27
Installing     : php53-process                                           11/27
Installing     : php53-gd                                                12/27
Installing     : php53-devel                                             13/27
Installing     : php53-odbc                                              14/27
Erasing        : php-ldap                                                15/27
Erasing        : php-pdo                                                 17/27
Erasing        : php-mysql                                               18/27
Erasing        : php-devel                                               19/27
Erasing        : php-odbc                                                20/27
Erasing        : php-gd                                                  21/27
Erasing        : php                                                     22/27
Erasing        : php-common                                              23/27
Erasing        : php-bcmath                                              24/27
Erasing        : php-cli                                                 25/27

Erasing        : squirrelmail                                            26/27
Erasing        : php-pgsql                                               27/27

php.x86_64 0:5.1.6-27.el5_5.3         php-bcmath.x86_64 0:5.1.6-27.el5_5.3
php-cli.x86_64 0:5.1.6-27.el5_5.3     php-common.x86_64 0:5.1.6-27.el5_5.3
php-devel.x86_64 0:5.1.6-27.el5_5.3   php-gd.x86_64 0:5.1.6-27.el5_5.3
php-ldap.x86_64 0:5.1.6-27.el5_5.3    php-mbstring.x86_64 0:5.1.6-27.el5_5.3
php-mysql.x86_64 0:5.1.6-27.el5_5.3   php-odbc.x86_64 0:5.1.6-27.el5_5.3
php-pdo.x86_64 0:5.1.6-27.el5_5.3     php-pgsql.x86_64 0:5.1.6-27.el5_5.3

Dependency Removed:
squirrelmail.noarch 0:1.4.8-5.el5.centos.10

php53.x86_64 0:5.3.3-1.el5_6.1         php53-bcmath.x86_64 0:5.3.3-1.el5_6.1
php53-cli.x86_64 0:5.3.3-1.el5_6.1     php53-common.x86_64 0:5.3.3-1.el5_6.1
php53-devel.x86_64 0:5.3.3-1.el5_6.1   php53-gd.x86_64 0:5.3.3-1.el5_6.1
php53-ldap.x86_64 0:5.3.3-1.el5_6.1    php53-mbstring.x86_64 0:5.3.3-1.el5_6.1
php53-mysql.x86_64 0:5.3.3-1.el5_6.1   php53-odbc.x86_64 0:5.3.3-1.el5_6.1
php53-pdo.x86_64 0:5.3.3-1.el5_6.1     php53-pgsql.x86_64 0:5.3.3-1.el5_6.1
php53-process.x86_64 0:5.3.3-1.el5_6.1 php53-xml.x86_64 0:5.3.3-1.el5_6.1


Check all the php rpms you had installed at 5.1.6 are now there at 5.3

-bash-3.2# rpm -qa | grep php
-bash-3.2# php -v
PHP 5.3.3 (cli) (built: Mar 30 2011 13:51:54)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Set your timezone for PHP ( if you do not do this you may see errors like PHP Warning:  strtotime(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. )

vi /etc/php.ini

date.timezone = ‘Europe/London’

Restart Apache

service httpd start

Check your applications now work


WordPress backups

My WordPress is only a few days old but logging in on the admin dashboard showed a new version of WordPress is out. I was going to sort out backups a little later but now seems a very good time to do it and then I can do the upgrade.

The Worpress site has a section on backing up Worpress , basically you backup the database and backup the flat files in your WordPress HTML directory.

First create a directory to store the backups :-

mkdir -p /backups

chmod 700 /backups

To backup the WordPress database I created a little script in /usr/local/bin :-


TODAY=`date  ‘+%Y%m%d’`




mysqldump –opt -u ${DBUSER} ${DBNAME} | gzip > /backups/wordpress.dump.${TODAY}.gz


The values for DBNAME , DBPASS and DBUSER  are those setup in the wp-config.php file for your install.

To backup the flat files I just did a tar :-

cd /var/www/html ; tar cvf /backups/my-wordpress.20090211.tar  wordpress

Of course no one cares about backups – only restores count, so you should test your restore on another server. You should also backup the Mysql database which holds the usernames and passwords

mysqldump mysql -p > /backups/mysql.db.dump.20090211

You will be prompted for the root user password for the Mysql database which you would have set when you first started up mysqld at install time.

Don’t forget to copy the dumps and tars to another server in case of a total server loss !

I will automate all the above with cron and rsync in the future

Installing WordPress on a Linux VPS

WordPress blogging software

Having setup my Linux VPS server ( see previous blog ) it’s time to install some web applications.

I wanted to install a blog so I could recount my experiances with a Linux VPS server. WordPress was chosen as it is open source and had very good reviews.

WordPress needs PHP and mysql – both of which were installed already.

Note current versions of WordPress require a later version of PHP than that shipped by default with Centos 5, If you are using Centos 5  update php to version 5.3 see here

First setup Apache so it will use PHP files

vi /etc/httpd/conf/httpd.conf and search for DirectoryIndex

Add index.php index.php3 index.pl index.htm index.cgi

( they are not all needed for WordPress but as I’m going to add other software I put them in )

Restart apache :-

service httpd restart

Create the database

As this is the first application I’m installing that uses mysql there a few steps needed to get msql up and running.

chkconfig  mysqld on

/etc/init.d/mysqld start

mysqladmin -u root password ‘apassword’

‘apassword’ is the password you want to set for the mysql root user

mysqladmin -u root -p -h localhost password ‘apassword’

Now create a database and a user for the database

mysql  -u root -p

create database wordpress ;

grant all privileges on wordpress.* to “wordpressadmin”@”localhost” identified by “passwd” ;

flush privileges ;


passwd” is the password you want the wordpressadmin user to have. You don’t have to call the database wordpress or the user wordpressadmin.

Get the latest WordPress version :-

cd /root

wget http://wordpress.org/latest.tar.gz

cd /var/www/html

tar xvfz /root/latest.tar.gz

Now for the setup and install

cd wordpress

cp wp-config-sample.php wp-config.php

vi wp-config.php

change DB_NAME , DB_USER, DB_PASSWORD    to the values you used above in mysql.

Assuming you have your site enabled for SSL then add the following to force all login and admin sessions to be over SSL ( https )

define('FORCE_SSL_ADMIN', true);

Point your browser to https://yourhostname/wordpress/wp-config.php

Fill in the blog name  and an email address ( you can change these later ) then click install.

If successful you will get a password for the admin user displayed – make a note of this and login as user admin with that password.

Click on the Settings link at the left hand side and fill in the Blog Title , Tag Line , Worpress Address URL ( http://yourdomain/wordpress ) , Blog Address ( http://yourdomain/wordpress ).

Check and change any of the other settings such as date format as you want then save the changes.

Next setup your profile – click Users and Edit the admin user, fill in your first and last names ( these are not made public ) , a nick name  , select from the drop-down box the name you want to appear as and  an email address.

Finally change your password , then click on Update Profile

Now you are ready to blog. Click on Posts at the left hand side – you will see the is already one post which you can either edit or delete. Once you have created your post hit the Publish or Update Post button at the right hand side.

There are loads of different themes and plugins available for WordPress – give them a go.