Categories
Workflow

Rename Default Git Branch

Rename on Github first.

Then:

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
Categories
PHP Workflow

Upgrading Local PHP with PHP-FPM

Updated and linked new version with Homebrew. Update path in terminal manager may help third party programs too.

PHP comes with its own PHP-FPM. For the new version I modified its config to run on a new port.

/usr/local/etc/php/8.0/php-fpm.d

e.g. ran this version at 127.0.0.1:9080

brew services restart php

Then in nginxcfg for a virtual host I updated its config to call php-fpm at that port. That site runs PHP 8.0. Others using old port seem to still be working with PHP 7.4.6. Unsure if that will survive a restart, or if only one version of php-fpm will be running (?)

Categories
Workflow

Restart Nginx Locally Mac

sudo brew services stop nginx
sudo brew services start nginx


Sudo because I have it bound to :80, which is otherwise not allowed.

Seems to work better than singular restart command (I think)

Categories
Workflow

Nginx fails after reboot

I later discovered…

I’d previously pointed a real domain to localhost for local dev. Nginx started at that time. I later changed hosts file and removed that connection. That caused Nginx to do a DNS lookup, and then fail to bind to the IP and refuse to start.

Once I removed that site from nginx/servers I was sweet!


Somewhere it’s trying to bind to a specific local network IP. If I’m at Wotso that failed and I started towards config debugging hell.

Restarted at home and it was ok. That’s a terrible setup, but it worked around it for now.

nginx needs to be started with sudo in order to listen on port 80.

Categories
Workflow

Nginx on Homebrew

Feb 2020 – replacing Apache with Nginx to fix broken dev env.

Nginx with PHP-FPM was giving 404 because the script name wasn’t being forwarded to PHP-FPM.

Needed this inside the fast_cgi file. It wasn’t there by default, but some random Googling turned it up 🙁

fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

Various Paths and Notes

  • Need system Apache to be off. (sudo apachectl stop)
  • May need to (re)start nginx and php-fpm
  • Create new local domains in /usr/local/etc/nginx/servers
  • nginx -t to test config
  • sudo nginx -s reload

Nginx may start as non-sudo/root user and lack permission to bind to :80

In that case I brew services stop nginx, then sudo brew services start nginx.

Paths

  • /usr/local/etc/nginx/ (nginx config)
  • /usr/local/var/www (old default location, I have since changed to my user /Code dir)
  • /usr/local/etc/php/7.4/
  • /usr/local/etc/php/7.4/php-fpm.d/www.conf
Categories
Workflow

Broken MySQL after Homebrew installing Qcachegrind

MySQL died after rebooting after installing Qcachegrind.

I think the problem was brew update doing a ‘prune’ which removed /usr/local/etc/my.cnf.d

I recreated it manually and was able to start MySQL

cd /usr/local/bin
sudo mysql.server start
Categories
Workflow

QCachegrind

I installed it with homebrew. That put it in:

/usr/local/Cellar/qcachegrind/18.04.1
open qcachegrind.app

Boom, you got a GUI.

Open cachegrind files that I have in /var/tmp.
Need to enable xdebug profiling for these to exist.

Categories
PHP Workflow

Xdebug Profiling

Installed xdebug with pecl install xdebug.

Enabled in extra .ini config file in:

/usr/local/etc/php/7.2/conf.d

Restart PHP with:

brew services restart php72

The webcachegrind script does not seem to work. It lists only a few of the cache files, and they often do not match their description. For example the filename will appear to be webcachegrinds own PHP script, but all the data relates to a different WordPress script. Out of sync with the requests.

Might need a different tool like QCachegrind.

Currently cachegrind files are in /private/var/tmp

Categories
Workflow

Fixing the PHP-FPM User/Group File Permissions

After upgrading to PHP7.2 php-fpm was running as the _www user. PHP worked, but was unable to write to most files.

Needed to change php-fpm to use my own Mac user and group. Biggest difficulty was finding where my actual version of Apache & PHP are configured and where error logs are written. This is due to Homebrew adding to the native installs.

Try these paths if it happens again.
(May not be correct as I tried a lot of things to get this fixed)

Apache

Config  /usr/local/Cellar/httpd24/2.4.27
Logs   /usr/local/var/log/apache2

(Defined in /usr/local/etc/apache2/2.4/)

PHP

/usr/local/etc/php/7.2/php-fpm.d
Categories
PHP Workflow

Upgrading to PHP 7.2 locally

Tried for brew install php@7.3 – produced errors. No go 🙁

Went for 7.2 instead. Installed ok, but brew link php@7.2 didn’t work (errors).

Manually edited ~/.bash_profile to add new PHP to PATH

export PATH="/usr/local/Cellar/php@7.2/7.2.15/bin:PATH"

That got command line PHP up to date. Fast CGI config needed to be updated to listen to port 9072. Unfortunately I’ve broken the multi-version setup. Now PHP-FCGI only listens to 9072 for PHP 7.2 (no access to 5.6 or 7.1 at the moment).

/usr/local/etc/php/7.1/php-fpm.d
/usr/local/etc/php/7.2/php-fpm.d (updated this to :9072)

So Apache config (httpd-vhosts.conf) needs to point to :9072 to work.

This article at GetGrav looks very thorough, but takes a different approach of using a PHP switcher script, rather than FPM listening on different ports for different versions.

See: restarting local PHP