This is a guide on who is mac Terminal lover and I show you how to set up Laravel Valet on macOS for a WordPress local development environment with WP-CLI
Valet runs only on macOS and runs directly on top of the operating system, not in a virtual container.
Valet itself has an Nginx, PHP7+ (latest version is 7.3), MariaDB or MySQL (I prefer MariaDB), DnsMasq and by default uses the .test domain name. Once the software is all installed Valet itself will launch automatically on startup.
So, let’s start:
1. Install or update Homebrew to the latest version using brew update
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Install PHP latest version
brew install php
3. Install MariaDB instead of MySQL
brew install mariadb
Now set MariaDB root user
sudo mysql -u root
mysql> USE mysql;
mysql> SELECT User, Host, plugin FROM mysql.user;
You’ll see this
+------------------+-----------------------+
| User | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
As you can see in the query, the root user is using the auth_socket plugin.
Run this command and reset the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Now your mySQL login password is: root
4. Download composer from this link: https://getcomposer.org/installer
5. Rename it “composer.phar”
6. Run PHP Phar
php composer.phar
7. Move it to composer directory
mv composer.phar /usr/local/bin/composer
8. Run Valet command
composer global require laravel/valet
then this
export PATH=$PATH:~/.composer/vendor/bin
9. Now create a directory, for an example, I have created a directory on my user directory called “www”
valet install
10. Now park your directory
valet park
How to use phpMyAdmin with Laravel Valet?
Go to download phpMyAdmin and extract the zip file.
Install phpMyAdmin
move the zip file and rename it to “pma”. See screenshot #9. PMA means, phpMyAdmin.
First, go to pma directory, run this command on the Tutorial:
valet link
Valet Commands
valet start
it starts the server. By default, it is running in the background.
valet stop
it stops the server. If you are very low in resources, you should stop it after you are done using it.
How to install WP-CLI
Download the wp-cli.phar file using wget
or curl
:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Next, check the Phar file to verify that it’s working:
php wp-cli.phar --info
To use WP-CLI from the command line by typing wp
, make the file executable and move it to somewhere in your PATH. For example:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
If WP-CLI was installed successfully, you should see something like this when you run wp --info
:
$ wp --info
OS: Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64
Shell: /bin/zsh
PHP binary: /usr/local/bin/php
PHP version: 7.0.22
php.ini used: /etc/local/etc/php/7.0/php.ini
WP-CLI root dir: /home/wp-cli/.wp-cli/vendor/wp-cli/wp-cli
WP-CLI vendor dir: /home/wp-cli/.wp-cli/vendor
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.3.0
Updating
You can update WP-CLI with wp cli update
(doc), or by repeating the installation steps.
If WP-CLI is owned by root or another system user, you’ll need to run sudo wp cli update
.
Want to live life on the edge? Run wp cli update --nightly
to use the latest nightly build of WP-CLI. The nightly build is more or less stable enough for you to use in your development environment and always includes the latest and greatest WP-CLI features.