Home Blog WordPress Management Finding the absolute path of a directory on a website (using PHP)

Finding the absolute path of a directory on a website (using PHP)

A WordPress website is made up from a number of files, organized in a number of sub directories. These files and sub directories are saved in a directory on a web server. This is the root directory of your site, also known as the document root.

Sometimes you need to find out absolute path of a directory on your WordPress site. The absolute path is the path of where a particular file or directory is saved on the web server. For example, if you are using .htaccess file restrict access to the WordPress dashboard, you need to specify the absolute path of the .htpasswd file (Apache password file) in the .htaccess file, otherwise the authentication files cannot be found.

This short article explains how you can find the absolute path of a website directory.

PHP script to find absolute path

Here is a simple one line PHP script you can use to find the absolute path of the directory on your web server.

<?php echo getcwd(); ?>

How to find the absolute path of a directory on your website

  1. Save the above PHP script to a file, for example path.php,
  2. Upload the file path.php to the directory of which you want to know the path,
  3. Launch a web browser and navigating to the script e.g. http://www.example.com/directory/path.php

6 thoughts on “Finding the absolute path of a directory on a website (using PHP)

  1. Whats suppose to happen when I navigate to script?
    All I’m getting is a blank screen with no sign of a root file path.

    Please help!

    1. Hi Nate,

      You should simply get the path where the script is uploaded. E.g. in my test installation of Xampp on windows it simply shows the following: C:xampphtdocsxampp

      Please note that if you use the function “copy to clipboard” from this blog post, in notepad it will be shown as one line, which is not the correct format. I recommend using the “view source” option and then paste it on the text editor.


Leave a Reply

Your email address will not be published. Required fields are marked *

Stay in the loop

Subscribe to the Melapress newsletter and receive curated WordPress management and security tips and content.

Newsletter icon

It’s free and you can unsubscribe whenever you want. Check our blog for a taste.

Envelope icon
newsletter-pop-up