How To Enable mod_rewrite In Ubuntu

The mod_rewrite is Apache’s very powerful URL manipulation module. It may seem somewhat complex to beginners. This module comes the default with Apache setup. By default its disabled. Let see how to enable mod_rewrite in Ubuntu.

Apache has very simple but very useful command a2enmod to enable Apache modules. You can run this command using terminal from any directory. We are going to use this command to enable mod_rewrite module as well. Enter following in terminal:

$ sudo a2enmod rewrite 
$ sudo service apache2 restart

Now open default site configuration:

$ sudo gedit /etc/apache2/sites-available/000-default.conf

000-default.conf file may have contained following content:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

We need to add <Directory> directives, allow to override URL manipulation done using .htaccess. Your file finally will look like follow:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html 
    #OR DocumentRoot /var/www depending on your setup

    <Directory />
        Options FollowSymLinks
        AllowOverride All

    <Directory /var/www/html/> 
    #OR <Directory /var/www/> depending on your setup
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

If <Directory> directives are already there you just need to change AllowOverride from none to All.

Now restart Apache service using this command:

$ sudo service apache2 restart

Yes! That’s it…. Pretty simple huhh? Wanna test your changes? Lets do it…

Create one php file phpinfo.php in your server root (mostly /var/www/html/ or /var/www/) with following inside it.

<?php phpinfo(); ?>

Now create .htaccess file at your server root with following rewrite rule inside.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /phpinfo.php [L]

Above rules will map any non-existing file or directory URLs to phpinfo.php file. Suppose you have example directory inside your server root and you are trying to visit URL http://localhost/example, it will work. If you have a file example2.php on your server root and if you visit URL http://localhost/example2.php, it will work too. But if you visit any URL for those directories or files not present on your server it will open phpinfo.php file instead. Lets check by visiting URL http://localhost/yourname or http://localhost/yourname.php.

How To Create Virtual Host In Ubuntu

It is a very common scenario for web-developers to host more than one website on single machine for development purpose or for deployment purpose. The term virtual host is very common in such situations.

Those virtual hosts are “IP-based”, or “name based”. IP-based virtual host means to have multiple IP addresses for your multiple sites, where one or more IP address may associated with one website. Where as name-based virtual host means to have multiple names associated with each IP address. The beauty of virtual host is that, the fact that they are running on the same physical server is not apparent to the end-user.

Most web-developers are working with very known and widely used Apache web-server. Apache was one of the first servers to support IP-based virtual hosts.

The same way Ubuntu is the choice of development platform for most developers. In Ubuntu with Apache running, it is very easy to create virtual hosts.

In my experience, I have found virtual host very handy when you are dealing with the sites developed using WordPress, Joomla! and even using some frameworks with lots of URL dependency, whether on site root or on some third-party services. It helps to deploy your websites locally in your regular work space but with a proper identification (virtual domain/IP) just like you have with your live site.

Let see, how to create virtual host for in Ubuntu for Apache server.

$ sudo nano /etc/hosts

Edit the host file and add following line just at the end of IPV4 entries.

Save changes and exit the file.

$ cd /etc/apache2/sites-enabled
$ sudo nano

Last command will create a temp file on path at we are.

<VirtualHost *:80>
    DocumentRoot  (/var/www/example) # root directory of your project.

Save file and exit. Restart Apache to apply changes.

$ sudo /etc/init.d/apache2 restart 

POODLE Caused PayPal To Discontinue Support For SSL 3.0

As of December 3, 2014 at 12:01 a.m. Pacific Standard Time (PST), PayPal has discontinued support to the Secure Socket Layer version 3 (SSL v3.0) to help keep customers’ accounts secure from the POODLE vulnerability. However PayPal has figured out a short-term solution, that will allow PayPal to extend the SSL v3.0 support to most merchants and that too until January 12, 2015 at 12.01 a.m. PST.

PayPal is well aware of the compatibility issues going to arise with the shutting off SSL 3.0 and is still identifying possible issues that may arise due this decision.

Will this affect to you?

If you are an independent developer or online service provider or whatever you are doing from the furthest corner of the world. If you have integrated PayPal as your online payment solution or providing PayPal integration as a service, you should pay attention.

Consider 3 simple steps from PayPal Merchant Response Guide

1. Test your current integration against the PayPal Sandbox
Simplest way to identify if you are using SSL v3.0 is to check your current integration with PayPal Sandbox. SSL 3.0 has already been disabled on the PayPal Sandbox, so if you can successfully make an application programming interface (API) request you are not using SSL 3.0. If your request fails, check your logs, if you see an error similar to those shown below, then you are using SSL v3.0 and will need to configure your secure connection to use Transport Layer Security (TLS).

Unknown SSL protocol error in connection to 9824


140062736746144:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:337:
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
Protocol: SSLv3

2. Update to TLS
All PayPal integration which use SSL v3.0 for client interaction required to disable SSL v3.0 and upgrade to TLS. You will find detailed upgrade instruction for SDK and language here.

