Category: Notes

  • Increase PHP memory limit in Laravel Valet

    In /opt/homebrew/etc/php/8.0/php.ini – or whichever PHP version you’re running – find and increase memory_limit to 512M or 1024M or whatever you need to debug.

    (If the memory_limit line is commented out – i.e. has a prefix of ; – make sure to remove it).

    You may also need to add the following line to your wp-config.php (matching whatever value you set in php.ini):

    define( 'WP_MEMORY_LIMIT', '1024M' );

    Finally, you should probably run valet restart from the command line.


  • Fix 504 Gateway Timeout in Laravel Valet

    Add:

    proxy_connect_timeout 1200;
    proxy_read_timeout 1200;
    proxy_send_timeout 1200;
    fastcgi_read_timeout 1200;
    fastcgi_send_timeout 1200;

    In /opt/homebrew/etc/nginx/nginx.conf, right before:

    include "/Users/.../.config/valet/Nginx/*";
    include servers/*;
    include valet/valet.conf;

    All credit to / solution from:

    https://github.com/laravel/valet/issues/315#issuecomment-1362039656

    https://dev.to/aubreypwd/how-i-configured-niginx-valet-to-stop-the-504-gateway-time-out-during-long-xdebug-sessions-174i


  • Pull all remote git branches to local

    Used this when moving away from a git repository that it wasn’t possibly to transfer. Unfortunately the repository had a lot branches that I wanted to keep a copy of just in case.

    So I used the following bash script to pull them all down locally so I had a backup.

    #!/bin/bash
    
    # Clone the repository
    git clone [email protected]:username/repository.git
    
    # Navigate into the repository
    cd repository.git
    
    # Fetch all branches
    git fetch --all
    
    # For each remote branch
    for branch in `git branch -r | grep -v HEAD`;do
        # Get the name of the branch without the "origin/" prefix
        name=`echo $branch | cut -d/ -f2-`
    
        # Create and checkout local branch
        git checkout -b $name $branch
    done

    Just replace username and repository with the actual username and repository name.

    Save this script to a .sh file, give it execute permissions with chmod +x scriptname.sh, and then run it with ./scriptname.sh.


  • Use –precise if wp search-replace does not get all matches

    I just discovered that you can add the --precise flag when using wp search-replace with WP-CLI.

    I’ve never needed to use this before, so I wouldn’t suggest using it by default, but I had a site that was stubbornly refusing to replace all instances of a test domain after switching to the production domain and this solved it.


  • Solving MySQL error with Laravel Valet on macOS Ventura

    After updating to macOS Ventura, everything seemed to be fine with my Laravel Valet (v4.1.2) setup, but after restarting / doing some other thing which screwed everything, I couldn’t connect to the database properly.

    I tried everything.

    In the end how I fixed it was abandoning MariaDB (& removing all any any traces of it), dumping the my.cnf file in /opt/homebrew/etc and install MySQL v8.0.33 via homebrew.

    How much of that was really necessary, I’m not sure, but the key step was deleting the my.cnf file in /opt/homebrew/etc.

    Until then the brew install mysql would continually fail at the last step on the brew postinstall mysql step.

    (When I tried it ignore this step I would constantly bump into an ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error).

    In case it was relevant, I also completely removed Laravel Valet – valet uninstall force – and only re-installed it after I was sure MySQL was OK.

    I also switched to using PHP v8.0 locally (as that’s what I’m running all my sites on right now anyway) before doing the valet install (including the initial composer install).

    EDIT #1: Here’s what the my.cnf file looked like once it was working again:

    # Default Homebrew MySQL server config
    [mysqld]
    # Only allow connections from localhost
    bind-address = 127.0.0.1
    mysqlx-bind-address = 127.0.0.1

    EDIT #2: Found similar solution here https://andy-carter.com/blog/resolving-post-install-issue-with-mariadb-install-via-homebrew