I’ve been working on a WordPress project lately that is housed on an Amazon EC2 server, using Bitnami. Overall, it’s a pretty awesome setup, giving me total free reign to setup the server how I need. Everything worked great on the QA server, but for some reason, after we moved the code to the production server, users started complaining about the inability to post any media (images, video, etc.) to their posts. They were getting a permissions error in WordPress trying to create the upload directory.
My initial thought was to use chmod to give all users write permissions to the folder in question. This couldn’t be done, however, as it opens up an obvious security hole.
So Next I checked out the QA site, and realized that the user and group owning the htdocs directory were daemon and bitnami, respectively. This was not the case on the prod server. So it became obvious that WordPress was hitting this directory as the daemon user, and did not have ownership rights to it. So I gave it to them:
chown -R daemon:bitnami /opt/bitnami/apps/wordpress/htdocs
And viola! The issue was resolved. This little jaunt down the rabbit hole, however, got me thinking about permissions as a whole when it comes to WordPress. I did some further reading and came across this great article regarding security on the wordpress platform. I highly suggest you give it a look.
If you only care about the meat and potatoes, as most developers often do, these two snippets are what you want. If you have shell access to your server, you can change file and folder permissions recursively with these bad boys, and set them to the correct permissions the WordPress team suggests.
For Folders:
find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} \;
For Files:
find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;
Good luck!
Well, we are officially making the transition to sublime as a team. I for one am happy, as this will make it much easier for us to share and version control many of the short cut benefits of this powerful coding tool. Its also an application that is very singular in how customizable it is, through preference files in JSON format.
One of said preference files is the tmTheme file, which is used for creating a color scheme for the codebase in sublime. Now, there are quite a number of good theme files out there, however none seem to play well with JSPs, at least not well enough for myself. I for one cannot have my JSTL tags the same color as my html. Blasphemy!
So, I proceeded to edit the theme to my liking, starting with a theme called “Tomorrow Night.” This started off well, however I came upon a stumbling block: the language file for JSP just wasn’t granular enough to color what I wanted. I could make JSP tags purple, but had no control over their child attributes or operators. This would not do.
Enter the tmLanguage file:
<!-- Targeting all of the JSP tags/attributes separately; This should let us color them however we want --> <dict> <!-- Start by targeting all alphanumeric tags with colons in them --> <key>begin</key> <string>(</?)([a-zA-Z0-9]++(:)[a-zA-Z0-9]+)</string> <key>beginCaptures</key> <dict> <key>1</key> <dict> <key>name</key> <string>punctuation.section.embedded.dsp</string> </dict> <key>2</key> <dict> <key>name</key> <string>meta.tag.block.dsp</string> </dict> </dict> <!-- then target the closers purple --> <key>end</key> <string>(>)</string> <key>endCaptures</key> <dict> <key>1</key> <dict> <key>name</key> <string>punctuation.section.embedded.dsp</string> </dict> <key>2</key> <dict> <key>name</key> <string>meta.tag.block.dsp</string> </dict> </dict> <key>patterns</key> <array> <!-- target the substrings separately --> <dict> <key>match</key> <string>([""'])(?:(?=(\\?))\2.)*?\1</string> <key>name</key> <string>string</string> </dict> <!-- target the equals separately --> <dict> <key>match</key> <string>([=])</string> <key>name</key> <string>constant.other.color</string> </dict> </array> </dict>
This guy let me add more granularity to the language targeting, such as looking for tags with the colon character in them, surrounded by anything alphanumeric. This is a very common structure in JSTL.
Once I set this up, I was able to target specific pieces in my JSP tags in order to color them. The specific string names that I setup are in red below, pointing to the specific part of the code that is targeted to color:

Anywho, I’ve placed the code on Github for your use. You will need to clone two separate repos, as I have one for both the theme and language file:
Day After Tomorrow Night Theme
Updated Sublime Jave bundle
Any questions, just let me know.
Enjoy!
Well, I took a quick look at my Page Speed results today, and it looks like Google is angry at me for my inability to leverage browser caching. Essentially, I’m reaching out to the server for every image on my site, even if the user has loaded it already. Seems like a ton of extra unnecessary work eh?
Well, htaccess to the rescue! I added the following to my .htaccess file, which sped up my site considerably (and also upped my Page Speed score). I opted to set my headers to a long time for both images, css, and js for now, since I don’t really update the look of my site that often. When I do decide to, I’ll most likely rename my js and css files, and removed the old ones.
# Setting Cache Control Headers # 480 weeks <filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=290304000, public" </filesMatch> # 2 DAYS <filesMatch ".(xml|txt)$"> Header set Cache-Control "max-age=172800, public, must-revalidate" </filesMatch> # 2 HOURS <filesMatch ".(html|htm)$"> Header set Cache-Control "max-age=7200, must-revalidate" </filesMatch>
Anyone out there have any suggestions on ways to set cache control? This was my first attempt at it, and I’d love some feedback!
PROTECT IP Act Breaks The Internet from Fight for the Future on Vimeo.
Tell Congress not to censor the internet NOW! – http://www.fightforthefuture.org/pipa
PROTECT-IP is a bill that has been introduced in the Senate and the House and is moving quickly through Congress. It gives the government and corporations the ability to censor the net, in the name of protecting “creativity”. The law would let the government or corporations censor entire sites– they just have to convince a judge that the site is “dedicated to copyright infringement.”
The government has already wrongly shut down sites without any recourse to the site owner. Under this bill, sharing a video with anything copyrighted in it, or what sites like Youtube and Twitter do, would be considered illegal behavior according to this bill.
According to the Congressional Budget Office, this bill would cost us $47 million tax dollars a year — that’s for a fix that won’t work, disrupts the internet, stifles innovation, shuts out diverse voices, and censors the internet. This bill is bad for creativity and does not protect your rights.
Mozilla is taking action, and so can you.
Was setting up some HTML5 audio on a site today, and noticed that the .ogg file was not playing in Firefox. After a bit of pulling out my hair, I realized that GoDaddy did not have this mime type setup on my server. So, I tried this in my .htaccess file:
AddType audio/ogg .ogg
And viola! HTML5 audio in Firefox.
So yesterday we needed to build a page that would redirect based on the device a user came from. We needed to know if a user was coming from a Droid, iPad/iPhone, BlackBerry, or Desktop. I grabbed some user agents here, and went to town. Lemme know if you know a better way to tackle this, as I tried to make it as lean as possible.
<%@ page import="java.util.*"%>
<%
Enumeration e;
e = request.getHeaderNames();
String userAgent = request.getHeader("user-agent");
%>
<%
if(userAgent.matches(".*BlackBerry.*")) {
out.print ("BlackBerries taste yummy.");
} else if(userAgent.matches(".*Android.*")) {
out.print ("These aren't the droids you're looking for.");
} else if(userAgent.matches(".*iPhone.*") || userAgent.matches(".*iPad.*")) {
out.print ("Pods or pads, doesn't matter.");
} else {
out.print ("I'm a PC.");
}
%>
So I finally got around to setting up Facebook Connect on my site this weekend. Now not only can you like all of my posts individually, but you can login and comment on them via your Facebook profile, and even post your comments to your user page. All this using a bit of FBML, and a nifty widget from Sociable.
I’d like to try and integrate some more aspects in the near future, such as my profile picture, and some better semantic implementation of the Open Graph Protocol.
Now, I just need to figure out how to align my like buttons on my blog with the same URLs that get aggregated to my Facebook page…
Had to grab the absolute URL of a JSP today in order to pass it to the Open Graph Protocol for Facebook. I had to set it up to include any query strings as well, and here’s what I came up with, using a bit of inline Java. Enjoy!
String url = (request.getRequestURL()).toString();
if (request.getQueryString() != null) {
url += '?' + request.getQueryString();
}