Upgrade to PHP 5.6 on CentOS 6

The IUS Community Project is sponsored by Rackspace and offers an easy upgrade path for users on CentOS 6 who are tired of being stuck with PHP 5.3 (or Python 2.6). My experience upgrading to PHP 5.6 was totally painless, by YMMV. The IUS repo is recommended over the Remi repo, because IUS uses package names that are different from the default package names, whereas Remi overrides the defaults.

These instructions assume that you already have a version of PHP installed on your server.

$ cd /tmp

If you don't already have the EPEL repo, install that first. EPEL offers packages that aren't available on standard CentOS (like Fail2Ban and phpMyAdmin). If you're not sure whether you have EPEL, run sudo yum repolist  and see if epel is listed.

// Install the EPEL repo, if necessary
$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
$ sudo rpm -Uvh epel-release-6*.rpm

// Install the IUS repo
$ wget https://centos6.iuscommunity.org/ius-release.rpm
$ sudo rpm -Uvh ius-release*.rpm

// Install the IUS replace plugin
$ sudo yum install yum-plugin-replace

// Use the plugin to replace the existing PHP with 5.6
$ sudo yum replace php --replace-with php56u

// You will see some warnings. These warnings are normal.
WARNING: Unable to resolve all providers: [...
Continue? [y/N] y
...
Complete!

// Restart your web server. For Apache it's
$ sudo service httpd restart 

// Check installed PHP version
$ php -v
// should output...
PHP 5.6.25 (cli) (built: Aug 19 2016 11:03:33)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Congratulations, you are now on PHP 5.6! Want to  see what else IUS has available?

// Check for a specific package
sudo yum --enablerepo=ius list python*

// List everything in the IUS repo
sudo yum --disablerepo="*" --enablerepo="ius" list available | more

To learn more, check out the IUS Project website and this installation walkthrough on GitHub. There's also a helpful article by Rackspace. 

 

Checking Swap Space Size and Usage on CentOS

You can check the size and current usage of CentOS swap space by running:

$ grep SwapTotal /proc/meminfo

You can check current swap activity using:

$ vmstat 3 100
procs --------memory---------- --swap-- --io-- --system-- --cpu---
r b   swpd free buff cache     si so bi bo in cs us sy id wa st
0 0   1272 61748 227044 2786452 0 0   1 3   7 7 0 0 100 0 0
0 0   1272 61764 227044 2786452 0 0   0 19 18 19 0 0 100 0 0
0 0   1272 61796 227044 2786452 0 0   0 0 21 25 0 0 100 0 0
0 0   1272 61796 227044 2786452 0 0   0 12 29 29 0 0 100 0 0

The swpd column shows total swap usage. The si and so columns show the amount of memory swapped in and swapped out. Swapping should be relatively rare, so the si and so columns should usually be zero. If they are consistently non-zero, your system needs more RAM.

 

Start-Up vs Small Business

Allow rem units in HTMLPurifier

Edit the $allowedUnits parameter in /Length.php

protected static $allowedUnits = array(
'em' => true, 'ex' => true, 'px' => true, 'in' => true,
'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true,
'rem' => true // ADDED
);

Logging & Load Balancers - Getting the correct IP address

If you've set up a load balancer and have noticed that your Apache logs are showing all traffic coming from your load balancer's IP address instead of the user's, you can fix it by grabbing the X-Forwarded-For header and using that in the log format in httpd.conf:

LogFormat "%{X-Forwarded-For}i %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

Within your application code you can grab HTTP_X_FORWARDED_FOR from the server environment variables. 

ENV["HTTP_X_FORWARDED_FOR"]         # Ruby
$_SERVER["HTTP_X_FORWARDED_FOR"]   # PHP

 

 

Install Ruby from source - Centos 6

Install the required dependencies:

$ yum -y groupinstall "Development Tools"
$ yum -y install openssl-devel

Download, compile, and install Ruby 2.2.1:

$ cd /tmp
$ wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.1.tar.gz
$ tar xvfvz ruby-2.2.1.tar.gz
$ cd ruby-2.2.1
$ ./configure
$ make                 # this will take a while
$ make install

Update gems:

$ gem update --system       # updates rubygems itself
$ gem install bundler
$ gem update                # updates default gems

Check that Ruby and Rubygems are installed:

$ ruby --version       # 2.2.1
$ gem --version        # 2.4.6

Finally, clean up:

$ rm -rf /tmp/ruby-2.2.1
$ rm -f /tmp/ruby-2.2.1.tar.gz

And now you can...

$ irb
irb(main):001:0> puts "Hello #{ENV['HOSTNAME']}"
Hello plato
=> nil

 

Access a Local Sinatra App from iPad/iPhone

If you are developing a Rack application locally it's nice to be able to easily test a variety of devices. But if you try to connect via your local IP address, you will find that is doesn't work because by default Rack binds to localhost. In order to accept external connections we need to make Rack bind to 0.0.0.0 instead. You can do this with:

bundle exec rackup --host 0.0.0.0 --port 8080

You can find your local IP address from the OS X System Preferences > Network.

Access a Local Sinatra App from iPad/iPhone, Foreign Gods in

You can now connect from an external device using http://YOUR_IP:8080, e.g. http://10.0.1.14:8080

 

Most Recent

Archive

March 2016 (1)
January 2016 (1)
September 2015 (1)
May 2015 (1)
April 2015 (1)
March 2015 (1)
February 2015 (2)
January 2015 (5)
September 2014 (2)
August 2014 (4)
July 2014 (1)
March 2014 (1)
November 2013 (3)
September 2013 (3)
July 2013 (6)
June 2013 (1)
May 2013 (1)
March 2013 (2)
February 2013 (3)
January 2013 (4)