In the digital realm, maintaining order and organization can be as satisfying as tidying up a physical space. For those like me who appreciate neatness, keeping WordPress core files in a dedicated subdirectory is a preferred practice. However, when it comes to Pantheon managed WordPress hosting, achieving this can be a bit challenging. In this guide, we’ll explore the concept of “WordPress in its Own Directory” on Pantheon and provide you with a solution to implement it seamlessly.
If you’re unfamiliar with the concept, “WordPress in its own directory” involves placing all core WordPress files and directories (such as wp-includes and wp-admin) inside a subdirectory within your website’s document root, rather than having them directly in the document root itself.
This approach offers several benefits:
- A cleaner and more organized file structure for those who value aesthetics and order.
- The ability to configure your web server to restrict unauthorized access to the WordPress directory, enhancing security. (Note: This may affect WordPress auto-updates.)
- Simplified management of WordPress core and plugins when using Composer, particularly when they are contained within a subdirectory.
Let’s delve into the steps to achieve this on Pantheon.
Before we proceed, let’s establish some assumptions and prerequisites:
I assume you have configured your pantheon.yml file with
web_docroot: true, which sets the document root to
/code/web instead of just
/code. This is for better organization and security.
We will use the subdirectory named
wp/ to house WordPress core files. You can choose a different name if you prefer, but for consistency, we’ll stick with
wp/ in this guide.
For convenience, we’ll refer to the website as “mysite.”
I’m using an empty WordPress upstream for all Pantheon sites. If you use Pantheon’s default WordPress upstream, you may need to adjust these instructions accordingly.
This guide assumes a certain level of command-line Linux proficiency, including git cloning and symbolic linking.
Let’s begin the process of relocating WordPress to its own directory:
mysite) onto your local machine using
web/directory for your WordPress files. We’ll call it
wp-includes, etc.) into the newly created
wp/directory. Ensure you include files like
readme.html. Notably, exclude
index.phpfile from the
web/directory, and modify the last line to read:
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
wp-config.phpfile. Since Pantheon provides a customized
wp-config.php, keep it in the
web/directory (outside of
wp-config.php, find the line starting with
define('WP_SITEURL',and modify it to read:
define('WP_SITEURL', $scheme . '://' . $_SERVER['HTTP_HOST'] . '/wp');
define('WP_SITEURL'…line, add these two lines:
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
define( 'WP_CONTENT_URL', WP_HOME . '/wp-content' );
Now, you can test your website on your development environment. If it works correctly, proceed to test it on the staging environment and finally on the live site.
During my transition to Pantheon, I encountered issues with cache clearing when using “WordPress in its own directory.” To resolve this, I discovered a crucial configuration file:
wp-cli.yml. Follow these steps:
terminus env:clear-cache mysite.live
wp-cli.ymlin the root (code/) directory of your Pantheon project with the following content:
This file specifies the path to your WordPress installation within the
You may encounter issues with wp-cli commands related to plugins and themes. To address this, create a symlink to your
wp-content/ directory within the
mysite/web/wp$ ln -s ../wp-content wp-content
Commit this change to your Git repository and push it to your Pantheon repository. Then, deploy these changes through the Pantheon dev/test/live workflow.
With these adjustments, running wp-cli commands like
terminus wp mysite.live -- plugin list should now provide a complete list of your plugins and themes.
While the process of organizing your Pantheon installation with “WordPress in its Own Directory” may not be extensively documented, it is a valuable technique for those who appreciate digital neatness. I hope this guide has helped you achieve a cleaner, more organized WordPress setup on Pantheon. It’s worth noting that Pantheon has shown interest in improving documentation for this approach, so stay tuned for potential updates.
If you’re a perfectionist when it comes to digital order, implementing these steps can significantly enhance your Pantheon hosting experience, ensuring everything is in its rightful place and functioning correctly.
The Crucial Role of Clients in App Development The process of creating a successful mobile application begins with a spark of an idea from the client, not the app development company. The client formulates the concept that will be transformed into a functional app, collaborating closely with app developers who can enhance and refine theRead more
Smartphones have transformed the way we access information and communicate, with mobile apps becoming an integral part of our daily lives. In this dynamic landscape, iOS app development stands out for its ability to deliver high-quality, feature-rich applications. As a result, iOS app developers are constantly pushing the boundaries of creativity to cater to theRead more
iOS app development is a dynamic process that involves creating mobile applications exclusively for Apple devices, including the iPhone, iPad, and iPod Touch. This article explores the intricacies of iOS app development, from the initial requirements to the final steps of publishing your app on the App Store. The World of iOS App Development iOSRead more