Categories
AWS php sysadmin WebApps

Building PHP with nginx, and fast-cgi on EC2

Here’s my quick and dirty guide to building PHP with nginx and fast-cgi on EC2:

yum install mysqld
yum install mysql
yum install mysql-server
yum install mysql-devel
service mysqld start
/usr/bin/mysqladmin -u root password 'your_password'
/usr/bin/mysqld_safe &
yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear
 php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mbstring p
hp-mcrypt php-mssql php-shout php-snmp php-soap php-tidy
yum install spawn-fcgi
# Next, download spawn-fcgi init.d shell script:
wget http://bash.cyberciti.biz/dl/419.sh.zip
unzip 419.sh.zip
mv 419.sh /etc/init.d/php_cgi
chmod +x /etc/init.d/php_cgi
# Start php app server, enter:
/etc/init.d/php_cgi start

# check to see if it's running
netstat -tulpn | grep :9000

Your /etc/nginx/nginx.conf file should look like this:
https://gist.github.com/1961501

Categories
php wordpress

How Do You Explain WordPress? Use Ruby Metaphors!

Last night I went to the WordPress Meetup at the Automattic office on Pier 38. I was late, but thank goodness that their sponsors had free booze and pizza.

What struck me about this meetup was how folks explained WordPress and how to do production pushes with it.

They had to use Ruby best practices metaphors.

This is a dramatic change from 5 or 6 years ago when the opposite was the case.

How do you push to production? “It’s like using Capistrano.”

How does WordPress.com push code to production? “We use SVN with no branches. It’s like git without the merging.”

What if you wanted to do RSpec / TDD? “Use something like Simpletest to exercise the user tables?”

There was no automated solution for what to do with serialized data, and pushing that serialized data from dev to stage to prod if said data contained a different FQDN for each environment.

Categories
php TechBiz Webalytics WebApps

URL Shorteners: tinyurl.com bit.ly and seductive.me

There’s a pretty useful spreadsheet comparing different URL shorteners here:
http://spreadsheets.google.com/pub?key=pApF4slh39ZkqUOoZQSo8bg .

Tinyurl just really shortens your URL and doesn’t provide any other data. A great feature is the preview option that allows you to preview a link so you don’t get Rick-rolled.

Bit.ly is my favorite service. The features I like are

  • its API,
  • its analytics, and
  • its Pro feature which allows you to make a branded URL shortener

I wanted to figure out just how much effort it was to code a URL so I coded up my own MVC based on Rasmus’ article on making one in PHP, and added URL shortening code to it. You can get the URL shortener I wrote on Github.

Here are a few things that I noticed once I put this code on Seductive.me:

  1. Somebody found a bad, infinite loop that I accidentally put into the code
  2. URL Shortener services that offer analytics have to sort out “bots” from real user clicks, and I’m not sure they are correct 100% of the time
  3. Using CRC32 as my hashing mechanism for shortening URLs will cause a link collision after 65,536 URLs shortened.
  4. Seductive.me is a lame url for a URL shortener which is why I got 3vi.be the next day.
Categories
How-To php

WP Geo Plugin

The print_GeoCache_Url function came across my email today from a self-described local designer and geek, but after a little research, I found out it only works up to WordPress 1.2 . Thank goodness for the WordPress WP-Geo Plug-in which I’m using right now.

More info here: WPGeo.com

[wp_geo_map]

Categories
php Questions ruby TechBiz WebApps

My Favorite Coder Interview Question

What is your favorite algorithm?

My favorite algorithm right now is the merge sort.

v1: Nuno Nogueira (Nmnogueira), v2: edited by Daniel Miller (cobaltBlue)
v1: Nuno Nogueira (Nmnogueira), v2: edited by Daniel Miller (cobaltBlue)

I like it so much that I’ve implemented it in PHP and Ruby.

The problem is that as a web developer I’ve never had to use a merge sort. Back in the old days when pagination was tricky, I’ve had to use a linked list, but you really don’t have to use the merge sort anymore.

So at this point it’s really just academic.

What interview question should really count now?

More on that in my next post. As a clue, I’d like to say it has to do with Leibniz’s statement, “The present is big with the future.” A techie who believes that and the principle of sufficient reason is the kind of techie you want.

Categories
Announcements php WebApps

Another Hackday Update: PHP unserialize doesn’t quite do it

Wow, I had to use someone’s custom unserialize code because PHP’s unserialize doesn’t quite work multi-byte strings. 🙁 Time wasted: 3 hours.

Here’s the function:

function mb_unserialize($serial_str) {
$out = preg_replace(‘!s:(\d+):”(.*?)”;!se’, ‘”s:”.strlen(“$2″).”:\”$2\”;”‘, $serial_str);
return unserialize($out);
}
Categories
Announcements php WebApps

Update on the WordPress Dev2Live Hackday

I know the bare minimum of what has to change in a WordPress install. Code that gets me the tables, and shows me the serializeable data in WordPress’ option settings is done.

Categories
Announcements php WebApps

A WordPress Hackday

Today, I’m going to explore looking for a solution for staging WordPress from a development environment to a production one. I’ll be posting throughout the day as “hacks” become available.

The main issue is changing serialized dev data into production data.

I’ll be in irc.freenode.net #wpdev2live .

Categories
php TechBiz

Looking For a New Web 2.0 Job? Try Shifting Your Perspective.

I spoke to a friend on Tuesday who recently received a promotion with a company he’d been employed with for just about a year out in Ohio. And the day before, on Monday, I learned that two friends had been laid off from the jobs they loved here in the Bay Area. When the Tuesday friend said he didn’t know how to feel about his promotion, I advised him to be grateful.

The Tuesday evening news informed me that if trends don’t change, California is going to run out of money for people on unemployment within a year, and will then have to borrow money from the federal government, as my home state Michigan and its neighbor Indiana are already doing. California’s unemployment rate now sits at an average of 8.2%. Layoffs are occurring left and right, and those in the tech industry can be tracked at both the TechCrunch Layoff Tracker and at CNET’s Tech layoffs: The scorecard. As was noted in October at sCommerce, “[w]hen it rains, it pours in the Tech World,” and already December has certainly seen its own fair share of downpour.

One recent victim I talked to kept shaking his head and insisting that it just didn’t make sense. But unfortunately, much as I sympathize and wish circumstances were otherwise, it does make sense. Businesses are doing the same thing the rest of us are doing, tightening their belts and hoping to survive the winter. Most people I spoke with didn’t seem to know where to begin once they’d lost their jobs.

However, while many industries are (however temporarily) very decidedly on the decline, others are thriving, growing even, and it isn’t impossible for the tech savvy to migrate over. Education, for instance. With so many people out of work, many are looking to further their educations. The Labor Department reported 9,800 jobs were created in the education industry. Additionally, the director of the Center for Economic and Policy Research in Washington, DC, Dean Baker, is quoted on CNNMoney.com as saying, “Education will be an area that governments will try to protect because there’s a lot of political support.”

But you don’t have to be a teacher at an established institution to teach. (Though that certainly isn’t a bad way to go if you can manage it. I suggest checking your local city or community college’s website, or trolling through the local paper’s want ads. That’s how I found an opening for an English teacher at my former local community college.) Freelance tutoring is a perfect opportunity for some quick money and a new addition to your resume. Lots of people are turning to private tutors when they don’t have the time or discipline for a structured class schedule.

Another industry that will always remain strong is the health industry. CNNMoney.com reports that “[e]ven in the midst of the economic fallout, healthcare employment grew by 34,000 jobs in November,” and later went on to add that “[o]ptions…abound at pharmaceutical companies, biotech firms and medical-equipment companies.” The moderator of Your Health and Tech, William Welense, urges people “to look into healthcare information systems! Seriously, HCIT [Health Care Information Technology] really really really needs some web 2.0 people, especially on the visual design part of development.” And with innovations like Google Health (blogged about here at Your Health and Tech) coming out, this could be a really exciting field to get into!

