Been meaning to move my dev environment onto my local machines instead of developing directly on the server. There are lots of benefits to this: it will save me from setting up dev hosts on the server, for one. And this will help keep commits in github from being so granular and cluttering up the place. Also, it should save a few seconds every time I want to test what I’ve done, which will save me at least a few minutes every day. Plus every single time I commit code to test, it is followed by one more commit usually with the comment ‘doh!’. Would be good for my ego to eliminate that as well.
To make a local environment for dev, in the olden days we would get each application (apache, mysql, php) and download or compile them locally, then install, etc. All updates were manual. In today’s world, we have quite a few options for install suites that provide a complete local environment.
I did some initial research, and installed a couple that didn’t work well, then finally did what I should have done in the first place and consulted phptherightway.com – my first and often final source for advice regarding current best practices. From php the right way’s home page, navigate under ‘Getting Started’ to ‘Window Setup’. There you will find a brief write-up, including a list of integrated development environment bundles.
After reviewing the offerings under each of the recommended sources, I installed EasyPHP – DevServer 17 (http://www.easyphp.org) on my Windows 7 desktop host, which takes most of the abuse in terms of installing unknown software, etc. these days. So far, the download page seemed a little sketch, but it doesn’t seem to have installed anything undesirable. I had problems with the menu in the notification area immediately after the install – it would not recognize any of the menu selections to start servers (or to exit the DevServer itself). The dashboard link, which goes to the localhost with a custom port, opened to an error in my browser. When I navigated to just localhost (port 80), there was a link to view php_info() output, but nothing else.
When it let me open a second instance, I knew it was having severe problems and shut everything down then rebooted. After my computer came up I was back on track with the Getting Started guide, here: http://www.easyphp.org/documentation/devserver/getting-started.php. I was able to start the servers and access the dashboard.
The dashboard has some good options – you can clearly see whether servers are running and their versions, configure directories to serve as the document root (although missing a Browse button) and access those sites. There is also a link to phpMyAdmin, which is a great tool to have available. And there is a novel php code tester interface, essentially a snippet tester.
Next move was to configure DevServer to work out of my existing GitHub repository directories. First I picked a project without a database for now, and was able to access a directory list in the dashboard interface and open the site in my browser, from an automatically created sub-directory under the localhost document root. Any links or images using an absolute path will obviously not function correctly. Otherwise, that worked easy enough.
The real test is to configure databases for my applications in the new test environment. The phpMyAdmin interface worked fine – I created a new user for my dev site, specific for this application, and opted to have it create a database. Then I exported the data structure and initializing data from my existing database and was able to load that no problem.
Next, I created a working directory in DevServer that pointed at my repo directory for this project, just like before. Finally, I updated my projects config files with the correct database credentials. I clicked on the “open in browser” link on the dashboard and… drumroll….. wah wah. It thinks my document root is: C:/Program Files (x86)/EasyPHP-Devserver-17/eds-www .
Luckily, my application is able to work in a subdirectory if it is configured, so presto-changeo, bummer: “Could not connect to database server.” Ok, so long story short, the database comes configured to allow anyone from localhost, and to otherwise require ssh, so I changed my new user to have no password, and to only be able to log in from localhost. That seems fine, but then I get “Unable to select database.” Ugh! So not sure how I fouled that up, but I created a new user then granted permissions for the application database and finally it connects!
Just in this short window I can already see how dev changes and testing can be much easier with a local environment. It realistically took me about 20 minutes to get up and running including troubleshooting. In all, definitely worth it!