Search Results for ""

Heroku/PHP Quick Tip #2 – Adding PHP extensions

If you are used to using Composer, adding PHP extensions to a Heroku PHP app is really easy. For adding the GD library, just add the extension as follows to the “require” section of your project’s composer.json file:

"require": 
{ 
​   "ext-gd": "*", 
    "laravel/framework": "4.1.28", 
    "doctrine/dbal": "2.4.2", 
    "guzzlehttp/guzzle": "4.0.2", 
    "way/generators": "2.6", 
    "fzaninotto/faker": "v1.3.0" 
},

Heroku has a complete list of already included extensions and those available to be added during deployment.

Heroku/PHP Quick Tip #1 – Webroot

So I checked out Heroku yesterday after the official support for PHP announcement. I pushed up a basic install of Laravel 4.1 to a new free account. However, if you just create your repo, set up Laravel, and do a git push origin master , your webroot will be the project root, not /public. After reading about “buildpacks”, etc., I found out that all you need to do is create an empty file in the project root named “Procfile” and add:web: vendor/bin/heroku-php-apache2 public to it (assuming you are using Apache). I saw something else showing custom composer.json settings for heroku that defined the webroot, but I couldn’t get that to work.

Adding the Oracle extension (oci8) to MAMP PRO 3/OS X 10.9

I’ve never been successful in getting the OCI8 extension working on OS X (with or without MAMP) until now. I’ve been forced to use Vagrant (which is a usually a good thing) for anything requiring an Oracle connection).

 

Steps:

Make sure that the PHP version you are using in MAMP is in your path:
export MAMP_PATH=/Applications/MAMP/bin/php/php5.4.26/bin
export PATH=$MAMP_PATH:$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:~/composer-packages/vendor/bin

Download the basic and SDK packages.

Extract the files into a common folder (i.e.,/opt/oracle/instantclient). unzip *\.zip. They will all end up in a instantclient_11_2 folder, which I renamed to just instantclient. create two symbolic links:

ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib

Download the source for the version of php that you are using in MAMP (I’m using 5.4.26).

Extract the PHP source file and move the created folder to the following location (based on PHP version): /Applications/MAMP/bin/php/php5.4.26/include/php. The contents of the extracted folder should be in the root of ../include/php.

Run sudo pecl install oci8 from anywhere.

For the oracle instant client path, use: instantclient,/opt/oracle/instantclient. If all goes well, the last line of the build process should say: You should add "extension=oci8.so" to php.ini In MAMP, go to File | Edit Template, choose your PHP version and add the above text where appropriate.

Open /Applications/MAMP/Library/bin/envvars and add the path to the instant client library: DYLD_LIBRARY_PATH="/opt/oracle/instantclient:/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"

Restart MAMP and go to the MAMP welcome page and open up phpinfo and see if there is an entry for OCI8. Done. Credit to http://caseymorford.com/2014/04/17/installing-oci8-with-mamp-pro/ for filling in a few missing pieces for me (downloading the source for the PHP version used in MAMP and edting the envvars file). For the other steps, the main difference for me is the preference of keeping the oracle library files in /opt/oracle like I would on an Ubuntu server.

Giving PHPStorm a Chance

I’ve been a committed Sublime Text user for a while. I’ve spent a lot of time looking for the right mix of packages, learning the keyboard commands, auditioning LOTS of different themes and color schemes, and constantly playing with the user config (i.e., “trim_trailing_white_space_on_save”: true). Since I’m still fairly new to the PHP world and OOP specifically, I really didn’t want my editor doing any of the work for me either – code completion, auto-importing namespaces, handling Vagrant and Git commands in-app being some examples. As a result, I’ve resisted using a true IDE up to now.

Every time I’ve installed PHPStorm in the past to play around with it, I always disliked it’s lack of customizability in terms of the UI (which is surprising given it’s ridiculously complex Preferences/Settings). In spite of all of this, I keep giving PHPStorm a go every couple of months just to see what’s changed and I think I’ve had a breakthrough with the latest attempt.

“Fixing” the UI

The first challenge for me is to make it not ugly. I usually don’t even make it past this step before giving up and going back to Sublime, but this time I was able to get it just about right (for me).

 Steps:

  • Switch to Darcula theme.
  • Install the “total-conversion” of the UI by Shawn McCool.
  • Install the ColorIDE plugin.
  • Install the Dayle Rees color schemes for Jetbrains (I used one of his themes as a base to create my own color scheme). - Remove some of the annoying UI elements like the horizontal line above classes and between functions (“method separator color”). Hint:** you can’t remove it, but you can make it the same color as your background so it’s not visible. - Tone down the color of files that have been modified (VCS).
  • Remove the browser icons that show up in the upper-right.
  • Replace the ugly app icon with this...

Making it work like Sublime Text 

This is all about matching up the keyboard shortcuts with Sublime’s. Basically, all of the stuff you might be used to doing with Sublime via the keyboard is there (find anything, project switching, etc.). It’s just a matter of tracking them down. So now I’m going to give PHPStorm a workout for a few days exclusively. I’m really not that interested in it’s Git and Vagrant integration. I’d prefer to keep that in the Terminal for now, but I can already see some benefits with auto-importing and code completion that actually works. For Laravel, the lack of Blade highlighting is a problem (I’ve tried installing Textmate bundles for this unsuccessfully), but it’s apparently in the works.

Resolving Issues with Laravel Remote SSH Keys

I was recently banging my head over getting SSH keys to work with Laravel’s Remote Component. I’m apparently not alone in having problems getting this to work. I set up my remote connection as expected, pointing to my SSH private key file:

'production' => array( 
    'host' => 'xxx', 
    'username' => getenv('SSH_USER'), 
    'password' => '', 
    'key' => '/Users/gtaylor/.ssh/id_rsa', 
    'keyphrase' => '', 'root' => '/var/www', 
    ),

“Essential” Sublime Text 3 Plugins