As per details from PayPal, No current Software Development Kit (SDK) versions use SSL 3.0. However, since the Java and PHP SDKs were recently updated to address this issue, all merchants using these SDKs or legacy SDKs (older than October 21, 2014) will need to update to the latest version.

3. Issue new credentials
As per PayPal this step is strongly recommended, but not required.

If you are using Certificate authentication, no action is required because the vulnerability is in the SSL v3.0 protocol and not in the design of the SSL Certificates

If you are using Signature authentication, see here.

If you are using OAuth authentication, see here.

For more details please visit PayPal MTS

Further reading:

How To Create WordPress Child Theme

WordPress child theme is an elegant way to customise WordPress theme without loosing original theme’s core code. Child theme inherits functionality and style of parent theme. It allows us to modify or add functionality of the parent theme.

Why should I use child theme?

Theme developers and distributors frequently releases new versions of the theme to add more functionality over previous version, or to provide bug fixes and security updates. The main advantage of using child theme is to keep your customisation safe, while you update a parent theme. This will allow you to update your theme to available latest version, without loosing your changes. By creating a child theme you are actually creating a separate set of files, that you will use to customise your theme without affecting your original theme. Practically you are going to create only those files which you wants to customise. You can always turn off your child theme to fallback to original theme.

Getting Started

In this example I will create child theme for default WordPress “Twenty Fourteen” theme. To create a child theme we will need minimum two things. A directory which contains files for child theme and another is style.css file within this directory.

There is no restriction to name theme directory, except one; you can not use white space as a part of directory name. You can name it whatever you like to call it. If you want to dedicate this child theme to one of your best friend, or your pet name; you can. The common practice among developer is to use parent theme name with “-child” appended to it. In our example child theme directory name would be “twentyfourteen-child”.

In the child theme directory create a file called style.css. Specific set of comment line added to the starting of this file detects your theme. Child theme must start with following lines of comments. The only required lines are the “Theme Name” and “Template”.


Theme Name:     Twenty Fourteen Child 
Template:       twentyfourteen 
Theme URI: 
Description:    This is a child theme of Twenty Fourteen 
Author:         Saurin Dashadia 
Author URI: 
Version:        1.0.0

@import url("../twentyfourteen/style.css"); 

/* ----------Theme customization starts here----------------- */

Theme name is to give your child theme a name. While Template is directory name of your parent theme. Here it is ‘twentyfourteen’. This will be use to identify your parent theme.

The @import section will import parent theme’s css. Make sure your path to the parent theme. Everything here is case-sensitive. make sure your Template parameter and import path reflects the same name as your parent theme has.

Activating child theme.

Now if you have set up everything correctly, your child theme should be listed on themes page(Appearance->Themes). Activate your child theme by clicking on Activate button on child theme.

Now by activating your child theme, you site will use your child theme as am active theme, theme needs many predefined formats as well as many files to run. Like to display your post, your child theme should contain single.php file. Our newly created child theme don’t have such file yet. Still when you will visit your page or post it will going to display the same way as it was before with parent(original) theme, before you activated child theme. This is because child theme will retrieve any missing files from its parent theme. So actually you don’t have to worry about any functionality or styling. You will actually need only those files to be there in child theme, you want to customise.

Modify theme look.

As I said, we only imported parent theme’s style to child theme. So for now there is no change to your site’s look. Lets modify child theme’s style.css to change your site’s look. You can add any changes to your child theme’s style.css file below @import line. All your custom css will load after parent theme css loaded. This way your style will overwrite original style. Let say if we want to make all header tags to be in red colour we should add our style like this;


Theme Name:     Twenty Fourteen Child 
Template:       twentyfourteen 
Theme URI: 
Description:    This is a child theme of Twenty Fourteen 
Author:         Saurin Dashadia 
Author URI: 
Version:        1.0.0

@import url("../twentyfourteen/style.css"); 

/* --------------Theme customization starts here--------------- */ 

h1, h2, h3, h3, h4, h5, h6 { color: red; }

Modify theme functionality.

functions.php is the file where theme’s main functionality is stored. Unlike style.css, we do not need to load parent theme’s functions.php file explicitly. It will load automatically with child theme. If we need to customise functionality we need to create functions.php file within our child theme folder. Child theme’s functions.php file will load just before parent themes functions.php file. We can write our code to this file between PHP tag.

//Your custom code goes here

Note: Child theme style.css file should load after parent theme style. While child theme functions.php will load before parent theme’s functions file. Child theme and parent theme’s functions.php file will load in same scope, so make sure you do not create duplicate function names.

Modify other template files.

Just like style.css and functions.php files we can override all related template files. only thing is we need to maintain same template structure it is with parent theme. For an example if we want to customize template file from “twentyfourteen/inc/widgets.php”, we should have to maintain same file structure at child theme like “twentyfourteen-child/inc/widgets.php”. The same way we can also override plugin’s template files. Usually you can find plugin template override information at their official documentation.

If you find this post helpful do share or comment here.

Copy link
Powered by Social Snap