7.4 KiB
Setting Up a MainWP Development Environment
This guide walks you through setting up a development environment for MainWP extension development. A proper development environment will make your development process more efficient and help you avoid common issues.
Quick Start for Experienced Developers
- Install Laragon (or similar local development environment)
- Set up WordPress (latest version)
- Install and configure MainWP Dashboard plugin
- Add at least one test child site (local or remote)
- Clone the MainWP Development Extension:
git clone https://github.com/mainwp/mainwp-development-extension.git
- Start developing your extension
Why Use a Local Development Environment?
Developing MainWP extensions in a local environment offers several advantages:
- Speed: Local development is faster than working on a remote server
- Safety: You can experiment without affecting live sites
- Offline Work: You can work without an internet connection
- Version Control: Easier integration with Git or other version control systems
- Debugging: Better access to logs and debugging tools
Recommended Development Tools
Local Development Environment
We recommend using Laragon for MainWP extension development because it:
- Is easy to set up and use
- Includes all necessary components (Apache, MySQL, PHP)
- Supports multiple PHP versions
- Includes helpful developer tools
- Makes it easy to create and manage multiple local sites
Other options include:
Code Editor
A good code editor will make your development more efficient. We recommend:
- Visual Studio Code with PHP extensions
- PhpStorm
- Sublime Text
Version Control
Using Git for version control is highly recommended:
- Git
- GitHub Desktop (for a user-friendly interface)
- GitKraken
Browser Developer Tools
Modern browsers include developer tools that are essential for debugging:
Step-by-Step Setup Guide
1. Install Laragon
- Download Laragon from laragon.org
- Install Laragon following the installation wizard
- Launch Laragon
2. Create a WordPress Installation
- In Laragon, click "Menu" > "Quick app" > "WordPress"
- Enter a name for your site (e.g., "mainwp-dev")
- Laragon will create a new WordPress installation
- Once complete, click the link to open your new WordPress site
- Complete the WordPress installation process
3. Install MainWP Dashboard
- Log in to your WordPress admin dashboard
- Go to "Plugins" > "Add New"
- Search for "MainWP Dashboard"
- Click "Install Now" and then "Activate"
- Follow the MainWP setup wizard to configure the dashboard
4. Set Up Test Child Sites
For a complete development environment, you'll need at least one child site to test your extension with.
Option 1: Create Local Child Sites
- In Laragon, create additional WordPress installations for child sites
- Install and activate the MainWP Child plugin on each site
- Connect these sites to your MainWP Dashboard
Option 2: Use Existing Remote Sites
If you have existing WordPress sites, you can use them as test child sites:
- Install and activate the MainWP Child plugin on each site
- Connect these sites to your MainWP Dashboard
5. Clone the MainWP Development Extension
- Open a terminal or command prompt
- Navigate to your WordPress plugins directory:
cd path/to/laragon/www/mainwp-dev/wp-content/plugins
- Clone the MainWP Development Extension:
git clone https://github.com/mainwp/mainwp-development-extension.git
- Activate the extension in your WordPress admin dashboard
6. Configure PHP Development Settings
For effective development and debugging, configure PHP with appropriate settings:
- In Laragon, click "Menu" > "PHP" > "php.ini"
- Ensure the following settings are enabled:
display_errors = On error_reporting = E_ALL
- Save the file and restart Laragon
7. Install Additional Development Tools
Composer
Composer is a dependency manager for PHP that makes it easy to manage libraries and dependencies:
- Laragon includes Composer by default
- To use it, open Laragon Terminal and run:
composer --version
WP-CLI
WP-CLI is a command-line tool for managing WordPress:
- Laragon includes WP-CLI by default
- To use it, open Laragon Terminal and run:
wp --version
Query Monitor
Query Monitor is a debugging plugin for WordPress:
- In your WordPress admin, go to "Plugins" > "Add New"
- Search for "Query Monitor"
- Install and activate the plugin
Development Workflow
Once your environment is set up, here's a recommended workflow for developing MainWP extensions:
- Plan your extension: Define its purpose, features, and how it will integrate with MainWP
- Create a new extension based on the MainWP Development Extension template
- Implement features incrementally, testing each one as you go
- Test thoroughly with different configurations and child sites
- Debug and refine your code
- Package for distribution when ready
Debugging Tips
WordPress Debugging
Enable WordPress debugging by adding these lines to your wp-config.php
file:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
Debug logs will be saved to wp-content/debug.log
.
MainWP Specific Debugging
MainWP includes several debugging options:
- Go to "MainWP" > "Settings" > "Advanced Options"
- Enable "Development Mode" for additional debugging information
- Use the "MainWP Tools" section for diagnostics
Common Issues and Solutions
Connection Issues Between Dashboard and Child Sites
If you're having trouble connecting your MainWP Dashboard to child sites:
- Ensure both sites are accessible from the internet (or use a tool like ngrok for local sites)
- Check that the MainWP Child plugin is properly installed and activated
- Verify that your server meets the MainWP requirements
- Try using the Connection Recovery process in MainWP Dashboard
PHP Version Compatibility
MainWP requires PHP 7.0 or higher. To change PHP versions in Laragon:
- Click "Menu" > "PHP"
- Select the desired PHP version
- Restart Laragon
Next Steps
Now that your development environment is set up, you're ready to start creating your MainWP extension: