Skip to content

Development with LocalWP

LocalWP is a development stack aimed for WordPress Developement (but also works with Laravel and other PHP Applications) available on macOS, Windows, and Linux.

While LocalWP was originally designed to work with Flywheel Hosting and WPEngine, You can use itto develop WordPress and PHP Application for any hosting provider including Cloudways.

Features

LocalWP was designed to give you the environment as close as the real web server as possible while keep everything simple.

  • Support PHP from 7.4 to 8.4. User can freely choose which version to run per project.
  • Support both Nginx and Spache.
  • Support local domain with self-signed SSL, enabel developer to develop feature which require HTTPS (such as Geolocation API) locally.
  • Ship with Mailpit to cache email sent out locally without the need of setting up SMTP Server.
  • Integrated with LiveLink, let developer send out preview link for their local website.

Create new project

Follow these steps to create a new local WordPress project using LocalWP:

  1. Launch LocalWP and Click the ➕ (plus) icon located at the bottom-left corner of the LocalWP window. Main Screen
  2. Select Create a new site and click ContinueMain Screen
  3. Enter website name. You can customize local domain or change project directory by clicking on Advanced options. Click Continue when done. Main Screen
  4. You may choose a Preferred or Custom environment. It’s recommended to match your production environment as closely as possible.
    • Select the PHP version, web server (Apache or Nginx) that matches your production setup.
    • If unsure, check your production server details or ask your developer. Main Screen
  5. Enter username and password for Admin account. You can also change site language and enable multisite capability in Advanced options. Then click Add SiteMain Screen
  6. LocalWP will start provisioning your website. It may ask for your computer password. Once provisioning is finished, you can now access your website. Main Screen

Import project from staging/production

Setup local HTTPS

Some feature (such as JavaScript Geolocation API or Service Workers) required HTTPS to work with. To enable HTTPS in LocalWP site, please follow these steps

  1. Go to WP-Admin > Settings > Gerneral, then update both WordPress Address (URL) and Site Address (URL) to be HTTPS.

  2. Go to LocalWP dashboard. Select Overview, under SSL section, click on Trusted

    In recent version of macOS, Applications can no longer automatically trust self-signed certificate. User need to trust the certificate manually.

  3. Open Keychain Access app. Go to System > Certificates, you will find a certificate with the same name of the project with red x icon Keychain Access

  4. Double click that certificate, expand the Trust section, then change value of When using this certificate to Always TrustTrusting certificate

  5. Keychain will ask you to enter password to confirm. Once done, you should be able to access the local website via HTTPS.

Update configuration for WP-CLI

macOS run most apps inside sandbox, including LocalWP, for security reason. Though this approach make it impossible for PHP that installed outside the sandboxed enviroment to directly connect to service running inside sandbox.

In short, wp-cli installed locally won't work with LocalWP.

To mitigate the issue, we have to tell WordPress to connect to database via sock.

Go to the project inside LocalWP then navigate to Database tab of said project. Copy the value in SocketLocalWP

from the image above, the Socket would be:

/Users/jirayu/Library/Application Support/Local/run/_SsCQnook/mysql/mysqld.sock

Open wp-"config.php of the project. then update the key DB_HOST with socket path. Also add localhost: at the front. For example:

php
define( 'DB_HOST', 'localhost:/Users/jirayu/Library/Application Support/Local/run/_SsCQnook/mysql/mysqld.sock');

Work with Git

There are two scenarios here

  1. Newly created project. Never added to git repository before.
  2. Existing project. Continue working on a project that already in git.

Newly created project

Let's say we are starting a new project. We have created a git repository on GitHub and ready to push the initial commit.

An empty git repository

Existing git project