Posts

Debugging multiple PHP projects with VS Code and Laragon

Laragon is a great solution for developing PHP, and especially Laravel, projects on Windows.
It bundles together Apache, PHP, MySql and automatic host resolution based on folder names.
It's great...
Until...
You try and debug in VS Code using XDebug when multiple sites on your local machine are hit in quick succession resulting in multiple connections from apache being opened against port 9000 on your VS Code instance at the same time.

This manifests itself in VS Code by not hitting any breakpoints and just showing "Request 1" and "Request 2", or similar, in the debug call stack.

In my environment, I have a main project containing middleware that does a security check against a second project before hitting my main action in my controller. Both PHP instances fire off their XDebug connections on port 9000, as xdebug.remote_autostart=1 in the PHP ini file.

Normally this is fine as only one project is practically running at once, but the middleware causes the two …

Reformatting a php.ini file with Sublime Text 3 for use with Ansible

So quite a specific post this...

PHP .env files are of the format

KEY_A=true
KEY_B="This Is Another Value"

To set variables for use with a Jinja2 template they need to be something along the lines of

key_a: true
key_b: ThisIsAnotherValue

In Sublime Text in the replace all (CTRL+H)
Make sure that regex matching is on and not to preserve case.

Find What: (.+)=(.+)
Replace With: \L$1\E: $2

This will replace two groups of one or more characters. The first will be lowercased, the equals replaced with a colon and then the second group in its original case.

Then the original .env file can have the following in the Jinja2 template

KEY_A={{key_a}}
KEY_B={{key_b}}

Useful Vagrant plugins

Some useful Vagrant plugins I've picked up along the way

vagrant-hostmanager
Updates your host file with entries

vagrant-reload
Allows you to reload the vm during provisioning

vagrant-share
Allows sharing access remotely to vms

vagrant-vbguest
For automatically updating the virtualbox plugins

vagrant-winnfsd
NFS for sharing folders

Vagrant not working after fresh Windows 10 x64 install

After recently re-installing Windows 10 x64 I discovered that to get vagrant to download box images, it uses an embedded version of curl. This requires the Microsoft Visual C++ 2010 Service Pack 1 Redistributable Package x86 version.

Occasionally making phpunit work with PhpStorm and homestead

When using homestead on vagrant I find that I need to use ssh/sftp setup for the server and interpreter for it to get the path mappings correct.

Settings I configure

"Build, Exection, Deployment" -> "Deployment"
Add an entry for the server and set its "Type" to be "SFTP".
In the "Connection" tab, set the details according to the information obtained by running "vagrant ssh-config".
Set the "Auth type" to "Key pair" and set the "Private key file" to be the location of the IdentityFile from the ssh-config.

In the "Mappings" tab, make sure that the deployment path remote server location matches the local path.

Set up the PHP interpreter by going to "PHP" and adding a remote Interpreter. Set the remote to be based on the "Deployment configuration", saves you setting up all the SSH information again.

In "PHP" -> "PHPUnit" add a "Remote Inter…

Making node / npm / gulp / elixir work for Laravel using Homestead on Vagrant with Virtualbox on Windows

Wow what a title. More of a note to myself this one.

Problem: npm install or variants thereof cause errors, mainly related to long filenames when run inside a homestead virtualbox virtual machine on Windows.

A simple fix is to create a symbolic link inside the vm for the node_modules path so that it doesn't reside inside the folder being shared with the Windows file-system.

Modify the Vagrantfile or the scripts/homestead.rb file if using homestead to include the following as part of the config:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

Then you'll need to run the Git Bash shell as admin, otherwise it won't let you create the symbolic links. The important part here is actually that winnfsd.exe starts as admin so you could change the compatibility in the properties to start as admin.

Start vagrant with a "vagrant up"

Once you…