Conventions & File System Layout

Important: You can use easyengine which automated WordPress-Nginx site management.

There is a famous proverb that goes like this:

A place for everything and everything in its place!

There is no denying to this. So we are devoting a dedicated page for all conventions we have used in wordpress-nginx tutorials series.

This page might feel a little boring to read. But it will help you get a grip on all the conventions used. You will definitely thank me for this when you will end-up breaking something. Because in that panic moment, this page will help you troubleshoot quickly.

File-System Layout

Please note that following layout is for Ubuntu 12.04 LTS. Most of them are default locations for respective packages. Sticking with default will save us from some trouble. On non-Ubuntu/Debian OS, some locations may vary.

Nginx

Configuration Files:

  • /etc/nginx/ – all nginx related configuration will be in this folder
  • /etc/nginx/nginx.conf – THE (main) nginx configuration file
  • /etc/nginx/sites-available/ – nginx configuration for different sites will be available here
  • /etc/nginx/sites-enables/ – symlinks to nginx configuration files which are “active”

Log Files:

  • /var/log/nginx/ – default log directory for nginx. We will use this for logs of all sites we will create.
  • /var/log/nginx/example.com.access.log – access log file for example.com
  • /var/log/nginx/example.com.error.log – error log file for example.com
  • /etc/logrotate.d/nginx – this file control log-rotation policy for nginx related log files

PHP

Configuration Files:

  • /etc/php5/ – all php related configuration will be in this folder
  • /etc/php5/fpm/php.ini – THE (main) php configuration file
  • /etc/php5/fpm/php-fpm.conf – FPM related settings
  • /etc/php5/fpm/conf.d/www.conf – “www” i.e. default pool related settings

Log Files:

Note: You may not find following files by default. They were added in by us.

  • /var/log/php5-fpm/ – php related to logs. you should check this if you feel your site is slow or broken
  • /var/log/php5-fpm/slow.log – this file will help you find slow php scripts
  • /var/log/php5-fpm/php.log – this file will help you find slow php scripts
  • /etc/logrotate.d/php5-fpm – this file control how long php logs will be maintained

MySQL – Configuration & logs

Configuration Files:

  • /etc/mysql/my.cnf – this is mysql configuration file (not folder)

Log Files:

  • /var/log/mysql/mysql.log – mysql general/error logs
  • /var/log/mysql/mysql-slow.log – this file will help you find slow mysql queries
  • /etc/logrotate.d/mysql-server – this file control how long php logs will be maintained

Website Structure

Following is the convention we will be using for WordPress as well as non-WordPress sites.

  • /var/www – all your websites will be here
  • /var/www/example.com – everything related to example.com will be inside this folder
  • /var/www/example.com/htdocs – this is web-root for example.com. Its like DocumentRoot in Aapche. You will put WordPress will here.
  • /var/www/example.com/logs – contains logs for example.com only.
  • /var/www/example.com/logs/access.log – contains access.logs for example.com only. If you want to use a tool like AWStat then this is the server-log file you will need. This is a symbolic link to /var/log/nginx/example.com.access.log file.
  • /var/www/example.com/logs/error.log – contains error.logs for example.com only. This will help you in debugging. It captures some PHP related error as well. This is a symbolic link to /var/log/nginx/example.com.error.log file.
  • /var/www/example.com/wp-content – in case you want to keep wp-content outside web-accessible folder. I will NOT cover this in this tutorial. Consider this is an exercise for yourself! 😉

Notes:

Few notes about the above website-structure:

  1. Following structure does not take into account shared-hosting scenarios where generally all sites for a users are located under his home directory. Something like /home/bill/www or /home/bill/public_html
  2. Subdomains are treated like domains. They reside directly under /var/www with their own htdocs and logs folder. e.g. subdomain.example.com will use directory /var/www/subdomain.example.com

Notes about access.log & error.log files for websites:

You might have noticed that you can check access.log & error.log for a domain by 2 ways – either from logs folder under domain or nginx’s log folder. There are few reasons for this kind of setup:

  1. Keeping all log files places under /var/log/nginx location make things like logrotation, disk cleanup very easy. Also, things like checking logs for all sites hosted on your nginx server or for all subdomains for a top-level domain will be easy.
  2. Site-specific log folder can make debugging easy. Also, from security perspective you may want to create a user and give him access to a specific site only. In that case we can access logs for that site (if needed)

Related: You can find the complete list of WordPress-Nginx tutorials here.

Important: You can use easyengine which automates WordPress-Nginx site management.

13 responses to “Conventions & File System Layout”

  1. Good aftenoon Sir.,

    I have problem using nginx.,
    I want to migrate from apache to nginx, but I don’t know configuration nginx for wordpress., then in my wordpress, I have “htaccess”.

    When I convert htaccess wordpress to using nginx, and when I access my website, display a message “500 Internal Server Error” ..,

    Please help me sir.

    • what you are missing and Rahul did not explain (this guy is busy) is you do not need to convert htaccess, you can use easyengine as it is for most of the configurations that you had in your htacess file, and if anything is missing (mostly wont by any) the community and Mr.google can help you fix it in few minutes (not more than 2 hours for sure).

  2. I have mysql already installed and the default position of the my.cnf file is /etc/my.cnf

    Mysql looks here first before looking in /etc/mysql/.

    How can I tell ee to look at /etc/my.cnf instead of /etc/mysql/my.cnf?

    Thank you in advance

  3. no such file on directory cant find nginx at etc and cant find directory my site on var. where is it? thanks