Easy Docker dev environments for PHP with CloudEstuary

Lately I’ve been messing around with Docker, and specifically with containerizing PHP applications to perform quick services, such as static analysis of PHP code, compatibility of existing PHP code to specific versions of PHP, and performing security checks on PHP libraries included in my projects. However, I’ve not created a development environment for my projects using Docker.

Like most professional PHP developers, I’ve been using Vagrant to create virtual environments for most of my development. It works fantastic, but one of the downfalls is that it leads to a large VM file for each virtual machine taking up disk space on my laptop. This is unfortunate for a consultant like myself, who creates a separate VM for each client.

But today I found another way. A way to easily create PHP development environments with Docker. The fine folks at CloudEstuary have created an easy to use web-based tool to create PHP development environments (yml files) for use with Docker-compose.

CloudEstuary

The entire process was super easy, assuming we already have Docker and Docker-Compose installed.

Create a Project

To start I selected the framework, of which I decided to try this with the very popular Zend Framework in an application I’ve been working on, so I clicked the Zend Framework icon. The tool chosen will cause the runtime settings in the next section to be altered to accommodate.

Next I added a custom name for my project and chose PHP 7.1 for the Runtime, but left the rest of the items set as default.

Following that, there is a list of pre-existing Addons to be enabled as desired. It seems Postgres is selected by default, but it is simple enough to Remove it and select another solution if desired.

 Then the final step, as of this writing, was to add any workers if I desired. I’m not sure of the limits of what can be put there, but I’m sure documentation will be forthcoming.

Then, finally, I was able to click the Generate Docker Compose button to receive the docker-compose.yml file. The final result was a brief explanation of what to do next, and of course, the file contents.

The docker-compose file expects to be placed in a directory where the application to be served resides in an ‘html’ directory. Don’t worry, you can change this as needed. In my case I simply change the following portions of the yml file (3’ish places):

To become:

I placed the docker-compose.yml file to the root of my Zend Framework application. (on the same level as the composer.json file)

Additionally, I have a local installation of Apache running on port 80, so the docker-compose file would not work for me out of the box. It sets the Nginx server port forwarding to expect the host port 80 to forward to the Docker container port 80. So I updated the ports from this:

To become this:

Use It

Now I was ready to fire up the Docker container. I did this via CLI by navigating to the root of the application and issuing the docker-compose command.

After a couple minutes of Docker fetching various images, the container was running. Note: the terminal continues showing what it happening inside the container. (Nginx and other apps logs are output to the terminal)

Now I was able to pull up my awesome Zend Framework PHP app in the browser using the address http://localhost:8888

Add Account

One other nice feature of the site is the ability to create an account. I am told there will be more functionality around this later, but for now it allows you to see a list of all projects you’ve created, and enables you to edit the configurations.

Simply click the link to create an account:

Then you can see projects created while you were logged in via the “My Projects” menu item.

Closing

I hope you found this post helpful. Using Docker to create PHP development environments is easy. Enjoy!

PHPStorm and debugging IP issue

Recently I was helping someone troubleshoot an issue using PhpStorm and Zend Debugger. In this case Zend Studio was able to debug an application using Zend Debugger while PhpStorm was failing unless an SSH tunnel was used. The error received was:

Host ‘127.0.1.1’ is not allowed to open debug sessions – please configure zend_debugger.allow_hosts in the ini file.Failed to connect to host ‘127.0.0.1’, reason: ‘Connection refused’.

The person experiencing this issue was attempting to debug a site in a VirtualBox virtual machine from the host machine. Both the host machine and the virtual machine were running Ubuntu 14.04. At first glance I thought adding 127.0.1.1 to the allowed hosts would do it. But turns out it was more than that.

In this case we knew there was not a firewall blocking access, so it had to be networking.

To start things off I wanted to take a look at what PhpStorm was listening to, so I used the broadcast port 20080 to see this in a browser:

Screenshot from 2016-04-04 16:13:09

So it appears PhpStorm was attempting to use the IP addresses linked to the host systems ‘localhost’ and ‘hostname’, but not an IP address accessible via the network. This meant the server would never be able to send information back to the IDE without the use of an SSH tunnel, because it could not reach 127.0.1.1 or 127.0.0.1 of the host.

