A place for everything and everything in its place!
There is no denying to this and for this very reason, we are devoting our first chapter in this series to conventions only.
It is important to assign a place for all characters (read softwares’) we will encounter in this series. It will make things easier for us as we move ahead!
This chapter might be a little boring. 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 knowledge will help you troubleshooting and quickly find things that you need to fix!
Single-line of code/command:
This is an example of a single line code/command
Multiple line of codes/commands:
This is an example of a multiline code-block and/or multiple commands
This is an example of
inline command and this is an example of
- I have tried to use absolute paths wherever needed. Rarely, you may find a relative path but then it will have a cd command before that or it will be part of multi-line code block.
- Directory: /path/to/directory/ will always end with slash “/”.
- File: /path/to/file won’t have slash “/” in the end.
If a path ends with slash “/” then its a directory.
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.
/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” [TODO- more info on how to enable/disable nginx]
/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
/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
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
/etc/mysql/my.cnf- this is mysql configuration file (not folder)
/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
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/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/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!
Few notes about the above website-structure:
- 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
- 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:
- 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.
- 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)
This is all for today. Tomorrow, we will jump to installation of nginx and other required software to run WordPress!
You can find the complete list of WordPress-Nginx tutorials here.