Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress Plugin Development Cookbook

You're reading from   WordPress Plugin Development Cookbook Create powerful plugins to extend the world's most popular CMS

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher
ISBN-13 9781788291187
Length 386 pages
Edition 2nd Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Yannick Lefebvre Yannick Lefebvre
Author Profile Icon Yannick Lefebvre
Yannick Lefebvre
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Preparing a Local Development Environment FREE CHAPTER 2. Plugin Framework Basics 3. User Settings and Administration Pages 4. The Power of Custom Post Types 5. Customizing Post and Page Editors 6. Accepting User Content Submissions 7. Customizing User Data 8. Creating Custom MySQL Database Tables 9. Leveraging JavaScript, jQuery, and AJAX Scripts 10. Adding New Widgets to the WordPress Library 11. Enabling Plugin Internationalization 12. Distributing Your Plugin on wordpress.org

Installing a web server on your computer

The first step to configure a local development environment is to install a local web server on your computer. This will transform your computer into a system capable of displaying web pages and performing all tasks related to rendering a WordPress website locally.

Having a local web server has many benefits, as follows:

  • It provides a quick response to the frequent page refreshes that are made as plugin code is written, tested, and refined, since all information is processed locally
  • It removes the need to constantly upload new plugin file versions to a remote web server to validate code changes
  • It allows development to take place when no internet connection is available (for example, when traveling on an airplane)
  • It offers a worry-free programming environment, where you cannot bring down a live website with a programming error or an infinite loop

There are many free packages available online that contain all of the web server components necessary to run a WordPress installation. This recipe shows you how to easily install one of these packages.

How to do it...

  1. Visit the XAMPP website (https://www.apachefriends.org/) and download the appropriate XAMPP package for your computer.
XAMPP is available for Windows, macOS, and Linux platforms. The screenshots in this recipe were taken from XAMPP version 5.6.30 on Windows 10. The installation steps and exact dialog content might vary based on your choice of platform.
  1. Optional on Windows: Disable the Windows User Access Control (UAC) feature to give full permissions to XAMPP to install itself on your system (look up the steps to perform this procedure on your favorite search engine).
  2. Launch the XAMPP installer (xampp-win32-5.6.30-0-VC11-installer.exe on the Windows platform).
  3. Acknowledge the warning message about User Access Control (UAC) and click on Next to start the installation process.
  4. On the following screen, which lists all of the components that can be installed, uncheck the boxes for FileZilla FTP Server, Mercury Mail Server, Tomcat, Perl, and Webalizer, then click on Next:
  1. On the Installation folder screen, leave the default value for the installation directory if possible (c:\xampp), since some references to this folder will be made in this book, then click on Next.
  2. Click on the Next button to proceed with the web server installation.
  3. Make sure that the option to start the Control Panel is checked and click on Finish once the installation is complete.
  4. Select your preferred language for the XAMPP Control Panel and click on Save to launch the application.
  5. Click the Start buttons for Apache and MySQL to launch these modules. Their names will be highlighted in green once they have been successfully started, as shown in the following screenshot:
  1. Open a web browser and navigate to the address http://localhost to display your local web server's welcome page:
  1. Open the c:\xampp\apache\conf\httpd.conf file in a text editor (for example, Notepad).
  2. Search for the DocumentRoot configuration option and change its value to a different location on the disk to avoid keeping your project files under the original installation directory. For example, you could set it to a new directory designed to hold your local development installation of WordPress, such as DocumentRoot "C:/WPDev".
Notice that forward slashes are used in this path. You should be careful if you copy and paste a path from a file explorer window.
  1. Search for the Directory option and change it to the same path that was used for DocumentRoot, that is, <Directory "C:/WPDev">.
  2. Save and close the httpd.conf file.
  3. Create the directory specified as DocumentRoot, if it does not already exist on your computer.
  4. Open XAMPP Control Panel.
  5. Stop and re-start the Apache service for the new configuration to take effect.
Trying to access the local web server's welcome page will no longer work after having performed steps 14 through 20, since the new directory specified is currently empty. This will be corrected in the next recipe.

How it works...

The XAMPP package contains all of the components necessary to run a web server capable of hosting a WordPress website on your computer. These components include:

  • Apache web server
  • PHP interpreter
  • MySQL database server
  • phpMyAdmin database management interface

The XAMPP package also includes other components, which are not required to run a local WordPress development site.

Once XAMPP is installed and started, the keyword localhost that we type in the web browser is recognized by the operating system as a request to communicate with the web server on the local computer and the Apache web server displays the welcome page from its documentation.

The XAMPP documentation is a set of flat HTML files located in the c:\xampp\htdocs directory on the Windows platform. This is the web server's default working directory.

The last few steps of the recipe instruct the Apache web server to look for the local website's content in a new directory. This is a safety precaution to be sure that site files are not deleted inadvertently if XAMPP is uninstalled. It can also help in managing multiple sites on a single computer.

There's more...

While XAMPP is a full-featured local web server package and is available on the three major operating systems, there are many others available online. Most of these packages will run the required web services on the computer directly, while more advanced packages, such as Varying Vagrant Vagrants (VVV), will virtualize a Linux-based web server on your computer to create a more accurate replica of a final deployment environment optimized for WordPress. Here is a list of some of the most popular local web server packages:

For Windows:

For macOS X:

For Windows, Mac, or Linux:

For a more complete list of web server packages, visit https://en.wikipedia.org/wiki/List_of_AMP_packages.

Creating a remote web development environment

If it's not possible for you to set up a local web server to develop WordPress plugins, or if you are planning to share the development tasks with one or more people, then an alternative to setting up a local web server is to create a remote development environment.

The easiest way to create such an environment, assuming that you already have a web hosting account set up, is to create a sub-domain off your main domain. This will allow you to create a standalone test installation for WordPress that will still provide safety from affecting a live site, but will not carry the other benefits of a local installation.

See also

  • The Downloading and configuring a local WordPress installation recipe
You have been reading a chapter from
WordPress Plugin Development Cookbook - Second Edition
Published in: Jul 2017
Publisher:
ISBN-13: 9781788291187
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image