Unfortunately PhpStorm doesn’t provide a way to alter the listening IP addresses in the preferences, so we were left with either using an SSH tunnel to allow port forwarding of the listening port (10137) back to the host, or manually informing Zend Debugger where the IDE would be located.

Zend Debugger Tweak

By default Zend Debugger will automatically attempt to detect the IDE settings, as shown below:

Screenshot from 2016-04-04 16:23:04

However, this wasn’t working because PhpStorm was not reporting a usable IP address, so we needed to update the settings manually:

Screenshot from 2016-04-04 16:22:37

NOTE: Checking the box “Use browser’s IP Address” did not fix the issue. The IP address needed to be entered.

With this done, the server now knew where to reach the IDE for debugging sessions. One downside to this is if the host machines IP address changes, this setting will need to be updated.

This post is one in a series on debugging. For others click below:

Setting up step debugging in Zend Studio
Using an SSH tunnel to step debug through a firewall
Setting up local step debugging with PhpStorm

Edit: Please head out to the PhpStorm ticket system and +1 this fix to make this a thing of the past. https://youtrack.jetbrains.com/issue/WI-7465

SunshinePHP 2016 Recap

The Good

SunshinePHP 2016 was an awesome event! Not only were we sold out of tickets for the 4th year in a row, but the attendee list was truly amazing! Each year more and more companies in South Florida send most if not all of their PHP developers to the conference. This year we saw at least 20 companies in South Florida send 5 or more of their developers, and around 8 of those sent around 10. We love seeing our work take hold, and with this many companies embracing the conference it is obvious we are doing a good job. Thanks to all for participating.

SunshinePHP CrowdsThis year we had 14 of our amazing 19 sponsors represented in the exhibitor area, handing out Lego pieces and speaking with developers about how they could help them enhance their careers in one way or another. We are happy that every sponsor raved about the event, attendees, the amount of contacts they made, and the overall organization of the conference.

SunshinePHP exhibitor areaAttendees told us they loved the Lego puzzle idea, and really enjoyed collecting the Legos from the sponsors.

We had some amazing talks and keynotes this year, and really pulled some topics that were outside the box we typically see at PHP conferences. Two talks were about the brain and mental functionality, and how rest and downtime can affect our thought processes and how we learn. There were talks about dealing with customers, and how to help them help us. The keynote speakers shared tips on collaboration and teamwork while sharing stories about Pacific Ocean crossing, and growing up with physical and/or mental disabilities.

Or course these off-the-wall, but very valuable, subjects joined our already mind blowing lineup of topics and speakers.

We also had a very gender diverse attendee and speaker lineup with 16 female speakers (or 36%) and around 20% female attendees! This is a step in a very positive direction, and SunshinePHP continues to lead the way through non-biased speaker selection and responsible marketing.

The menu each day was slightly altered from previous years, with some healthier choices. The quality of the food was another nice touch as the venue really stepped up to provide some tasty items.

Evening events went well with games and panel discussions about API building indoors, and an open bar with some food items outdoors on the pool patio. (Yes, it was nice and warm.)

SunshinePHP tasty food

Overall the event went amazingly well.

The Bad

We didn’t receive too many complaints in our feedback from the event. Some mentioned that the temperature in one room was a bit cold for awhile. Others mentioned that we could have added the technical levels of the talks on the printed schedule. (We had them on the site, but overlooked adding it to the printed materials.)

One complaint, which we loved, was that we made it very difficult to improve the event for next year. 😉

The Ugly

Yes, unfortunately there was some ugly. With the recent awareness of codes of conduct and with the increase in gender diversity there is bound to be more visibility as victims come forward rather than remaining hidden. (Because even though we didn’t hear about these incidences in the past, they were already happening.) We are relieved to report that each incident below was handled professionally, and to the satisfaction of the victims.

One report was about a male attendee offering 2 separate female attendees a private sampling of relaxation techniques in his room. And when the women refused the man did not continue or push. When the incidences was brought to the man as being inappropriate he apologized and said he meant well, and he would not do it again.

A second report was made about a man in the pool area, long after the conference had ended for the day, who approached the girlfriend of an attendee and flirtatiously claimed that she could do better than her current boyfriend. We recommended that the man retire to his room (to prevent an assault) and get some rest for the next day, which he did. Nothing further was said, and no additional actions were taken.

