To chmod or not to chmod

When installing scripts on a server, there is a tendency of both developers (in their instructions) and users to be overly generous in dishing out file permissions. In Linux, file permissions can be manipulated with the “chmod” command.
For example, a script may require write access to a temporary directory, and the instructions may call for you to chmod the directory 777. What this means is that anyone can read, write, and execute commands to the directory, including complete strangers. While such permissions might be necessary for a public repository, they are not for most web-based scenarios.
If the server or a particular authenticated user needs write access for a directory, chmod it 664. This means that the owner and the user group will be able to write to that directory, but others will only be able to read its contents. If you ever need something to be completely locked down and not readable by the outside world, make the last digit a “0″. Stay tuned to this blog for more chmodding tips in the future.
Photo Source: Flickr
Tag: chmod, directory, linux, permissions, scripts, server, users
Forcing a browser to prompt to save certain files

Question: I am distributing sensitive forms to my clients and want to make sure they download them rather than opening them in their browser. Is there a way to force the web server to prompt them for download rather than using a browser plugin?
Answer: Yes, using .htaccess you can force most browsers open a “save as” prompt rather than opening a particular file type with a browser plugin. Add the following to an .htaccess file inside the directory with the files:
AddType application/octet-stream .pdf
AddType application/octet-stream .doc
AddType application/octet-stream .txt
Nevertheless, nothing is fool proof. If you want to make sure your clients will save the documents, there is no substitute for good education. Make sure they know how to do and that you mark that clearly on the download page. If you want to be particularly diligent, you can even add a popup window to remind them again before they click the link.
Photo Source: Flickr
Apache's DocumentRoot directive

Apache HTTP Server gives you the flexibility to decide where you want to store the web-accessible files for your websites. Most operating systems have their own unique directory structure for their default web server installations, but even those can be changed. The Apache default document root is /usr/local/apache/htdocs.
To change the document root, use the following directive in your httpd.conf or virtual host configuration file:
DocumentRoot directory-path
Replace “directory-path” with the path you want to use. For example:
DocumentRoot /var/www/public_html
Make sure you do not have a trailing slash. With this setup, a file, such as index.html, found in /var/www/public_html/index.html will appear on the web at: http://www.yourdomain.com/index.html. Whatever directory you choose must be readable (but not writable) by outside users.
Source: Apache.org
Tag: apache, directive, directory, document root, web server
What are symbolic links in Linux?

Question: What are symbolic links in Linux?
Answer: Linux has a convenient feature that allows you to link a virtual file to a real one. For example, if you have a directory called “images” and you also want one called “photos” to point to the same place, you need to make a symbolic link.
To create a symbolic link, first login to your server via SSH. For this example, let’s assume your real file is called “testdummy” in /home/public_html, and you want a file called “crash” in /home/public_html/dummies to link to it. Follow these simple steps:
1. $ cd /home/public_html/dummies
2. $ ln -s /home/public_html/testdummy crash
3. $ ls -al (this will show you whether you correctly link the file.
It should show crash -> ../testdummy)
That is all it takes to make symbolic links. Use the same process to link a directory.
Photo Source: Flickr
Tag: dedicated server, directory, file, linux, symbolic links