News & Updates
23 Nov 2015
There’s a new article up on LaraPhil, a blog I’m writing just for Laravel related topics. Checkout Seeds with Media Assets using Laravel Elixir!
5 Jul 2015
I don’t bother with Virtual Hosts or Vagrant. It may sound blasphemous, or stupid, but it works for me (YMMV). Call me crazy. Say I’m not doing what the cool developers are doing. I don’t care.
My main reasons for doing so are speed and simplicity. The way I manage developing projects locally is to have a single, basically default web server configuration, with symbolic links into project directories. Lame, right?
But Virtual Hosts Are Cool!
Yes, they are. Browsing your project at my-project.dev is neat. But you have to create the virtual host every time you start a project. There are things out there that make this super simple like Pow (for Ruby on OS X), and I’m sure there’s something similar for Windows or PHP, I just haven’t found it (haven’t really looked), and I don’t want to bother. You can do some clever Rewrite so that *.dev points to a C:\Users\You\Dev\*\public folder. You can probably do a lot of things. I don’t. I really don’t care. I just want to get down to coding.
Vagrant Is Cool!
And you’re even using Laravel, Phil, which has Homestead! What’s wrong with you? Flat out, last time I checked, Vagrant didn’t run on Windows. Or at least not on my version of Windows. Believe me, I tried.
Windows? Ewww! Use a Mac! Use Linux! I’m stuck on Windows at least half the time due to working at a corporation with an IT dept. that makes their own flavor of Windows. I ran their installer for half a day and ended up with a computer that let’s me communicate with everyone else in the company. And I still had Administrator access to install my own IDE and other various programs so I can do my job. My Windows set-up is actually so similar to my iMac at home that there’s very little difference in my work environment, besides “ls” being “dir” and “/” being “\”. I even have Console with Solarized Dark colors. It’s really not so bad.
I don’t really have the time or inclination to install Xubuntu on my company issued laptop, and maintain it plus all of my applications all by myself, just to end up with the perfect development environment (and a computer that doesn’t run Office).
You Don’t Need Virtual Hosts
For reals, yo. You actually don’t need to jump through all of these hoops to develop something locally that still works when you deploy it. And if you do need it, well then by all means, make a virtual host. But trust me, this solution works 99% of the time.
How To Do It
On OS X or Linux flavors, you can create a symbolic link in your web server’s document root. Do it with the command line using the ln command by specifying the target and link name:
$ cd /var/www/htdocs
$ sudo ln -s /home/username/code/my-project/public my-project
On Windows, there’s a little tool called Junction which will let you create symbolic links on the command line. The only difference is the parameters are reversed (link name first, target second):
> junction my-project C:\Users\username\Code\MyProject\public
Now your project is “rooted” here: http://localhost/my-project
That’s it. No messing around with configuration files. No restarting Apache.
But… But… Relative From Root Paths?
I personally feel that if your application or framework requires you to put code in the root directory, there’s something wrong with it. If programmed carefully, you can easily deploy a project at the web root of a virtual host somewhere, without changing any code. Most modern frameworks have a ‘base path’ function.
I’ve only run into one problem doing things this way when working with Laravel’s pagination. Their paginator class assumes that the base path is ‘/’, but I was able to overcome that by passing url() into the path parameter from the controller. It’s hacky, but works. I’m thinking about making a pull request one of these days and seeing how that goes.
Questions? Comments? Emotional outbursts? Let me know how you set-up your development environment.
2 Apr 2015
There’s a new article up on LaraPhil, a blog I’m writing just for Laravel related topics. Checkout Laravel Route Cache breaks Route Model Binding!
3 Feb 2015
For fun I created an implementation of the Game of Life in PHP. Check it out!
22 Jan 2015
There’s a new article up on LaraPhil, a blog I’m writing just for Laravel related topics. Checkout How to Make a Laravel Artisan Alias!
7 Nov 2014
How Not To Store Passwords
Marty Weiner wrote a great a great article on how not to store passwords. He discusses the problems with passwords, how not to do it, and gives his recommendation of the right way to store passwords. Go read his article now.
How To Store Passwords
Marty recommends using bcrypt and gives examples in a lot of languages except PHP. Here’s how to do it in PHP 5.5 and up (but maybe not 6?).
Bycrypt With PHP
PHP 5.5 Makes It Easy
password_hash function, and pass in the constant for the bcrypt algorithm, which is
PASSWORD_BCRYPT. Also provide an appropriate
Here’s its signature:
[gist id=”c0dd025b31d40e0d145b” file=”1-signature.txt”]
And here’s an example of how to use it:
[gist id=”c0dd025b31d40e0d145b” file=”2-hash-password.php”]
The return value will be the hash. Store this somewhere. A database, perhaps.
Note that you can also pass a
'salt' in the
$options array. DON’T DO THIS. Let the salt be generated for you randomly.
What’s my $cost?
$cost to use depends on your hardware, and how quickly you would like the
$hash to be computed. The PHP manual provides a simple function you can run once on your server to find a good
$cost. It will probably be 10 or 11.
[gist id=”c0dd025b31d40e0d145b” file=”3-find-cost.php”]
Validate The Password
Validating the password is equally easy:
[gist id=”c0dd025b31d40e0d145b” file=”4-validate-password.php”]
$password will be what the user provides.
But I don’t have PHP 5.5!
Before PHP 5.5
Take the time to upgrade your authentication layer now or you open yourself up to liabilities galore. Helpful hackers should probably be forking ZFCommons ZFUser and other libraries as we speak.
17 Sep 2014
Lots of people want to know what their life plan is.
Answer: your life’s plan is the one you make.