There was a third incident reported which took place before the conference actually started, but was reported after the conference ended. A male offered to take a female shopping some distance away from the venue. Allegedly, while they were shopping the man touched the woman in an inappropriate manner. Because of the lateness of the report there were no further actions.

In a fourth report, allegedly a woman was swimming with a group, long after the conference had ended for the day, and one of the men in the group touched her in an inappropriate manner. The following morning this was brought to our attention as a 3rd party story by someone who was not present. We spoke with the man, who remained in his room except for meals over the remainder of the conference.

And finally in a fifth incident, also reported by a woman but late into the following day, it was stated that a man in the pool area the night before was over-aggressively tugging on the straps of her swimsuit. The apologetic man was questioned and promised to refrain from such activities in the future. The woman said this was an acceptable outcome.

My desire, and the reason I am being open about these incidences is to help others. Other conferences need to be aware this happened, so they can also keep their attendees safe. And attendees need to know about these things so they can watch for it, report it early, and help keep each other safe. Because whether we admit it or not, these types of activities happen everywhere. If you organize an event or group, please do not fool yourself into thinking your event is immune.

Conclusion

While SunshinePHP was very organized, and was an awesome event, sometimes things can happen that are out of an organizer’s control. I feel the SunshinePHP staff did everything in their power to ensure the safety of our attendees. We are looking forward to next year.

Delayed anxiety, never forgotten

Today I read a blog post from a local developer, Chris Russell, in which he describes how he is struggling with anxiety, stress nightmares, and sleeplessness due to a past job and the stress it caused. I wrote a blog post about this in the past, but will share more personal experiences here because Chris’s experience led me to recall something I deal with on a daily basis, and have dealt with for the past 17 years. (No, it never goes away.)

As we grow older the memories of the past become more and more clear, and 17 years “feels” like yesterday. Even as I say that number it’s hard to believe it was that long ago, yet here we are in 2015. So recalling this is not a problem. Well, actually it is a problem because the memories suck, though the fact I can recall it is sweet.

At that point in my life I was on the verge of closing a failed business. I was smoking 2 packs of cigarettes and drinking 2 pots of coffee each day, and dealing with the stresses of bill collectors, not being able to pay employees, and possibly being homeless soon. All while living on a single meatball sub each day because I couldn’t afford anything else to eat. My life had become one HUGE ball of stress and failure.

One evening I was trying to relax, and was sitting on my couch watching something stupid on TV (most things on TV are stupid), and felt a sudden heat in my chest. I felt as if I had a pool of warm water right where my heart was, and fully expected to look down and see exactly that. There wasn’t any pain, just a warm “oozy” feeling. Following this I was filled with sudden feelings of TERROR! No, not the scared feeling we get from watching a frightening movie or riding a roller coaster. This was sheer TERROR ripping through my body and mind. I “knew” I was about to die at 32 years old. Not knowing what else to do I called 911 for an ambulance. (I was alone, because nobody wants to be around a failure.)

After a night in the ER, of which I had a couple more in the following month as I finished closing the business, I was diagnosed as having a panic attack driven by anxiety. They prescribed some anxiety drugs and sent me home. (I only took the drugs a couple times because they caused feelings of paranoia, so I flushed them.)

On one trip the ER I had a fairly attentive doctor who actually talked with me about what was happening. He said that these attacks were likely spurred on by previous months of high stress, rather than what I was experiencing at the moment. It turns out that anxiety builds over time, and attacks can be the result of stress experienced up to 6 months prior as a delayed response. So things like divorce, job stress, fights with loved ones, unsolved problems, auto accidents, past due bills, disgruntled employees, and pretty much anything else that can cause stress doesn’t manifest itself immediately. Our minds and bodies can take up to 6 months to fully process it and manifest them in physical ways.

All of this is what led me to change my life. I stopped smoking, stopped drinking coffee (caffeine free herbal tea became my friend), got a new job, and moved in with family until I got back on my feet, and started doing things proactively rather than waiting for things to happen to me.

Times are brighter now, and I have experienced many successes. But the anxiety always remains and NEVER goes away. I opened the Pandora’s box by allowing stress to run me and will pay the piper for the rest of my life. Terror is only one missed indicator away from taking over. But I manage it by keeping stress levels low, keeping busy, staying physically fit, and recognizing symptoms before they escalate. My journey continues.

