Skip to content

Instantly share code, notes, and snippets.

@tamagokun
Last active March 12, 2020 11:15
Show Gist options
  • Select an option

  • Save tamagokun/3801087 to your computer and use it in GitHub Desktop.

Select an option

Save tamagokun/3801087 to your computer and use it in GitHub Desktop.
Run a Wordpress site via PHP's built-in web server
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir($root);
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
set_include_path(get_include_path().':'.__DIR__);
if(file_exists($root.$path))
{
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
$path = rtrim($path,'/').'/index.php';
if(strpos($path,'.php') === false) return false;
else {
chdir(dirname($root.$path));
require_once $root.$path;
}
}else include_once 'index.php';
@pyrmont

pyrmont commented Feb 19, 2013

Copy link
Copy Markdown

I think this is missing a ?> at the end of the file.

@jfrux

jfrux commented Jun 24, 2013

Copy link
Copy Markdown

How to get wp-admin to show up?
It's not loading for me... just loads the homepage instead...

@lpirola

lpirola commented Sep 30, 2014

Copy link
Copy Markdown

Work like a charm, tks!

@kasunben

Copy link
Copy Markdown

Is any simple way to remove the index.php part of the URL. (without using .htaccess)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment