Moving wordpress out of the public directory

Is there a way to move wordpress out of the public html directory?

The PHP files responsible for generating html output should be hosted but the php files responsible for database connections and other logic should not be hosted. They can be included by the hosted files in the following way: ../../NotPublic/wp-admin/...

Read More

Symfony does this and actually has only one hosted php. For more explanation as to why this would be a good idea you can check out this video.

I’ve tried to find instructions on how to do this but cannot find it. Worpress seems to have trouble making a distinction of php files generating output that need to be in the public directory and those that do stuff and should not be able to be requested through the web server (only as includes).

Currently I can use .htaccess to not list the directories or host any of the wp-content directories except wp-content/uploads

Related posts

2 comments

  1. WordPress is very clearly engineered for being placed into web-accessible folder.

    While attempt to move it from web folder could be made, it would be very challenging, especially for admin area which uses direct non-routed URLs to PHP files.

  2. It is possible. I always move my default wordpress installation to a folder. this is totally different with installing wordpress in a folder. moving default wordpress installation make your site more secure.
    what you have to do is here:

    1. go to cpanel > login > file manager > in /public_html or root, create a folder, eg.: “site”. it assumes, you now have folder /public_html/site
    2. login to your wordpress dashboard > settings > general
    3. change “WordPress Address (URL)” to: http://your-domain-or-whatever.com/site
    4. click “save changes” button. page will displayed error? no problem.
    5. in cpanel file manager, move your wordpress files, to /public_html/site
      *) what you don’t need to move is only : .htaccess, robots.txt, php.ini, and “index.php”. remember, do not move “index.php”.
    6. open and edit “index.php” with code editor.
      in the last line, you see this code

      require( dirname( __FILE__ ) . '/wp-blog-header.php' );
      

    change it to :

     @require( dirname( __FILE__ ) . '/site/wp-blog-header.php' );
    

    remember: “site” can be changed to any folder name you defined in step number 1.

Comments are closed.