Updates from December, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • Shafiul Azam 10:07 pm on December 11, 2011 Permalink | Reply  

    Translate Digits/numbers in Drupal 6.x 

    Hi, first of all, it’s an old tutorial, I don’t use Drupal 6.x any more. Anyway, below goes the procedures.

    WARNING: This is done hacking core Drupal files, so be careful when you update Drupal core. All changes might be lost.

    Edit file ‘DRUPAL_INSTALL_DIR/includes/common.inc

    Add following code snippet at the end of t($string, $args = array(), $langcode = NULL) function:

    if($langcode == 'bn'){
    return bengaliDigit(strtr($string, $args));
     }else{
    return strtr($string, $args);
     }

    And define following function somewhere in the page:

    function bengaliDigit($numb){
    // Credits: Hasan Raihan
    $latin = array('1','2','3','4','5','6','7','8','9','0');
    $bengali = array('১','২','৩','৪','৫','৬','৭','৮','৯','০',);
    return str_replace($latin, $bengali, $numb);
     }

    Here, I’m assuming I’m translating English (en) digits to Bengali (bn) Digits.

     
  • Shafiul Azam 9:55 am on November 26, 2011 Permalink | Reply
    Tags: , drupal module update, ftp ubuntu   

    Update Drupal Modules using FTP in localhost 

    When you’re going to update Drupal 7 modules using FTP, you need to have a FTP server running in your computer. In Ubuntu/Linux, we can have one named vsftpd (Very secured FTP Daemon) by running following command in the terminal:

    Configuration:

    Drupal: 7.0+

    OS: Ubuntu/Linux

    Step 1: Install VSFTPD

    sudo apt-get install vsftpd

    Step 2: Have an FTP account

    Next, we need to add your Ubuntu user account to the FTP group. You can do it either by:

    Open Users & Groups > Manage Groups. Double-click on FTP. Put tick-mark on your user-account, and click OK.

    In the screenshot above, I’ve added my user account “giga” to the FTP group. So, I can use my username “giga” and my account’s password to run FTP.

    3. Configure VSFTPD

    Run in terminal:

    gksudo gedit /etc/vsftpd.conf

    Make sure you have following lines in the configuration file. Also check that they’re not preceeded by a “#”:

    listen=YES
    local_enable=YES
    write_enable=YES
    local_umask=022

    Save and close the editor. Now we restart vsftpd by the following command:

    sudo /etc/init.d/vsftpd restart

    Step 4: Own your Drupal site

    Run following command to own all of your Drupal scripts.

    chown -R your-username /path-to-drupal

    Finally…

    Yes, we’re done. :) Use your username (“giga” in this example) and system password to connect to FTP while upgrading modules.

     

     

     
    • Shafiul Azam 11:26 am on January 10, 2012 Permalink | Reply

      Add user “giga” to “ftp” group using terminal:

      sudo usermod -a -G ftp giga

      Reference: http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/

    • Jim Snyder-Grant 3:58 am on January 31, 2012 Permalink | Reply

      The ‘chown’ command will typically need a ‘sudo’ before it.

    • Ryan 3:24 am on March 14, 2012 Permalink | Reply

      I had to chown www-data:www-data /drupal for this to work – this also enabled module installs from the user interface

    • Alaa 3:52 am on March 23, 2012 Permalink | Reply

      Thanks a lot ..

  • Shafiul Azam 8:43 pm on November 25, 2011 Permalink | Reply
    Tags: , drupal multisite, multi sites   

    Running many sites on single Drupal installation 

    Yup, you may call it “multisite installation”. That means, you may run more than one site with only a single Drupal core.

    Configurations:

    Drupal 7.0+

    Linux Machine

    Step 1: Create a new virtual host

    To run multiple sites, we need to create Virtual Hosts in our machine. For example, If I type http://mydrupal I’ll be taken to my drupal site. For that, first we need to change ‘/etc/hosts’ file. Run following command in terminal and provide root password when promted:

    gksudo gedit /etc/hosts

    Next, add following line to the file and save the file:

    127.0.0.4    mydrupal

    Step 2: Restart networking interface

    Type in terminal:

    sudo /etc/init.d/networking restart

    Step 3: Configure Apache2

    For the easiest way, go the directory /etc/apache2/sites-enabled. Here, you will see a file named something like 000-default (or whatever), open it for editing. Place following code for opening it for editing:

    gksudo gedit /etc/apache2/sites-enabled/000-default

    Now, you need to create a <VirtualHost> directive:

    <VirtualHost 127.0.0.4:80>
        ServerAdmin [your@email.com]
    
        DocumentRoot /path-to-your-drupal/
    
        ServerName mydrupal
    
        <Directory />
            Options FollowSymLinks
            AllowOverride All
        </Directory>
        <Directory /path-to-your-drupal/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    
        RewriteEngine On
        RewriteOptions inherit
    
    </VirtualHost>

    Note that <VirtualHost 127.0.0.4:80> should contain the IP address you provided in step 1, we chose “127.0.0.4″ since it will be pointing to your own machine. Also, note the line ServerName mydrupal – here “mydrupal” is the name we chose in step 1.

    Step 4: Restart Apache2

    Type in terminal:

    sudo /etc/init.d/apache2 restart

    Yup, that’s all!

    Finally…

    Type http://mydrupal in your browser, you will see the new drupal site running! Now you can create all the necessary files (database settings, modules, themes etc.) under sites folder of your Drupal path. Copy the path-to-drupal/sites/default folder and rename it to path-to-drupal/sites/mydrupal.

    Next, you can (should):

    • Edit “path-to-drupal/sites/mydrupal/settings.php” – for database settings. Change database username, password, database name etc.
    • Create a new database if necessary, using PHPMyAdmin, or whatever.
     
  • Shafiul Azam 10:29 am on November 4, 2011 Permalink | Reply
    Tags: drupal 7   

    Using a View to diplay a single node/content in Drupal 7 

    Using the View module you can display nodes of any content-types.  Usually, in a “Page” type view you can display many contents/nodes, with pagination support. But what to display only a specific node? perhaps, using an url like http://yoursite.com/viewname/10 where 10 is the Node-ID (nid)

    You can achieve this using Contextual Filters. In this example, I’m assuming you want to display a single node of ‘Article’ content type.

    1. First, create the View generally, simply in the way you’d create a view for displaying paged Articles. Next, like the image below, Click on Advanced > (Contextual Filters) add.

     

    2. In the new window, type “nid” in Search text-field, select Nid as shown in the image below:

    3. Look at the image below carefully, and apply all the changes marked.

    4. Click on Apply. Contextual filter window will close.

    5. Finally, on the main view page, click on Use Pager: Full under PAGER section (see image below).

    6. On the new window, select “Display a specified number of items” and click Apply.

    7. Type 1 in the “Items per page” text-field. Click Apply. The dialogue window will close.

    That’s all. Hit Save on the main page.

     
    • Mohd Shareef 5:34 pm on November 16, 2011 Permalink | Reply

      Dear Azam bro, nice code. Can u send me php code for country state n city drop down list

  • Shafiul Azam 9:24 am on May 21, 2011 Permalink | Reply
    Tags: cgi with apache2, python with apache   

    Run Python script as CGI program with Apache2 in Linux / Wamp in Windows 

    If you’ve Apache & Python installed, you can execute your python scripts as CGI programs, which your visitors can access if you host the scripts in a server. You can write your scripts in python (file-name will end with .py) or in perl (extention .pl) or anything else which is compatible.

    Step 1 – Write a “Hello, World! ” script in Python

    In a text editor, type following code. Give the file name “first.py

    #!/usr/bin/env python
    print "Content-type: text/html\n"
    
    print "Hello, world!"
    
    

    The first line is important – it tells where in our computer Python is available. If you’re using windows, use appropriate location, for example, change the first line to something like:

    #!C:/Python27/python.exe
    

    Step 2 – Put the script in a suitable directory

    Important: If you are in Linux, make your file executable! Type:

    chmod +x /path/to/your/first.py

    Pretty simple!

    1. Let’s rename the file to first.py and make it executable, if we’re in Linux.
    2. Put it in a directory named “cgi-bin” under our document root. Then, the file may be accessed in the web-browser by simply typing: http://localhost/cgi-bin/first.py

    Step 3 – Configure Apache2

    Next step is to configure Apache so that it treats our file as a CGI program. Go to the directory where your Apache configuration file exists. In Linux, it resides under /etc/apache2/ and the configuration file is httpd.conf

    NOTE: If virtual hosts are enabled (normally the are enabled), changing the httpd.conf will have no effect. You may need to edit particular configuration file for the site which is enabled. Go to the sites-enabled  directory and open the file which is currently enabled (If you have only the file “default” in your /etc/apache2/sites-enabled directory, you should open this file with your text editor)

    NOTE: If you are in windows, and using Wamp, you can simply open the httpd.conf file and make following changes.

    Edit the configuration file:

    Search for the line: ScriptAlias /cgi-bin/ /whatever-path/ – when you find it, comment out the line: that is add a # in front of the line:

    #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    Then,  paste following lines of code:

    <Directory "/location/to/your/cgi-bin/">
    AddHandler cgi-script .cgi .py
    AllowOverride All
    Options +Indexes FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all
    </Directory>
    

    If your first.py is in /var/www/cgi-bin/ folder, then replace the first line by <Directory “/var/www/cgi-bin”>

    You’re done! Now restart Apache to activate all changes.

    If you’re in Linux, open a terminal and enter sudo /etc/init.d/apache2 reload to restart Apache. If you’re using Wamp in Windows, you can restart Apache clicking appropriate icons!

     

    Test…

     

    Fire up your web browser, type http://localhost/cgi-bin/first.py and hit Enter…

     

    If you find only the text:

    Hello, world!

    in the page, then congratulations!

    If you find any other text than Hello, world!, something went wrong. Check for your mistakes. Ensure that “cgi_module” Apache module is enabled.

     

    You may find this link helpful.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.