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

Categories
Workflow

Mac – Random Loss of Apache

Mac hung this morning. After rebooting (twice) and restarting Apache still had no httpd service.

Needed to separately run:

sudo apachectl stop
sudo apachectl start

Categories
Uncategorized

Dev Skills

Things to see and do.

  • Laracon videos
  • Refactoring to Collections
  • Dev Tools Debugging (breakpoints, watchers, exceptions etc.)

Categories
PHP

PHP Testing Databases

class ModelTest extends TestCase {
  use DatabaseTransactions;

  /** @test */
  function its_radical() {
    // Given, When, Then
    
    //Faker class for Article to generate fake data
    factory(Article::class, 3)->create();

    //variation
    factory(Article::class, 3)->create(['reads' => 10]); 
    
    $popular = factory(Article::class, 3)->create(['reads' => 22]);
    $articles = Article::trending()->get();

    $this->assertEquals($popular->id, $articles->first()->id);
  }
}

class Article {
  public function scopeTrending($q, $take) {
    return $q->orderBy('reads', 'DESC')->take($take);
  }
}

Categories
WordPress

WordPress Plugins of Note

Envira Gallery Lite

Categories
Workflow

Squashing Git Commits

Assuming none pushed to origin.

git rebase -i HEAD~n where n is number of recent commits to squash.

Vim will show commits from oldest to newest.

  • i to enter interactive mode.
  • make changes. Esc to leave interactive mode
  • :w to write
  • : x to execute (remove space between : x. Preventing emoji render)

PICK the oldest (first line).  SQUASH the subsequent commits.

Do a similar thing with Vim to edit the new commit message (interact, save, execute)

Categories
PHP

Xdebug Profiling with Qcachegrind

Enable xdebug profiling temporarily while you profile. You’ll kill a ton of disk space if you leave it on.

Install qcachegrind from homebrew (brew install qcachegrind)

By default cachegrind output files go to /var/tmp (I think).

Move somewhere useful. Open qcachegrind to read this file. It’s in:
/usr/local/Cellar/qcachegrind/18.04.1

Spotlight didn’t find it, so maybe create a symlink or something elsewhere.

 

Categories
PHP Workflow

Local Mac PHP issues

Update March 2019

brew services restart php@7.2

I was trying to change PHP settings, to be able to experiment with Xdebug profiling.

phpinfo() shows that it loads /usr/local/etc/php/7.1/php.ini , which is true, but didn’t seem the case because changes were not taking affect after restarting PHP and Apache.

I was restarting the wrong PHP with brew services restart php71. Even stopping it has no effect.
So that’s not the version that Apache is pointing to. It uses some other instance of the service that I don’t know how to restart without doing the whole computer!

Do this

sudo brew services restart php@7.1
brew services list can also be useful, or even brew services list | grep php

Categories
Servers

MySQL Create User and Grant Privileges

GRANT ALL PRIVILEGES ON mydatabase.* TO 'my_new_user'@'localhost' IDENTIFIED BY 'a great password';

Creates user and gives them privileges at once. Probably follow up with FLUSH PRIVILEGES

Categories
Servers

Moving Site Off Nginx

When you move a website and change its DNS A record you will need to delete it from the old Nginx server. Otherwise when Nginx reboots (e.g. after a certificate renewal) it will fail DNS resolution.

I believe this can be changed, but by default Nginx will break when the DNS connection (even of an unrelated site) changes.