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
Servers

Changing PHP Upload limit on my Binary Lane VPS

php.ini is at /etc/php/7.3/fpm/php.ini

Change max_upload and post_max sizes (not their exact name, do a search for current value).

Restart PHP with this command:

service php7.3-fpm restart
Categories
JavaScript

JavaScript Thingies

Destructuring

let idaCalledEm, others
[idaCalledEm, ...others] = ['Chazwazzars', 'Simpsons', 'or perhaps', 'Futurama Quote']

To Do: Incorporate Wes Bos’ default object parameter post.

Categories
Uncategorized

Patterns That Pay Off

Notes from Matt Stauffer’s talk.


/*
View Model
*/
class DashboardViewModel
{
    function topTasks()
    {
        $overdue = $this->overDueTasks();
        return array_merge($overdue, $this->fillTasksDueSoon( count($overdue) ));
    }

    function progressChart()
    {
        return [
            'complete' => $this->progressDone(),
            'date_markers' => $this->dateMarkers()
        ];
    }

}

return view('dashboard')->with('vm', new DashboardViewModel($user));

?>

View Data Composition

Presenter
    Layer above other thing, usually the model, to give it more powers.

View Model
    PHP Object for organizing this logic 

Responsable (sic)
    interface in Laravel for PHP object that can be converted to Response 

View Models

These seem fairly easy to understand. A class that wraps a model, providing methods for data access that a view will need. Moves the complexity of querying out of Controller.

And nicer than putting straight on model which complicates it in a lot of unrelated contexts.

Categories
Frontend

Data List HTML suggestions

<input type="text" list="planets">
<datalist id="planets">
    <option value="Mercury"></option>
    <option value="Venus"></option>
    <option value="Earth"></option>
</datalist>
Categories
Servers

503 Bad Gateway on Ubuntu Server

Rebooted Ubuntu web server and PHP-FPM wasn’t running.
Just needed the old:

service php7.3-fpm start
Categories
Servers

Remove Non-Empty Directory

rm -rf my_directory_name

Be careful.