WordPress Development with LAMP

While I choose to develop for WordPress using LAMP there are alternatives such as MAMP, WAMP, XAMPP as well as services that provide a sandbox development environment such as Desktop Server and Local by Flywheel. This post only covers setting up WordPress using Ubuntu 20.04 Focal Fosa.

Installing WordPress for Local Development with LAMP

bash terminal illustration

LAMP must be installed prior to these steps I enjoy using this old tutorial. However, package names for PHP and others are outdated, be sure use the latest packages available for Ubuntu 20.04 Focal Fosa.

Begin by creating a folder in your hosting environment

Feel free to substitute scratch for your own folder name.

cd /var/www/html/
sudo mkdir scratch
cd scratch/

Creating a folder named scratch
Creating a folder named scratch to contain our WordPress website

Download and expand an archive of the latest version of WordPress.

sudo wget -c http://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz

Downloading and expanding the WordPress archive
Downloading and expanding the WordPress archive

After everything expands the files will be contained in a folder named wordpress. Now we can delete latest.tar.gz and move the files into our scratch folder then remove the wordpress folder itself.

Warning: This is a good time to warn you about the dangers of the rm command. It is a command to delete files, while superuser you can remove an entire directory and its contents so be sure you are in the scratch directory and targeting the correct wordpress folder.

sudo rm latest.tar.gz
cd wordpress/
sudo mv * ..
cd ..
sudo rm -rf wordpress/

Removing the download archive and moving our WordPress files.

Setting folder permissions

This next couple commands will provide permission for WordPress to operate with read and write access in the scratch folder.

sudo chown -R www-data:www-data /var/www/html/scratch/
sudo chmod -R 755 /var/www/html/scratch/

Setting up folder permissions for WordPress
Setting up folder permissions for WordPress

Create a MySQL database for WordPress

sudo mysql -u root -p

Change your database name to match your naming convention. and use a unique and secure password in place of password used here.

CREATE DATABASE wp_scratch;
CREATE USER 'scratch'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wp_scratch.* TO 'scratch'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Creating a WordPress database and a unique user
Creating a WordPress database and a unique user

Configure Apache for WordPress

sudo vim /etc/apache2/apache2.conf

Editing the apache2.conf file to allow pretty permalinks.

<Directory /var/www/html/scratch/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Configure Apache
Configure Apache

Run the following commands in the terminal to finish setting up Apache and then restart it along with MySQL

sudo a2enmod rewrite
sudo systemctl restart apache2.service
sudo systemctl restart mysql.service

Finish setting up Apache and restart services
Finish setting up Apache and restart services

If everything worked correctly you now have a localhost ready for WordPress development in using LAMP.

Visit http://localhost/scratch/ or the folder you used in place of scratch to complete the WordPress setup using the information you provided to MySQL.

Complete your WordPress Installation
Complete your WordPress Installation

Warning: If this server is intended to be used in a production environment use secure and unique passwords.


Building a WordPress Theme From Scratch

I’m a fan of using WordPress to build custom websites. So I’ve decided to start a tutorial series and share how I go about building a theme from scratch. No frameworks or starter themes.

The Sketch

Sketch of the theme's design
The layout sketch

Before even setting up my development environment I sketch a very basic layout for my theme. In this series we’ll use a simple layout that includes the following areas.

  • Site header & a primary navigation menu
  • Content area
  • Footer with secondary sidebar menu and a dynamic sidebar for widgets

The Outline

At any point you can review download or clone the repository which will possibly be a step or two ahead of the most recent post in the series.

All content will be offered free as in free beer as well as free software. The theme template files for Scratch JD are licensed under GPL3 and all content in this tutorial series is provided under Creative Commons Zero / Public Domain.


Lessons Learned From Presenting a Remote WordCamp Session

WP_Query, Going Beyond The Loop at WordCamp Santa Clarita April 18, 2020

As conferences have moved online to fight the spread of Coronavirus WordCamp Santa Clarita was one of the early WordPress events to try this new format. Here are my thoughts on how I could have improved my session for a distributed audience.

Cooking Looks Easier On Television

I grew up watching a lot of cable TV. One of my favorite tropes is that chef toiling over a cutting board passing fresh ingredients into spotless glass bowls. Ten minutes later pulling a flawless meal out of an oven.

Everything scripted and budgeted for time. A distributed conference is actually a lot like those cooking shows. No audience just a conversation with a camera.

Give Yourself Plenty Of Time To Prepare

Back in 2017 Chris Lema shared his process with me for preparing one of his standout conference sessions.

No matter how small or big the talk he would be ready to present two weeks early and rehearse a few days before. At my best I’m ready a week before. However, after a few talks I’ve found the closer I apply his advice the better things go.

My Usual Process

Before I submit my proposal for consideration I narrow down possible topics. Usually something I could present with no preparation whatsoever with anyone.

Next, I draft the proposal from beginning to end. Being sure not to cover too much or not enough for the time slot.

After I’ve submitted a proposal and before its accepted I’ll gather additional research materials and start taking detailed notes. I flow it into a nearly complete draft and consider possible additions or items that may need to be removed.

Once I’m approved to speak I start refining the final script and build out a slideshow and have everything done 14 days prior.

Well, a remote conference is a lot different from speaking at a podium in front of a poorly lit slide projection.

I Should Have Ditched My Slide Presentation

A good slide presentation is always valuable but lets be honest…When’s the last time we’ve watched a Powerpoint for fun on social media?

If I had this talk again I’d take a queue from those cooking shows and prepare each step in advance and present them to the audience step by step.

I’d probably still start and end with a slide presentation but at each point I’d jump into my WordPress templates and build the code live. Then, when it breaks… and it will. Just pull a working example out of the oven.

When it comes to code watching someone make errors live is just as valuable as seeing it work perfectly. It gives our audience a rare look into our problem solving process and developer workflow.

Broadcast Delays

Unfortunately the conference speakers all experienced at least a three minute delay with their audience. With no faces directly asking questions or responding in real time I missed an major opportunity in my talk… Where should we place the code? Yup, Its like I pulled bread out of an oven without mixing the ingredients together.

It wasn’t until the question and answer session that I realized I never mentioned WP_Query loops belong in a Child Theme’s template. If I were presenting the files live rather than slides the audience would have seen me open and close files moving content around and testing the results live! There would have been errors, it could have been glorious.

Don’t Panic! Success is in the oven, just off camera. ????