If you are already in the Bay Area, and don’t know what health care management software companies are around, I suggest you first stop by the Yahoo! Directory for San Francisco Bay Area > Health Care Management Software for a handy list of companies with links to their websites. Don’t overlook the classified ads on Craigslist either. After typing “healthcare information systems” into the search field, nineteen results popped up for me on Tuesday, December 16.

And speaking of people wanting to further their education in these times of low employment, a master of science degree in Human Computer Interaction might be a handy thing to pick up, especially when looking at the field of healthcare information systems, and can be earned entirely online at certain universities, such as Chicago-based DePaul University.

If you’re looking online for jobs, why not stop by Stephan Miller’s quick list of 11 Places to Find Tech Jobs? If you are looking for freelance work, definitely check out Elance. They have everything from “web & programming” to “writing & translation.” Other sites in this vein are Project4Hire and GoFreelance.

Most importantly when looking for a new job, don’t forget to network. Ask your friends. If they don’t know somebody, maybe they know somebody who knows somebody. I myself have connections at both Google and LucasArts that will likely never do me a damn bit of good, but could come in handy for other friends who are in those fields. I’ve found that a lot of companies offer recruitment bonuses to their employees, so don’t feel bad asking. And as pointed out in my previous post, don’t overlook even little things like the local happy hour.

The only way to get through this economic downtime and get things moving again is to persevere. Don’t lose hope, and don’t give up. If you can’t find a new job in your usual field, branch out. There really are jobs out there, we just have to know where to look. Hopefully this has offered a few launching points. Best of luck! I’m rootin’ for ya.

Categories
How-To php

Installing fcgi on IIS 6.0 with PHP 5.2.8

Choose fcgi iis
Choose IIS FastCGI
Be sure to install extensions needed for WordPress
Be sure to install extensions needed for WordPress

Select these extensions:
GD2
Gettext
Multi-Byte String
Mimetypec
MySQL
MySQLi
PDO/MySQL
SQLite (in case MySQL fails)
XML-RPC (WordPress needs this)

Be sure to install Pear and the PHP Manual, too.

Next step: Install FastCGI with the installer.

For more info check out this page

Also check out info how to install FastCGI on IIS 6.0.

Install eAccelerator.

My php.ini is below:

[PHP]
cgi.force_redirect=0
extension_dir=”C:\Program Files\PHP\ext”
[PHP_GD2]
extension=php_gd2.dll
[PHP_GETTEXT]
extension=php_gettext.dll
[PHP_MBSTRING]
extension=php_mbstring.dll
[PHP_MIME_MAGIC]
extension=php_mime_magic.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_PDO]
extension=php_pdo.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll

;eAccelerator
extension=”eAccelerator.dll”
eaccelerator.shm_size=”150″
eaccelerator.cache_dir=”C:\cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”1800″
eaccelerator.shm_only=”1″
eaccelerator.compress=”0″
eaccelerator.compress_level=”9″
eaccelerator.keys = “shm_only”
eaccelerator.sessions = “shm_only”
eaccelerator.content = “shm_only”

My fcgiext.ini in %WINDOWS%/system32/inetsrv is below:

[Types]
php=C:\PROGRA~1\PHP\php-cgi.exe

[C:\PROGRA~1\PHP\php-cgi.exe]
QueueLength=999
MaxInstances=20
InstanceMaxRequests=500
IdleTimeout=200
RequestTimeout=60

The performance you get on a 2GhZ processor with 1GiB of RAM is decent:

Transactions:                     662 hits
Availability:                 100.00 %
Elapsed time:                 123.15 secs
Data transferred:              21.96 MB
Response time:                  8.29 secs
Transaction rate:               5.38 trans/sec
Throughput:                     0.18 MB/sec
Concurrency:                   44.55
Successful transactions:         662
Failed transactions:               0
Longest transaction:           13.25
Shortest transaction:           4.23

5.38 transactions per second is 464832 hits per day.