Caching is one of the most important things to keep in mind when you are developing a website which is expected to get large amount of visitors. Most web developers neglect caching, some even don’t know correct ways to implement it.
In this tutorial, I’ll show you how to enable browser cache of static files simply using htaccess file. Basically server adds the Expires header to file-type you specify. Expires header will make sure the browser stores the file locally and use the same file until the time mentioned in expires header has passed.
Copy the following code and paste it into .htaccess file in your website’s root directory.
# Turn on the Expires engineExpiresActiveOn# Expires after a month client accesses the fileExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
# Good for one weekExpiresByType application/x-javascript M604800
ExpiresByType text/css M604800
ExpiresByType text/html M604800
Explanation:
ExpiresActive On turns on the expires engine. ExpiresByType image/jpeg tells server to check if MIME-type of file is image/jpeg. If yes, set the expires header. Read the rest of this entry »
You can enable or disable any apache module using a2enmod and a2dismod. You don’t need to edit the conf file for that unless you are having some problem with this method. The syntax of these commands is really simple: To enable a module:
We can check the php configuration, apache’s loaded modules and all other kinds of PHP configuration using a simple function called phpinfo(). Create a file called infophp.php in your web’s root directory and put the following code in it:
<?phpinfo();?>
This would output all the php configuration info and apache information. You can pass on an argument to phpinfo() to limit what information is displayed. You can checkout the phpinfo documentation here.
PS: This is a beginner tutorial for absolute beginners.
There’ve been lots of times when I wanted to use the mail() function on my local server. I am sure lots of you would’ve been wanting it too but most of you would’ve settled for PHPMailer or just used a web host to test the code instead. I myself had been doing the same until recently when I finally decided to do some research and get it to work.
Here are the steps in short for the geeks who like to do things on their own: All I did was used smtp client called msmtp, configured it to work with my gmail account and configured PHP to use msmtp to send emails.
This tutorial is only applicable for linux users. I’ll write another article for windows users soon when I get my hands on a windows box. All the commands used in the instructions are for Ubuntu, however you may use corresponding commands for your distro (for eg; you can use yum install instead of apt-get install on fedora, redhat, centos.
Msmtp is a small but powerful and highly customizable smtp client. You can access gmail smtp using msmtp, which is exactly what I’ll teach in this tutorial.
Step by step instructions:
Install msmtp and ca-certificates for use with SSL:
I came across this simple script on ubuntuforums which I thought was really very useful and worth sharing it on my blog. You can either make a function out of it and put it in .bashrc file or make an executable script and put it in /usr/bin/.
Method 1:
Open your ~/.bashrc file using any editor.
gedit ~/.bashrc
Copy and paste the following code at the end of it:
extract-file (){if[-f $1] ; thencase $1in*.tar.bz2)tar xjvf $1;;*.tar.gz)tar xzvf $1;;*.bz2)bunzip2 $1;;*.rar) rar x $1;;*.gz)gunzip $1;;*.tar)tar xf $1;;*.tbz2)tar xjvf $1;;*.tgz)tar xzvf $1;;*.zip)unzip $1;;*.Z) uncompress $1;;*.7z) 7z x $1;;*)echo"'$1' cannot be extracted via extract-file";;esacelseecho"'$1' is not a valid file"fi}
Now you can use the following command to extract any archive:
extract-file
The command extract-file would be available only to terminals which have been opened after saving the .bashrc file with the above code. Also this code is user-specific, so if another user logs in he cannot use this command.
Method 2:
Use the following command to create a new file in /usr/bin directory and launch the gedit.
Recently I got this error after installing VLC on Ubuntu 10.10 Maverick Meerkat. Not really remembering what caused the error to be triggered in the first place, it became very difficult to find a solution for it. When I executed sudo apt-get upgrade to upgrade my packages, it told me there was some issues and I needed to execute sudo apt-get -f install to fix them. I did as advised but it produced the following error:
Reading package lists… Done Building dependency tree Reading state information… Done Correcting dependencies… Done The following extra packages will be installed: vlc vlc-nox Suggested packages: mozilla-plugin-vlc videolan-doc The following packages will be upgraded: vlc vlc-nox 2 upgraded, 0 newly installed, 0 to remove and 198 not upgraded. 66 not fully installed or removed. Need to get 0B/5,258kB of archives. After this operation, 229kB of additional disk space will be used. Do you want to continue [Y/n]? y WARNING: The following packages cannot be authenticated! vlc vlc-nox Install these packages without verification [y/N]? y (Reading database … 206759 files and directories currently installed.) Preparing to replace vlc 1.1.0-1~ppa1~maverick (using …/vlc_1.1.0-1ubuntu1_i386.deb) … Unpacking replacement vlc … dpkg: error processing /var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb (–unpack): trying to overwrite ‘/usr/lib/vlc/plugins/access/libxcb_screen_plugin.so’, which is also in package vlc-nox 1.1.0-1~ppa1~maverick dpkg-deb: subprocess paste killed by signal (Broken pipe) Preparing to replace vlc-nox 1.1.0-1~ppa1~maverick (using …/vlc-nox_1.1.0-1ubuntu1_i386.deb) … Unpacking replacement vlc-nox … dpkg: error processing /var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb (–unpack): trying to overwrite ‘/usr/lib/vlc/lua/playlist/anevia_streams.luac’, which is also in package vlc 1.1.0-1~ppa1~maverick dpkg-deb: subprocess paste killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb /var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
After some time of googling and head-scratching, I finally found a solution and it wasn’t that difficult either. To fix it just note down the path of files which are causing the trouble. From the above mentioned error, we can clearly see that there are these two files causing the error: Read the rest of this entry »
To backup all or some of your MySQL databases, you’ll need mysqldump which comes bundled with mysql. If you have MySQL installed, you probably have mysqldump installed already.
To backup all databases use the following command:
I had been wondering this for few days. I wanted a solution which could comvert first letter of text in some fields to uppercase and the rest to lower. I got time today and experimented a bit and found a very simple solution. Read the rest of this entry »
I’ve seen numerous pages on facebook about changing facebook themes. Unfortunately, no user can change his/her profile theme because this data has to be stored on server. It can only happen if facebook starts supporting themes which I don’t see is a possibility anytime in near future.
Before following this tutorial, keep 1 things in mind:
This change will only be seen by you only on your computer and only on Mozilla Firefox.
This means that its only for people who would like to feel good seeing their own themes. It would not affect the look of your profile on others’ computer ie. other people would not be able to see your theme and instead see the default facebook theme.