You can setup WordPress in a sub-directory using composer, thanks to John P Bloch‘s WordPress Core Installer. Below I’ve outlined the bare minimum steps to get this running.
Step 1: composer.json
Create a composer.json
in the root of your project with the following content.
{
"require": {
"johnpbloch/wordpress": "*"
}
}
Step 2: Execute composer
If you don’t have composer installed already, install composer. Then run the following from the command line at the root of your project.
composer install
At this point you should have a wordpress
directory with your core files.
Step 3: Copy index.php
Copy wordpress/index.php
to index.php
. You can do this from the command line with
cp wordpress/index.php ./index.php
Step 4: Modify index.php in your project root
The index.php in the root of your project (the one you just created via a copy command) should be modified.
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
becomes
require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
Step 5: Create wp-config.php
Create wp-config.php
(and the database if it does not yet exist). Add the following lines to wp-config.php
. These lines keep wp-content and its contents in the default installation location even though the core files are loaded from the /wordpress
directory.
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' );
define ('WP_CONTENT_URL', 'http://wpsubdir.dev' . '/wp-content' );
Step 6: Set up WordPress
Visit your website and setup the database and your initial user (this is the same procedure for any WordPress website).
Step 7: Adjust the Site Address
At this point, your WordPress site should be setup in your sub-directory (e.g. http://wpsubdir.dev/wordpress/). However, generally we want the site to load in the top level directory (e.g. http://wpsubdir.dev/).
We make this change at Settings > General (i.e. /wordpress/wp-admin/options-general.php)
and remove “/wordpress” from the Site Address (URL)
Full Disclosure: I don’t use this technique
Typically, I do not install WordPress in a sub-directory. I use Local by Flywheel for running sites locally and use my WordPress .gitignore to keep the WordPress core files out of my repo. On the projects I work on where WordPress is installed in a sub-directory, we are using WP Starter.
john ploch… oki. who is he?
Google is your friend. https://github.com/johnpbloch
I get HTTP ERROR 500 on Step 6