PHP Lint has got your back

Hopefully, you have one of those friends who has your back, who will step in and stop you from making a really, really stupid mistake. Because we all are fallible and whether it be in a moment of rage, or just because we are in a rush, we will make mistakes.

This is why I have PHP Lint added as a pre-commit hook on my PHP Project repos. It only takes a minute to set it up and will have you a ton of time, and headache in the future.

First, you need to make sure you have PHP Lint installed on your system. If you are a PHP developer, then the chances are you have it.

Next go to you PHP project .git directory and add the following code to the file .git/hooks/pre-commit


And that should be it. Now every time you do a commit on some PHP code, your git workflow will send each file through the PHP Linter to check for errors. See the example below

Most editors will show you when you make an error, but we are rushing and don't notice that we forgot to add a semi-colon.

routes_php____Documents_GitRepos_DiegoDev_iParq_core_app_Http__-_VIM

We add the file and attempt to do a commit but because of the hook, Git will refuse to commit the files, and we can sleep easier at night knowing we can't accidentally send broken code to our repo.

2__eric_DiegoDev____Documents_GitRepos_DiegoDev_iParq_core__zsh_

One thing to note, this git hook will only parse the files you are committing and not the entire project. Meaning if you have a co-working was not doing linting, and you pull in their changes but don't touch the file, your commit will not catch it.

What time is it?!?!

When you heard that phrase in the 80's, you knew things were about to get funky. However, in the coding world, dealing with dates and time can be a real pain. I did a presentation for our Laravel User Group about a package that I enjoy called Carbon which makes working with dates and times a ton easier.

Check it out.

Talking Laravel

If you know me, you know I am a sucker for a good framework. Doesn't matter the language I am using, I will typically look for the hottest framework on the platform when I start a project.

In my primary development world of PHP, that framework had been cakePHP for a very long time. I had tried several others, but none of them stuck with me like cake did, that was up until a few years ago when a friend with our San Diego PHP User Group started pushing another framework on me called Laravel.

In that time, I've taken the Laravel framework further that I have any other including starting a development group that specializes in the framework. As typical, when I do something I like to submerge myself totally in it, and it wasn't too long before I found myself running a User Group for the Laravel framework.

During that time, I've had the opportunity to speak with a few of the key members of the Laravel community. The following two videos are interviews I did with Taylor Otwell (@taylorotwell) who is the creator of the Laravel Framework. The second video in my interview with Jeffrey Way (@jeffrey_way) who I consider the head educator for Laravel. Enjoyed talking with both these guys. They were super friendly and very, very accommodating.

Enjoy

First up is Taylor Otwell, the creator of Laravel. Great discussion with him.

This is Jeffrey Way's video, we had some major auto problems this night, sorry about that. We were able to mute everything when Jeffrey speaks. Also, the video should start at about the 15-minute mark. Everything before that is just some typical User Group meeting stuff.

SDPHP and the GeekGirl Tech Conference

Good time at the #geekgirltechcon  . #SDPHP  there talking #PHP  , Community, and development. Great time.

2014-06-21 07.45.26 2014-06-21 08.40.00 2014-06-21 09.04.01 2014-06-21 09.04.07 2014-06-21 17.08.56

PHP Unable to send email from web application .. (but commandline works)

This issue seems to have popped up a couple times over the past couple weeks so I figure I would capture the resolution here in the event someone stumbles onto this post and it's able to help them. Security is rarely convenient and this is an example of that.

Symptom:

CentOS machine running current on patches and running a current version of PHP, let's say PHP 5.3 or higher. PHP script is able to sent email from the command line, but when trying to send an email with PHP through the web browser it fails. Actually it doesn't "fail" it just doesn't seem to ever send.

Resolution:

SELinux is running on the machine and is preventing the Apache process to send out emails. There are a couple approaches you can take for this. To quickly test and confirm that the problem is in fact SELinux, and not something else, you can temporarily disable SELinux.

  • First verify SELinux is running with the command (as root) getenforce
  • Next, if SELinux is running you can disable with the command, again as root, setenforce Permissive

 

SELinux with be disable until you reboot the machine or enable it with setenforce Enforcing. You can permanently disable SELinux is you so desire editing the file /etc/sysconfig/selinux and changing the setting SELINUX=

