Thursday, May 23, 2013

How i know, is apache mod_rewrite is enabled

To know about the apache mod_rewrite module is enabled, we can follow two technique. One is using phpinfo other apache_get_modules function.

Let we use phpinfo function first,
  1. Create a file on your localserver root directory and renamed it something like this "phpinfo.php".
  2. then, add this,

    <?php echo phpinfo(); ?>

    and save it.
  3. Then go to your browser and write address like: localhost/phpinfo

    there you see a pic like this




    Look at Loaded Modules and i viewed here only mod_rewrite. Because i already enabled it. If you do not see anything like this, it assume that you have not enable mod_rewrite module.

 The another technique is,
  1. Create a file on your localserver root directory and renamed it something like this "mod.php".
  2. Then add this code snippet,

    <?php
    print_r(apache_get_modules());
    ?>
  3. Then go to your browser and write address like: localhost/phpinfo

    there you see a array like this

    Array (
                        [0] => core
    [1] => mod_log_config
    [2] => mod_logio
    [3] => prefork
    [4] => http_core
    [5] => mod_so
    [6] => mod_alias
    [7] => mod_auth_basic
    [8] => mod_authn_file
    [9] => mod_authz_default
    [10] => mod_authz_groupfile
    [11] => mod_authz_host
    [12] => mod_authz_user
    [13] => mod_autoindex
    [14] => mod_cgi
    [15] => mod_deflate
    [16] => mod_dir
    [17] => mod_env
    [18] => mod_mime
    [19] => mod_negotiation
    [20] => mod_php5
    [21] => mod_reqtimeout
    [22] => mod_rewrite
    [23] => mod_setenvif
    [24] => mod_status
    )
  4. I highlighted the mod_rewrite module. Here it exists because of i have this module already enabled. If you have not this, you need to enable this module.
 

Enable Mod_rewrite on Ubuntu (Apache2)

If you have .htaccess file with some rewrite rule that you need for your desire app.
But the rewrite rule is not working. There will be one of the reason is your mod_rewrite apache module is not enable or loaded. So you need to enable it.

For example, if you use a cms like wordpress,  permalinks for wordpress or another CMS is not working for same reason.

Now I am going to enable mod_rewrite apache module by using a simple command which is bellow

sudo a2enmod rewrite


This will enable mod_rewrite for apache2 in ubuntu. But we need to update Default apache2 config to AllowOverrides from .htaccess files or any rewrite rules created various cms like wordpress, joomla, drupal etc

Open the Default file by following command :

sudo gedit /etc/apache2/sites-available/default
 
Then looking the text "AllowOverride None" and changed it with "AllowOverride All" and restart apache by following command:

sudo service apache2 restart 

Mod_rewrite will enable now on ubuntu systemm runing on apache.

 

Tuesday, May 21, 2013

How get PHP Apps error log in Linux OS

Many time, we need to see what actually happened when we run PHP based Web App, It is especially for when you need to debug some issue :)

So lets start by its using terminal, just paste this command and see the log :

sudo tail -f /var/log/apache2/error.log 

Configure virtual Host in linux OS Environment

By following the bellow instruction, we can make the local host as virtual host and can use as like as sub domain locally 


1. make available site config from copy the default one. Here is my site will be  naimrajb.com and i renamed it with "naimrajb.com"
  
   sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/naimrajb.com

2. Open the new created file for set configuration root and others : 
  
   sudo gedit /etc/apache2/sites-available/naimrajb.com
 
   here set the following config:

        ServerName naimrajb.com //which site name will be
        ServerAlias www.naimrajb.com //which site name will be alias

       DocumentRoot /var/www/NaimRajb_Project_Folder    //where you put the main  project directory
    <Directory /var/www/CrowdRock1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

3. Enable new created virtual site by following command

   sudo a2ensite naimrajb.com

4. Restart apache server

   sudo service apache2 restart


5. Open hosts file

   sudo gedit /etc/hosts

6. Then add your site in hosts file

   127.0.0.1    naimrajb.com

All is done :)

Now browse naimrajb.com