October 7, 2021

So, I’m documenting this for my own benefit for now, but I promise to eventually get around to making a proper tutorial out of it, but the process of setting a coworker up with a new localdev computer (when they’re not the sysadmin-y type), can get tedious. Especially if you’ve forgotten the dependencies.

Now, this works on Ubuntu 20.04.3 LTS, and I hope I didn’t forget anything, but here we go:

# Let's install GDebi because dependencies
sudo apt install gdebi
# and now VSCode (get the current version from https://code.visualstudio.com/download)
sudo gdebi Downloads/code_1.60.2-1632313585_amd64.deb
# unfortunately, this terminal doesn't seem inclined to remember we installed ZSH
sudo apt install zsh
# we'll need curl for this next one
sudo apt install curl
# and ohmyzsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# now time for some terminal goodness
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
# it's composer time
# because php, of course
sudo apt install php
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
# you might need this for composer globals to run
export PATH=~/.config/composer/vendor/bin:$PATH >> ~/.zshrc
# wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
# let's cleanup
sudo apt autoremove
# it's Homebrew time
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# and add the shellenv to .zshrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc
# and enable it for this session
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# now the goodies
brew install roots/tap/trellis-cli
brew install python
brew install mariadb
brew install gcc && sudo apt install build-essential
# let's start the MySql server now
mysql.server start
# Valet, baby
# but before that, another dependency
sudo apt install php-curl
# now
composer global require cpriego/valet-linux
# more Valet dependencies
sudo apt-get install network-manager libnss3-tools jq xsel
sudo apt install php-cli php-curl php-mbstring php-xml php-zip
# doing this shit because mcrypt has gone missing
sudo apt install php php-pear php-dev libmcrypt-dev
sudo pecl channel-update pecl.php.net
sudo pecl update-channels
sudo pecl search mcrypt
sudo pecl install mcrypt
sudo echo 'extension=mcrypt' >> /etc/php/7.4/cli/php.ini
sudo apt install php-sqlite3 php-mysql php-pgsql
# almost there, squeeze tight
valet install
# and just a little bit
sudo service apache2 stop
sudo service nginx start
# and finally, Trellis-cli
brew install roots/tap/trellis-cli

Presto! If you’re lucky, you may not even encounter errors along the way. This will probably need a couple of updates.

Now we only need to run valet link domain inside whatever site folder we have running to get domain.test up in the browser, SSL self-sign it with valet secure domain, and start importing databases (or contemplating your .env file, which you’ll need).

Now, about that database. You’ll need to create a user (named according to the username in the .env file), grant it permissions over the database and all that jazz. Basically the following, replace db_user, db_name and db_password as appropriate:

Open up a terminal and run mysql.
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'dbuser'@'localhost';
GRANT FILE ON *.* TO 'dbuser'@'localhost';

Now you should be good to go to either wp db create, wp db reset or wp db import.

About the author 

Vlad Tudorie

  • Regarding the following line:

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"\nphp -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"\nphp composer-setup.php\nphp -r "unlink('composer-setup.php');"

    …the terminal outputs the following error:

    You can use -r only once.


    I tried finding a workaround and installed a composer from synaptic. It installed, however, now could not find composer.phar on my system, so I skipped the following step

    sudo mv composer.phar /usr/local/bin/composer

    … also, the following path
    … had no composer directory inside it, so I had to skip this step to:
    export PATH=~/.config/composer/vendor/bin:$PATH >> ~/.zshrc

  • regarding the following line:

    chmod +x wp-cli.phar\nsudo mv wp-cli.phar /usr/local/bin/wp

    … the terminal output was the following:

    chmod: cannot access 'wp-cli.pharnsudo': No such file or directory
    chmod: cannot access 'mv': No such file or directory
    chmod: cannot access '/usr/local/bin/wp': No such file or directory

  • Regarding the following command:

    wp –info

    … the terminal output was the following:

    zsh: command not found: wp

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}