Everyone likes to publish their favorite or “essential” Sublime Text plugins, so I’m joining the party. These are all Sublime Text 3-compatible plugins. I have a number of other plugins installed, but these are the only ones that I would immediately miss if I did a fresh install of ST3 (along with the Ubuntu Mono font.

A few Laravel 4.1 Update Gotchas

Update (12/12/1013)

One of the headaches with the upgrade to Production was waiting for ‘composer update’ to run while the site was down due to the skeleton and framework being out of sync. However, I’ve just realized that I should be pushing my composer.lock file to prod and just running ‘composer install’, which is much faster and makes sure your packages are in sync across environments. Doh!*

Moving to VPS hosting and dealing with email, Part 2

A while back I wrote a post about the dilemma of moving away from shared hosting to VPS (unmanaged) hosting and dealing with domain-specific email addresses. I’ve been migrating a number of web sites to a “droplet” with Digital Ocean. There are many benefits to this:

  1. Complete control over the environment - pick your own Linux distro, db engine, web server engine, PHP version, etc.
  2. Cost – For $10 on Digital Ocean, you get more RAM, CPU and storage than for most VPS servers for $30 or more.
  3. Flexibility – at Digital Ocean, you can spin up new “droplets” in about a minute, using a snapshot of a current droplet if you need to scale, etc.

But there are also some downsides:

  1. You’re on your own is something goes wrong.
  2. You need to come up with your own backup strategy.
  3. There’s no wysiwyg for creating virtualhosts, databases, etc., so you must be friends with the command line.
  4. Email. If the domains you are moving over include @mydomain.com type email, that last one can be a real problem. There are lots of horror stories about trying to setup and maintain your own email servers and I just don’t want to deal with that. Services like Rackspace offer email hosting for $2/mo., but with a minimum of 5 addresses, it’s really at least $10. Other services I looked at were often more expensive.

Solution

The simple solution I’ve found is maintaining a shared hosting account on Hostgator for email. As I migrate sites from a Hostgator reseller account to Digital Ocean, I’ve already determined that one legacy ecommerce site won’t run on PHP 5.4, so it’s moving to a shared “baby” account. On this account, I can create as many addon domains as I want, setup email addresses for those domains as needed, then in the Digital Ocean control panel, create MX records pointing back to the Hostgator where account is located (something like gatorXXXX.hostgator.com).

 The Hostgator “baby” plan is currently $7.96 month-to-month, which gives me unlimited domains, and in turn, unlimited domain email accounts. It also give me a place to put sites that don’t support PHP 5.4+ when needed. If you need to, you can also get webmail working by redirecting something like mail.{yourdomain}.com back to the hostgator webmail client.

6 reasons not to use a PHP Framework

  1. You are immortal, and therefore, will always be around to help other developers understand and extend your code.
  2. You have no life, and therefore, don’t mind spending all of your free time writing code comments and documentation that would already be written in a good framework, so other developers after you (or with you) can also write code for your app(s).
  3. You are coding an app that will be one of the most visited sites on the web (all by your self and for eternity if #1 and #2 are true), and therefore, can justify the potential nanoseconds saved by not having the “overhead” of a framework.
  4. You are a web security god and are way smarter than the collective group of developers who code and test good frameworks for security issues.
  5. You want to spend all of your time re-inventing the wheel by writing your own RESTful routing implementation, ORM, templating engine, etc. etc. instead of what a good framework provides. Or maybe you skip the ORM part and just re-write larges parts of the app when you need to switch DB engines.
  6. You don’t do “deadlines”.

If these reasons don’t apply to you, I recommend checking out Laravel, or better yet, the Laravel 4 beta.

Laravel 4 Pagination with Column Sorting

Updated (4/24/2014) to address possible SQL injection attempt with $order and/or $sort input.

It took a little effort, but I finally got Laravel 4′s pagination class working with the ability to sort by column. Posted here so I don’t forget.

//Controller 
$widgets = Widget::all(); 
$allowed_columns = ['column1', 'column2', 'column3']; 
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'delivery_date'; 
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; 
$widgets = $widgets->orderBy($sort, $order); 
$widgets = $widgets->paginate(20); 

//include $order and $sort when retrieving your layout/view 
$this->layout->nest('content', 'widgets.index',array( 'widgets' => $widgets, 'sort' => $sort, 'order' => $order) ); 

//View 
//Display the pagination 
//I tried using appends() first, but could not chain multiples 

{{ $events->addQuery('order',$order)->addQuery('sort', $sort)->links() }} 

//Column header 
//Using Twitter Boostrap up/down arrows
<th>Status
    <a href="{{action('[email protected]', array('sort' => 'status', 'order' => 'asc'))}}">
        <i class="fa fa-chevron-up"></i>
    </a>
    <a href="{{action('[email protected]', array('sort' => 'status', 'order' => 'desc'))}}">
        <i class="fa fa-chevron-down"></i>
    </a>
</th>

 

 

Why I’m moving from Coldfusion to PHP

People have spent a lot of time both predicting the death of Coldfusion, as well as refuting that assertion. Of course, it’s not really “dying”. It’s still very popular in government and higher education (I don’t have any stats to back this up, but this is what I’ve observed). Everywhere else, however, it’s market share appears to be small compared to PHP, Rails, etc. I blame Macromedia/Adobe for not providing a free, open-source version and for not marketing it sufficiently. Railo has filled the open-source hole, but it’s too little, too late.

Laravel Application Logs and Logrotate

Depending on usage, errors, and what you’ve chosen to log, the Laravel application log(s) can really grow after a while. With Laravel 3 and initially with Laravel 4, new log files were created every day by default, which kept them small and easy to search, but now Laravel 4 defaults to a single log file (which I prefer). Logrotate is a common utility on linux servers to handle the backup and rotation of server logs (Apache, syslogs, etc.) and it’s really simple to add additional logs/folders for Logrotate to handle. There’s a nice Digital Ocean tutorial for using Logrotate on Ubuntu 12.10, but here’s a quick and easy run through on how to use Logrotate with your Laravel logs:

Migrating to Cloud VPS Hosting. What to do with email?

I’ve started looking moving the sites I’m hosting on a Hostgator reseller account to a [Digital Ocean](http://digitalocean.com/) cloud VPS. I’ve already moved over my personal sites to a the base $5 VPS. The lone issue is what to do with the one client I have who uses their domain’s email thru Hostgator (as well as future clients). I set up all of my other clients (including myself) with Google Apps email for their domains prior to Google no longer offering a free version. I’ve never set up or maintained mail servers before, so I’m not excited about the prospect of doing that now, as critical as email is for most businesses. I wish there were cloud hosting services that could spin up a small VPS just for email after entering a domain name and making a few DNS updates. Maybe there are and I just haven’t found them yet. I could just maintain a Hostgator account that only handles email for multiple domains, but seems a bit klugy.

My “toolbox” re-visited

Every developer’s toolbox changes and evolves over time, even the old Reluctant Developer’s. In fact, I go through periods where I spend way too much time trying to find the next app that’s going to get me over the hump from hack to rock star. I haven’t found it yet because it doesn’t exist, but it’s still interesting exchanging some of the tools in the toolbox now and then, and sometimes finding that app that really makes a difference in one’s workflow.

So here’s a list of what I’m using now, along with a brief (sometimes very brief) explanation of “why”:

Operating System: OS X

This hasn’t changed in six years and will not be changing anytime soon. Aside from the aesthetics and being an Apple fanboy, OS X is just easier to work with when developing in languages like PHP that are being deployed to *nix servers and depending on things like Git, MySQL, etc. It’s a pretty seamless transition between working in the OS X terminal and an Ubuntu box terminal.

Code Editor: Sublime Text 3

Once you install Package Control and master the keyboard shortcuts, there’s no looking back. Extremely fast (start-up and searches), lightweight, packages for everything. Multiple selections = awesome. Got rid of Dreamweaver years ago (flaky). The Eclipse-based editors just seem really bloated to me. I used to use Coda, but after waiting for Coda 2, it became apparent that it was trying to do too much and was attracting it’s own bloat.

PHP Framework: Laravel

It’s just getting bigger, stronger, faster. I’ve deployed 2 apps now using Laravel 4, and though I still have a lot to learn, I’ve had no regrets in moving to PHP and to this still “new” framework.

CSS Framework: Bootstrap

 I’m not a designer and never will be. With bootstrap, I can put something out there that isn’t ugly, is consistent, and is responsive with very little effort.

MySQL Administration: Sequel Pro

Used to be a little buggy, but has come along nicely. Handles imports/exports every easily. Nice custom query editor.

Version Control: Git

Not an expert by any means, but Git is very powerful, yet pretty simple to use once you get the basics down. Though I do use SourceTree occasionally when I forget how to do certain things in Terminal, most of my interaction with Git is via the CLI:

git status
git add . 
git commit -am 'message' 
git push test

That’s pretty much it on a daily basis. Projects git pushed up to Bitbucket for safe-keeping and sharing with other team members. I use git hooks to do things like resetting file permissions after a push to test/prod, empty caches, run Laravel migrations, etc. I also use git tags to maintain and display the application versions in the footer of apps.

Development Environments: Vagrant]/Virtualbox 

I recently gave up on MAMP after running into several issues with not having identical environments between dev/test/prod. I decided to commit to a [simple Vagrant setup](https://github.com/rufhausen/super-simple-vagrant-laravel) using a single shell script to set up each environment.

FTP client: Transmit

 It works. Has a nice sync view between local and remote. Syncs favorites via Dropbox or iCloud.

That’s it. I don’t use anything else enough to warrant a mention.

Goodbye Wordpress, Hello "Brewski"

Since most of my work is "in-house" and won't ever reside on Github, and because needed to project that I would start using right away, and because Wordpress can be a PITA to work with at times, I decided to build my own [Laravel](http://laravel.com)-based blogging system. It's still very rough, un-stable, and written by a hack (me), but it's now powering this site. Having a personal project that I'm using right away, and with the code exposed on Github, is a nice motivator to keep working on it - so after many false starts, I think I've finally found a personal project that will keep me interested for a while.

 

Current Features:

  • Laravel-based
  • Themeable
  • Basic Disqus integration
  • Basic Social Media integration (in-progress)
  • Responsive Admin (bootstrap)
  • Markdown-based editor
  • Page caching
  • Basic Search
  • Categories & Tags

TODO:

  • Pages
  • Unit Tests
  • Lots of code cleanup/refactoring Github: https://github.com/rufhausen/brewski

Thoughts on Laracon Day 1

I'm at Laracon 2014 in NYC, and as I predicted, it's a little overwhelming - in Lower Manhattan, seeing in-person all of these people I've been following and learning from the last year or so, and listening to really smart people talk about stuff which, in some cases, is a little over my head. But it's all good, in spite of a few kinks with the venue.

 

I think I fully grasped/comprehended about 50% of the talks, which is fine. That's probably a better percentage than some design patterns books I've read the first time thru. Taylor Otwell's keynote was an exception in that I fully understand the headaches with dev environments and deployment, so Homestead and Forge providing the "artisan"-like bookends to developing with Laravel makes perfect sense. I hope that Forge can (eventually) work with existing VPS environments to some degree, as I don't deploy new environments often, but would love to use it for some existing VMs that don't use the hosting providers currently supported.

 

Photo Credit: https://twitter.com/brianwebb01/status/467072660023676928

"Extending" Laravel's Homestead

I put off moving my existing vagrant dev VMs over to [Laravel's Homestead](http://laravel.com/docs/homestead) for a couple of reasons:

  1. It doesn't completely match my production environments (Ubuntu 14.04 instead 12.04, PHP 5.5 instead of 5.4, Nginx instead of Apache).
  2. I knew I'd need to customize the VM anyway and I already had that worked out with my existing VMs (note the plural).

Controlling Laravel Homestead VM From Any Folder in Terminal

Having a single Vagrant VM for all of my projects is nice, but I was used to controlling Vagrant from within a project's folder in Terminal and not having to go back to the central Homestead folder to run things like vagrant up or vagrant reload.

Adding these to my Oh-My-Zsh config (.zshrc) seems to do the trick:

alias devup="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant up && cd - 1> /dev/null"
alias devreload="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant reload && cd - 1> /dev/null"
alias devdown="cd '/Users/gtaylor/Sites/Work/Homestead' && vagrant halt && cd - 1> /dev/null"

I'm using these in conjunction with `alias dev='ssh [email protected] -p 2222'` from the Homestead documentation.

Running Gulp.js in the background (OS X)

I discovered (or really just stopped ignoring references to) Gulp.js today and decided to give it a go. Now, this is not a post about what Gulp.js is - I'm assuming if you are reading this, you already know. This is about how to make me actually use it. The problem I ran into with Gulp right away was when you run it in a project in the terminal (`gulp`) with a gulpscript.js that watches certain folders (css,js, etc.), it has to just keep running in a terminal window in order to keep "watching" these folders. Even if you run the command with NOHUP to allow it to run in the background and free up the terminal session, you still have to remember to start it up for each project you're working on.

Pardon the Mess

I just pushed up a ton of changes to the "Brewski" platform (maybe "platform" is a bit much), so I'm dealing with a few errors, but the big thing is that I decided to ditch the markdown editor I was using and switched to ckeditor. There's just so much more I can do with it and it's easier for a non-tech person to use. The downside is most of the posts are currently a little f-ed up while I fix some formatting problems.

Using Laravel's Artisan with Git for Deployment.

There are many ways to handle web application deployment. Decisions on what method to use depends a lot on what type of hosting environment you are using, as well as the size, scope, and critical nature of the application. 

I handle the deployment of several applications with my own artisan "push" command that utilizes Laravel's SSH remote facade. The command is below, but first there's a little setup necessary: