I finally got around to PHP 5.4
Alas this meant reinstalling certain things, like ImageMagick and APC.
This also brought up the question of pagespeed, which I keep toying with. I use it at work, but since this server’s on CentOS with EasyApache, there’s no ‘easy’ way to install PageSpeed yet (not even a yum install will work), so it’s all manual work plus fiddling. I don’t mind installing ImageMagick and APC, but Google’s own ‘install from source’ aren’t really optimized for CentOS, even though they say they are, and I’m nervous about the matter. Well… I did it anyway. It’s at the bottom.
The only reason I had to do this all over is that I moved to a new major version of PHP. If I’d stayed on 5.3 and up’d to 5.3.21, that wouldn’t have mattered. But this changed a lot of things, and thus, a reinstall.
ImageMagick
I started using ImageMagick shortly after starting with DreamHost, since my co-worker Shredder was working on the ‘Have WP support ImageMagick’ project. It was weird, since I remembered using it before, and then everyone moved to GD. I used to run a photo gallery with Gallery2, and it had a way to point your install to ImageMagick. Naturally I assumed I still had it on my server, since I used to (in 2008). Well since 2008, I’ve moved servers. Twice. And now it’s no longer default.
Well. Let’s do one of the weirder installs.
First you install these to get your dependancies:
yum install ImageMagick yum install ImageMagick-devel
Then you remove them, because nine times out of ten, the yum packages are old:
yum remove ImageMagick yum remove ImageMagick-devel
This also cleans out any old copies you may have, so it’s okay.
Now we install ImageMagick latest and greatest from ImageMagick:
cd ~/tmp/ wget http://imagemagick.mirrorcatalogs.com/ImageMagick-6.8.1-10.tar.gz tar zxf ImageMagick-6.8.1-10.tar.gz cd ImageMagick-6.8.1-10 ./configure --with-perl=/usr/bin/perl make make install
Next we install the -devel again, but this time we tell it where from:
rpm -i --nodeps http://www.imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-devel-6.8.1-10.x86_64.rpm
Finally we can install the PHP stuff. Since I’m on PHP 5.4, I have to use imagick-3.1.0RC2 – Normally I’m not up for RCs on my live server, but this is a case where if I want PHP 5.4, I have to. By the way, next time you complain that your webhost is behind on PHP, this is probably why. If they told you ‘To get PHP 5.4, I have to install Release Candidate products, so your website will run on stuff that’s still being tested,’ a lot of you would rethink the prospect.
cd ~/tmp/ wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz tar zxf imagick-3.1.0RC2.tgz cd imagick-3.1.0RC2 phpize ./configure make make install
Next, edit your php.ini to add this:
extension=imagick.so
Restart httpd (service httpd restart
) and make sure PHP is okay (php -v
), and you should be done! I had to totally uninstall and start over to make it work, since I wasn’t starting from clean.
Speaking of clean, cleanup is:
yum remove ImageMagick-devel rm -rf ~/tmp/ImageMagick-6.8.1-10* rm -rf ~/tmp/imagick-3.1.0RC2*
APC
I love APC. I can use it for so many things, and I’m just more comfortable with it than xcache. Part of it stems from a feeling that if PHP built it, it’s more likely to work. Also it’s friendly with my brand of PHP, and after 15 years, I’m uninclined to change. I like DSO, even if it makes WP a bit odd.
Get the latest version and install:
cd ~/tmp/ wget http://pecl.php.net/get/APC-3.1.14.tgz tar -xzf APC-3.1.14.tgz cd APC-3.1.14 phpize ./configure make make install
Add this to your php.ini:
extension = "apc.so"
Restart httpd again, clean up that folder, and then one more…
mod_pagespeed
I hate Google. Well, no I don’t, but I don’t trust them any more than I do Microsoft, and it’s really nothing personal, but I have issues with them. Now, I use PageSpeed at work, so I’m more comfortable than I was, and first I tried Google’s installer. The RPM won’t work, so I tried to install from source, but it got shirty with me, fast, and I thought “Why isn’t this as easy as the other two were!?” I mean, APC was stupid easy, and even easier than that would be
yum install pagespeed
right?
Thankfully for my sanity, someone else did already figure this out for me, Jordan Cooks, and I’m reproducing his Installing mod_pagespeed on a cPanel/WHM server notes for myself.(By the way, I keep a copy of this article saved to DropBox since invariably I will half-ass this and break my site.) Prerequisite was to have mod_deflate, which I do.
The commands are crazy simple:
cd /usr/local/src mkdir mod_pagespeed cd mod_pagespeed wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_x86_64.rpm rpm2cpio mod-pagespeed-beta_current_x86_64.rpm | cpio -idmv cp usr/lib64/httpd/modules/mod_pagespeed.so /usr/local/apache/modules/ chmod 755 /usr/local/apache/modules/mod_pagespeed.so mkdir -p /var/mod_pagespeed/cache chown nobody:nobody /var/mod_pagespeed/*
Once you do this, you have to edit the file, and this is where I differ from Jordan’s direction. He just copied this over /usr/local/apache/conf/pagespeed.conf
but I had an older version from a ‘Let’s try Google’s way….’ attempt and someone else’s directions, so I made a backup and then took out the ModPagespeedGeneratedFilePrefix
line since I know that’s deprecated. I also added in a line to tell it to ignore wp-admin
.
Here’s my pagespeed.conf (edited):
LoadModule pagespeed_module modules/mod_pagespeed.so # Only attempt to load mod_deflate if it hasn't been loaded already. <IfModule !mod_deflate.c> LoadModule deflate_module modules/mod_deflate.so </IfModule> <IfModule pagespeed_module> ModPagespeed on AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html ModPagespeedFileCachePath "/var/mod_pagespeed/cache/" ModPagespeedEnableFilters rewrite_javascript,rewrite_css ModPagespeedEnableFilters collapse_whitespace,elide_attributes ModPagespeedEnableFilters rewrite_images ModPagespeedEnableFilters remove_comments ModPagespeedFileCacheSizeKb 102400 ModPagespeedFileCacheCleanIntervalMs 3600000 # Bound the number of images that can be rewritten at any one time; this # avoids overloading the CPU. Set this to 0 to remove the bound. # # ModPagespeedImageMaxRewritesAtOnce 8 <Location /mod_pagespeed_beacon> SetHandler mod_pagespeed_beacon </Location> <Location /mod_pagespeed_statistics> Order allow,deny # You may insert other "Allow from" lines to add hosts you want to # allow to look at generated statistics. Another possibility is # to comment out the "Order" and "Allow" options from the config # file, to allow any client that can reach your server to examine # statistics. This might be appropriate in an experimental setup or # if the Apache server is protected by a reverse proxy that will # filter URLs in some fashion. Allow from localhost Allow from 127.0.0.1 SetHandler mod_pagespeed_statistics </Location> ModPagespeedMessageBufferSize 100000 ModPagespeedDisallow */wp-admin/* ModPagespeedXHeaderValue "Powered By mod_pagespeed" <Location /mod_pagespeed_message> Allow from localhost Allow from 127.0.0.1 SetHandler mod_pagespeed_message </Location> <Location /mod_pagespeed_referer_statistics> Allow from localhost Allow from 127.0.0.1 SetHandler mod_pagespeed_referer_statistics </Location> </IfModule>
To tell Apache to run this, edit /usr/local/apache/conf/includes/pre_main_global.conf
and add:
Include conf/pagespeed.conf
Note: We put this code here because EasyApache and httpd.conf will eat your changes.
Finally you rebuild Apache config and restart apache and test your headers to see goodness! My test was a success.
HTTP/1.1 200 OK Date: Mon, 21 Jan 2013 03:12:13 GMT Server: Apache X-Powered-By: PHP/5.4.10 Set-Cookie: PHPSESSID=f4bcdae48a1e5d5c5e8868cfef35593a; path=/ Cache-Control: max-age=0, no-cache Pragma: no-cache X-Pingback: https://ipstenu.org/xmlrpc.php X-Mod-Pagespeed: Powered By mod_pagespeed Vary: Accept-Encoding Content-Length: 30864 Content-Type: text/html; charset=UTF-8
For those wondering why I’m ignoring wp-admin, well … sometimes, on some servers, in some setups, if you don’t do this, you can’t use the new media uploader. It appears that PageSpeed is compressing the already compressed JS files, and changing their names, which makes things go stupid. By adding in the following, I can avoid that:
ModPagespeedDisallow */wp-admin/*
Besides, why do I need to cache admin things anyway, I ask you?
So there you are! Welcome to PHP 5.4!
Comments
16 responses to “CentOS and PHP 5.4”
First of cool post π i did this about 2 weeks ago on BlogLines.co.za but then i was sent a invite to Googl PageSpeed Service
All the steps and you could have done one thing on your site .. GPSS
The only trick is that they only support www.
https://developers.google.com/speed/docs/pss/videos
https://developers.google.com/speed/docs/pss/setup
Any way the proof:
http://www.webpagetest.org/result/130121_9_6MM/ (BlogLines)
http://www.webpagetest.org/result/130121_8_6MP/ (MustLoveBooks with GPSS)
http://www.webpagetest.org/result/130121_J_6NW/ (Half Elf) it just need Quick Cache and GPSS
Thank you Kindly
Mark
GPSS … Google Pagespeed Service. Yeah, I’m opting out. It says it’s a 56% increase of speed, but given the bait & switch they pulled with Gmail for Domains, I’m pretty sure I’d wake up to find I’d need to pay for my (multiple) domains.
Test: http://www.webpagetest.org/result/130121_N_d67ff20b3ab6609728d153a49c2a1cb0/ (HalfElf)
I’m still experimenting with other ways to speed up the site though (and fwiw, there’s no plugin caching running here, at all, right now).
It is still cool GPSS i have about 20 domains running from it but it works best with WWW not with out
This was a test site.
Test it on this site it is a clean Single WordPress 3.5 site.
From WAS 7.489s NOW 2.499s
http://www.webpagetest.org/result/130121_5_456387efb4d6b5f076588ac6b43e616b/
Now that is fast 66% improvement
For the moment Page Speed Services is not as it is “free” but as soon as they start billing me then i will dump them.
PS How about a Guest Post on BlogLines.co.za
Sure, and they said they could do similar for me. But … It’s not that I don’t think this should be free (I’m all for paying for a service), it’s that I really have control issues π
At the point of using their services, I’d almost be better off with a front end Varnish server (or TrafficManger for Apache, what ever it’s called). Similarly, a CDN doesn’t help with my biggest problem right now, TTFB (time to first bite, not tough titties, grandma).
TTFB (time to first bite, not tough titties, grandma).
Give this a try http://wordpress.org/extend/plugins/quick-cache/ just install and click activate now for the setting just turn it on press save, Open a new browser were you not logged in pull up your site press F5 then gon Grtl U go to the bottom of the page your should see 3 green lines that means your good to go.
Now go test your site again.
Actually I improved it in a different way π A 2000 word explanation way that involves why I turned off caching right now, and why I’m NOT using WP for the work!
Hi,
Thanks for tips on how to use mod_pagespeed with WordPress. I haven’t had a chance to use CentOS with EasyApache, though.
I see you created two folders by the command mkdir -p /var/mod_pagespeed/{cache,files} . However, you have only used /var/mod_pagespeed/cache/ for caching with mod_pagespeed. May I know how you use the other folder /var/mod_pagespeed/files/ ?
Pothi
It was a mistake. I only need cache. Files USED to be used, but was deprecated. It came from the
ModPagespeedGeneratedFilePrefix
bit I removed.Okay, thanks. I started using mod_pagespeed only recently (probably since the start of this year). So, I didn’t know about the earlier versions.
There are a lot of cool things to add to your pagespeed.conf, as I’m learning. π It’s pretty nifty!
Any plans to upgrade to Nginx?
Not any time soon. Now that I’ve turned on PageSpeed, I’m working on making that sing. Sadly that doesn’t seem to be an option with nginx, and I can’t justify it yet. If I end up needing another server, it’d probably be an nginx proxy in front of my Apache server.
There’s just … more I can do with apache right now as an end user (vs root access) that doesn’t make it appealing to switch yet.
In the future, it will be. Pagespeed for Nginx is in alpha as of this writing. Anyone can know more about it at its Github repository.
And >this< is the amount of trust I'm willing to put in a Google Product being managed by someone other than Google. Given how long it took me to actually go for pagespeed, and the hassles you have installing it on certain servers, it'll probably be a couple more years before I consider nginx. Plus I've got no interest in losing my .htaccess to nginx's conf at this point. I've been using it, off and on, at DreamHost, and while I see the advantage from a dev, from an end user I'm not happy.
Mika
1) http://forums.cpanel.net/f189/nginx-automated-installer-148109.html
2) http://www.whmsecurity.com/web-server/how-to-install-nginx-on-cpanel-the-easy-way
I was looking at running Nginx on my Dedicated server but at the end of the day it just seem to much work yes i know WordPress.com runs Nginx for almost ever thing but is it worth it ?
I run a Dedicated Server with 16GB of ram and 2 hard drives the hole lot cost me $150 p/m
All i can say it i host “100K” blogs / users and the server is running nicely and the back ups are also sent to drop box
so over all i have to say i set it up nicely to work with me yes me and WordPress.
Google Page Speed Services is nice but server side caching is still a must have one day i will do a long post on how to set up a server on BlogLines.co.za…
I can’t answer that for you.
A lot of ‘Worth it’ falls under “what are you willing, and able, to support” and … I don’t know. I know that price is pretty fair for a Dedi with that much RAM, though.
PS: Don’t put affiliate links in your links man.