• 4
name Punditsdkoslkdosdkoskdo

How do I find out where the websites code reside?

The facts:

  • there is a website
  • this website is accessible via
  • there is an EC2 instance which very likely keeps the website
  • the server is Apache
  • the server OS is Ubuntu
  • I have full access to the server (and sudo privileges)
  • the server is a huge mess

The problem is I have no idea where to - simply put - find the index.html/index.php which gets loaded.

How do I figure out where to find the website's PHP and HTML code? Is there a systematic approach to this problem?

Please go to

cd /etc/apache2/site-avaliable/

Here you will find your configuration file (i.e : 000-default.conf)

Please open this file/open your configuration file using

vi 000-default.conf

There you will find DocumentRoot.That is your website's code

This is the Default conf file likewise you will some conf details please check those as well.

  • 1
Reply Report

Another method, which can be useful for debugging a website (or any process for that matter) is to use lsof (which may not be on path, commonly found in /sbin/lsof)

lsof -s [PID] will list all the files the given process has a handle on, and can be useful to see exactly what is being used (this includes your html/php files, as well as log files and libraries the site needs)

  • 1
Reply Report

First of all you should check what websites are hosted on the server

# apachectl -t -D DUMP_VHOSTS

Then when you will find a site check corresponding configuration file for the option DocumentRoot. For example

# apachectl -t -D DUMP_VHOSTS
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server (/etc/httpd/conf.d/
         port 80 namevhost (/etc/httpd/conf.d/
         port 80 namevhost (/etc/httpd/conf.d/hooks.conf:1)

You want to know where is resides a website

# grep DocumentRoot /etc/httpd/conf.d/hooks.conf
    DocumentRoot /vhosts/

# cd /vhosts/
# ls -la
total 4484
drwxr-xr-x  6 apache apache    4096 Feb 10 11:59 .
drwxr-xr-x 14 root   root      4096 Feb 23 08:54 ..
-rw-r--r--  1 root   root      1078 Dec 19 09:31 favicon.ico
-rw-r--r--  1 apache apache     195 Dec 25 14:51 .htaccess
-rw-r--r--  1 apache apache      98 Dec  7 10:52 index.html

Should also be on the lookout for aliases and redirects/rewrites

You also should paid attention on any alias directives. For example with the following settings

<VirtualHost *:80>
   DocumentRoot /vhosts/default/public_html/
   Alias /api/ /vhosts/default/public_api/

When you will access - apache will look the file at /vhosts/default/public_html/, at the same time with the file will be looked at /vhosts/default/public_api/.

What about rewrites/redirects, especially programmatic (when redirects are triggered by some php code), I think there is no easy way to find such cases.

  • 1
Reply Report