To those of you who have not experienced this, please do not let stress build up. Handle things early, because this is not the way to live. For those who do experience this, relax, it does get easier with time and alertness.

Mirror mobile device screen to your computer

I needed to perform a demo of a tool where I would utilize my mobile device (phone) to perform an action, and it caused a reaction on my laptop.  However, part of the “WOW” factor is to mirror my mobile device screen onto my laptop so the viewer can see both the mobile device and the web browser.

Thanks to Apple’s AirPlay this is relatively easy for the iPhone with the purchase of 3rd part software like Air Squirrels Reflector, but I don’t have an iPhone. (I can never figure out how to switch between apps, or how to go back if the app developer didn’t include a back button in the app.  But I digress.)  Instead I have an Android device, which has a much larger user base, and I really didn’t want to switch.  Unfortunately nobody has created a 3rd party application that utilizes the Cast Screen functionality of Android in the same manner as the AirPlay.

In searching I found many solutions that required the user to “root” their mobile device.  This really wasn’t an option for me.  I have a Google Nexus device, so I’m not really held back by mobile vendor limitations, lock downs, or pre-installed software.  No need to “root” my device.  I’ve rooted/unlocked other mobile devices in the past, and since I’m not a mobile developer, I feel no need to tinker with what works for me.

I did manage to find a couple other solutions (one with the help of my co-workers) that did work without altering my device software, or installing applications on my laptop.  Well, that is not entirely true.  Both of the solutions I’m about to share did require the Java runtime environment to be installed, but I consider that a mute point since most computers these days already have it installed for one reason or another. (Most developer IDE’s already require it, so I already had it.)

Step 1 – Ensure you have JRE

As I said, for this to work you will need to have the Java Runtime Environment of some sort installed on your system.  If you don’t already have the JRE installed you can do it at http://java.com.

Step 2 – Connect with USB

You must connect your Android device to your PC via USB connection for this to work.  As of this writing I have not found a way to make this wireless.

Step 3 – Enable Developer Mode

By default Android devices do not come with Developer Mode enabled.  This mode is needed so we can take advantage of debugging via USB tether.

On Android devices prior to 4.2 you could set USB Debugging from the settings…easy-peasy.

To enable this on Android 4.2+ go into Settings->AboutPhone and tap the Build Number 7 times.  The device will inform you that Developer Mode is now enabled.  Click back to hit the previous screen and you will now see Developer Options available.  Check the box for USB Debugging and you’re done.

Step 4 – Download the Android developer tools

For simplicity sake I only downloaded the standalone Android SDK Tools Only. (I had no use for the Studio.) I did this at the URL http://developer.android.com/sdk/index.html#Other, then unzipped the file to a place of my liking.

After making the file ‘/tools/android’ executable I ran it on the system.  This opens the Android SDK Manager window.  The purpose for this is to download and install the needed packages to allow us to “develop” Android apps.  I didn’t change a thing and simply clicked the button that said “Install n packages”. (Note: n will be some sort of number.)

It took awhile for the manager to do the update/download, but after it was completed I simply closed it.  This would have downloaded a bunch of things, but the most important for us is ‘/platform-tools/adb’ which is required to mirror our device screen to the PC. (Make sure this file is executable as well.)

Step 5 – Add locations to the PATH

For this screen sharing to work you will need to add two folders of the Android SDK to your PATH: ‘/platform-tools’ and ‘/tools’.  I did this by editing my .bashrc file as follows:

export PATH=$PATH:/home/aculp/android-sdk-linux/platform-tools:/home/aculp/android-sdk-linux/tools

Step 6 – Download Apps

There are two possible apps to use to do this:

Both carry the same sorts of functionality, however Droid @ Screen is a bit more mature and makes additional options a little easier.  One thing I didn’t like was the need to have an extra window open for the settings.  Due to my being a fan of simplicity I have been using Android-Screen-Monitor.

Both apps are a simple matter of executing the jar file using java and they just work.

Step 7 – Launch it!

Now it is simply a matter of launching either the Android-Screen-Monitor or [email protected] application. I did this via CLI like so:

$ java -jar asm.jar

NOTE: This command assumes we changed directory to where we downloaded the Android-Screen-Monitor jar file.

Conclusion

If you have questions or comments please post them.  I will return to this post and tweak it a bit more to become really easy to use, but for now this is mostly what I did.