VS Code Git Graph Extension

Updated: 03 February 2024

A reasonable layout for the VS Code Git Graph Extension which puts the diff view in the top half of the window.

Bottom left – Git Graph
Bottom right – Terminal
Top half – Diff view

Requires setting Git Graph ‘Open New Tab Editor Group’ equal to One.

How to configure PHP, Xdebug, Docker and PHPStorm

Updated: 15 November 2023

1. Select these two items in PHPStorm:
Run > Start Listening for PHP Debug Connections
Run > Break at first line in PHP scripts

2. Load a page in a web browser.

3. PHPStorm should display an Incoming Connection From Xdebug dialog box.

4. From the bottom of the dialog, select the local file which matches the ‘File path on server’ value and click Accept.

Deploy branch from intermediate bare git repo

Updated: 09 November 2023

Scenario

  1. I have a project on BitBucket.
  2. I work on this project locally.
  3. I want to deploy the changes to Production.
  4. Rather than pulling changes directly from Bitbucket to the working directory on the Production server, I need to go via a bare-repo on the Production server. The bare repo has been cloned from BitBucket earlier. This workflow is similar to deployments on Cloudways or Plesk.

Method

1. Push changes from local to BitBucket as normal.

2. From inside the bare repo directory on the Prod server, fetch all the changes from BitBucket

cd /bare/repo/my-proj.git
git fetch origin *:*

3. Transfer the changes to the working directory

cd /anywhere/on/the/system
git --work-tree /path/deploy/dir --git-dir /bare/repo/my-proj.git checkout --force my-branch

Tuxedo laptop with Windows in Virtual Box

Updated: 28 March 2024

I’ve had trouble running a Windows VM inside Virtual box on my Tuxedo laptop. The VM frequently crashes and sometimes consumes all the RAM of my host laptop also, requiring a restart.

Two good pieces of advice I’ve had from Tuxedo support:

  1. Turn off 3D acceleration: Virtual Box > The VM > Settings > Display > Enable 3D Acceleration.
  2. Limit the CPU the guest is able to use to 75%.

WordPress – unable to create directory

Updated: 16 January 2022

Resolution for ‘Unable to create directory’ error in WordPress.

This error is caused by an inappropriate set of folder and file permissions. The following statements assume you have shell access to the document root of your webserver.

Set owner and group of each folder and file to the webserver user
sudo chown -R www-data:www-data /var/www/html

Set permissions for all folders to 755
sudo find /var/www/html -type d -exec chmod 755 {} \;

Set permissions for all files to 644
sudo find /var/www/html -type f -exec chmod 644 {} \;

For problems uploading images, also check the uploads folder is set appropriately in WordPress Dashboard > Settings > Media. If already set to the default wp-content/uploads, this field may not be visible.

Homestead Vagrant xdebug3 vscode phpspec

Updated: 18 July 2021

Reset to original state

./vagrant destroy --force && ./vagrant up

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "log": true,
            "pathMappings": {
                "/home/vagrant/homestead.test": "/home/chris/code/homestead.test"
            }
        }
    ]
}

Start an ssh session

./vagrant ssh

Create the xdebug log file

sudo touch /var/log/xdebug.log && sudo chmod 777 /var/log/xdebug.log

Create xdebug settings
sudo nano /etc/php/7.4/fpm/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.mode = debug
xdebug.discover_client_host = true
xdebug.client_host = 192.168.10.1
xdebug.client_port = 9003
xdebug.max_nesting_level = 512

; required for cli debugging but for browser
; could omit and use query string at end
; of url instead XDEBUG_SESSION_START=name
xdebug.start_with_request = yes

; ensure file exists and is writeable
xdebug.log = /var/log/xdebug.log

Switch to cli PHP 7.4

php74

For cli debugging (alias xon=’sudo phpenmod -s cli xdebug’)

xon

After these changes

./vagrant reload --provision

Run phpspec

./vagrant ssh
tail -f /var/log/xdebug.log
project/dir vendor/bin/phpspec run

If vscode will not stop on a breakpoint try re-enabling PHP Debug extension and restarting vscode.

Run ngrok (outside of Homestead) pointing at a configured Homestead site

ngrok http 192.168.10.10:80 -host-header=site.dev