Test your PHP Mail functionality now from the web application. If it works then you need to have SELinux allow the apache process to send emails. In order to do this, run the commands

  • setsebool -P httpd_can_sendmail 1
  • setsebool -P httpd_can_network_connect 1

 

You should now be able to re-enable SELinux and successfully send emails from your application in the browser.

My SDPHP Composer Presentation

A little while back I did a lightning talk at one of our SDPHP MeetUps on Composer. Composer is a fantastic tool and one that will change the way you approach PHP development. Using and managing external packages on a per project level has never been so easy in the PHP world.

I kept forgetting to publish my slides so for what it's worth, here they are.

 

The new PHP – Programming – O’Reilly Media

If your organization has written off PHP from being a possible solution to its development needs, you may want to rethink that decision. PHP is making a strong comeback and with developers who have years of experience under their belt, a language that has matured with the Internet it helps run, and now new features, stronger communities, and interoperability high on everyone's priority list, PHP is once again a great solution for any development need. 

The programming language many love to hate is experiencing a renaissance. This is not your parents' PHP. The new PHP is a more mature language with community standards,...

SDPHP – Google App Engine PHP

My presentation from tonight's SDPHP Meetup. Some great discussions. Was happy to see so much interest in Google App Engines PHP offering. I think we could have been there all night talking about this.

Thanks to Invisible Children for hosting. Also thanks to La Touraine, Inc for sponsoring the food.

A couple of people asked me what presentation software I was using, pretty basic actually. It's was Google Drives Presentation with the "Light Gradient" theme. Happy everyone enjoyed them.

Download Presentation Here

Encryption: It’s For More Than Just Password

Earlier this week John Congdon gave this talk at tek13, one of the top PHP Conferences. I didn't get a chance to attend the conference this year but I did get to see a preview of the talk a couple of times as John practiced his presentation on the SDPHP group. It's very informative and has me really looking forward to a couple new features that should be released in the next version of PHP version 5.5.

2 Weeks as a Programmer

Screenshot_5_13_13_5_46_PM-3I am starting the 3rd week of my journey; you see I am a “seasoned” IT guy. I’ve been working in the IT industry professionally, in some form or fashion, for some years. I’ve been tinkering with computers longer than that. My first computer was a TRS80-CoCo2 I got for Christmas, I want to say back in 1984.

The first thing I did was teach myself BASIC. I would spend hours coding small applications that didn’t do much of anything. I also started to tinker around with how the computer worked, how did it communicate with my dot-matrix printer or the joystick. This opened up my vision of the field of computers a lot.

As an adult, I found myself in the IT field. This wasn’t that surprising. I had found myself on the track of an Operations guy. You may ask yourself “What is an ‘Operations Guy’?”, Anything short of programming or one of the specialized fields like security, databases, etc. Ops is the heart of everything, making the systems talk to each other and typically the guys who work the odd hours, weekends and holiday to make changes and not impact day-to-day production. We are talking networking, hardware, backups, managing, monitoring, patching, so on and so on.

This is a great field to build a career on, my only problem was I love programming. I mean its one of the things I am passionate about. For years I was a hobby developer, building small applications here and there on the side. I was also fortunate in the sense I always seem to manage to have small development task at work. The longer I worked in the IT field, the more I wanted to focus on development.

A few years back the phrase “DevOps” was gaining popularity and I tried to position myself more and more into a DevOps role. At the time, I was working for a Fortune 100 company. Very corporate in its ways and very slow-moving. They pretty much had the opposite philosophy, leaning more to people becoming very specialized in a particular field or task. About a year ago I decided to make a change and took on a role with a much smaller company in hopes to develop more of the DevOps role. At first, it was very promising but eventually it also turned into a typically Operations position.

All, this time, I continued to better my development skills. Learning as much as I could from languages to best practices. I got more and more involved with the development community and developed some great connections and friendships. When I expressed how unsatisfied I was with the direction my job was taking it was through their encouragement I decided to take somewhat of a leap and look for a position that was more focused on development.

Today I start my 3rd week as a developer. I will chronicle this adventure here.

New SDPHP Mentoring Program

I am helping organize a mentoring program for the San Diego PHP User group. We officially announced the program at last nights meeting.

The SDPHP Group is always looking for what it can do to better strengthen the PHP community in San Diego. It is in this spirit we are launching a project to help facilitate PHP Mentorship. The purpose of this project is to give individuals looking for guidance and personal development with PHP related topics a clear avenue to find people willing to help them. As well as to help organize individuals who are willing to offer guidance and a support, by giving them network to allow them to give the best help possible.

Feel free to check out the full posting, especially if you are interested in getting involved with the project >> SDPHP Mentoring Program

Awesome Free PHP Resources: Web & PHP Magazine

I'm doing a little cross posting here to promote a post I wrote on the SDPHP site:

There are a ton of good PHP resources out on the net, both free and paid. Web & PHP Magazine is one of those resources that raises that bar from your typical smart developer posting blog articles on the weekend to a very polished, well-organized publication. Best of all, IT’S FREE!!

Rest of the story Awesome Free PHP Resources: Web & PHP Magazine.

15 Minutes with CakePHP

I recently gave a quick, and I mean quick, presentation on CakePHP to our San Diego PHP User Group. The presentation consisted of 5 slides of which only 2 were actually about CakePHP. The rest of my presentation was me building a quick blog which I might add I successfully did in about 15 minutes.

SDPHP CakePHP Presentation 1 SDPHP CakePHP Presentation

So the presentation went something like this:

But it probably goes without saying that 2 slides and a quick 15 minute demo really doesn't do a framework like CakePHP justice. CakePHP is an awesome framework with a ton features and of course you can always read the documentation yourself. However, there did seem to be a lot of interest in the command line interface I was using to build my demo code with.

I showed a lot of the functionality of the 'Console/cake bake' command. To recap a little.

> Console/cake bake
---------------------------------------------------------------
App : app
Path: /path-to/project/app
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
>

I also demonstrated you can run

> Console/cake bake all

and we saw all sorts of auto code generation magic happen.

But there are also other options I didn't touch one.

> Console/cake bake db_config
> Console/cake bake model
> Console/cake bake view
> Console/cake bake controller
> Console/cake bake project
> Console/cake bake fixture
> Console/cake bake test
> Console/cake bake plugin plugin_name

One of my complaints was that CakePHP didn't have built-in migrations. Cake does have a couple commands to make moving database around a little easier.

Now we take a look at Console/cake schema.

We start with

> Console/cake schema generate

This will generate a schema.php of the data in your projects database.

To then use this data on another project or database you run

> Console/cake create create

which uses that schema.php to import the schema.

You can also use the schema command to create a database dump file

> Console/cake schema dump --write filename.sql

Cake Shell also comes with a ACL Shell interface for managing and inspecting Acl databases. We spoke a lot about the need to run PHPUnit test and touched on how cake bake had the option to generate test files. As such the command line interface also includes

> Console/cake test

One of the more interesting commands, and one I have not tried using myself is the Upgrade command.

> Console/cake upgrade all

According to the Cake documentation "The upgrade shell will do most of the work to upgrade your CakePHP application from 1.3 to 2.0." which, if worked as advertised, would make updating projects to the latest version of the framework a lot easier.

The full list of shells available look like this

Available Shells:

[CORE] acl, api, bake, command_list, console, i18n, schema, test, testsuite, upgrade

Hope this perks the interest of some of you to give CakePHP a try.

Why aren’t you using git flow?

Attended another great presentation put on by the San Diego PHP User Group (which I am now a co-organizer of) around a workflow built off Git called Gitflow, presented by John Congdon (@johncongdon). Unfortunately the slides, as good as they are, don't capture all the great discussion and examples that were sparked up from the presentation but its a good start.

As I mentioned, I've taken a more active role is the SDPHP Group so if you have any question feel free to ping me. You can also keep tabs on the groups in the normal spots:
Twitter: @sdphp
Facebook: San Diego PHP
Meetup: SanDiegoPHP

MySQL EXPLAIN Explained – SDPHP

A local PHP User Group is starting to get some traction here in San Diego again which makes me very happy. Last night we attend a pretty good presentation on MySQL help at the Oracle building here in San Diego. It was given by Dave Stokes who is the MySQL Community Manager there at Oracle and he was nice enough to share his presentation online.

http://www.slideshare.net/davestokes/san-diegophp via @slideshare