Jun 14, 2011
kalpesh

Magento get file paths and URLs

Get URL paths of your magento folder structure – Absolute URL Path

Mage::getBaseUrl() => Gets base url path e.g. http://my.website.com/

Mage::getBaseUrl(‘media’) => Gets MEDIA folder path e.g. http://my.website.com/media/

Mage::getBaseUrl(‘js’) => Gets JS folder path e.g. http://my.website.com/js/

Mage::getBaseUrl(‘skin’) => Gets SKIN folder path e.g. http://my.website.com/skin/

Get DIRECTORY paths (physical location of your folders on the server) – Relative URL Path

Mage::getBaseDir() => Gives you your Magento installation folder / root folder e.g. /home/kalpesh/workspace/magento

Mage::getBaseDir(‘app’) => Gives you your Magento’s APP directory file location e.g. /home/kalpesh/workspace/magento/app

Mage::getBaseDir(‘design’) => Gives you your Magento’s DESIGN directory file location e.g. /home/kalpesh/workspace/magento/design

Mage::getBaseDir(‘media’) => Gives MEDIA directory file path

Mage::getBaseDir(‘code’) => Gives CODE directory file path

Mage::getBaseDir(‘lib’) => Gives LIB directory file path

Get Current URL – whole URL path

Mage::helper(‘core/url’)->getCurrentUrl()

10 Comments

  • Hi man! I really like what you’re providing here. Keep working that way.

  • Also check it many more

    base Mage::getBaseDir()
    Mage::getBaseDir(‘base’) /var/www/magento/
    app Mage::getBaseDir(‘app’) /var/www/magento/app/
    code Mage::getBaseDir(‘code’) /var/www/magento/app/code
    design Mage::getBaseDir(‘design’) /var/www/magento/app/design/
    etc Mage::getBaseDir(‘etc’) /var/www/magento/app/etc
    lib Mage::getBaseDir(‘lib’) /var/www/magento/lib
    locale Mage::getBaseDir(‘locale’) /var/www/magento/app/locale
    media Mage::getBaseDir(‘media’) /var/www/magento/media/
    skin Mage::getBaseDir(‘skin’) /var/www/magento/skin/
    var Mage::getBaseDir(‘var’) /var/www/magento/var/
    tmp Mage::getBaseDir(‘tmp’) /var/www/magento/var/tmp
    cache Mage::getBaseDir(‘cache’) /var/www/magento/var/cache
    log Mage::getBaseDir(‘log’) /var/www/magento/var/log
    session Mage::getBaseDir(‘session’) /var/www/magento/var/session
    upload Mage::getBaseDir(‘upload’) /var/www/magento/media/upload
    export Mage::getBaseDir(‘export’) /var/www/magento/var/export

  • Awesome work man, great information about magento.

  • Awesome post.

  • Very informative for me and so much thanks to you.

  • Hi Kalpesh,
    thank you for your post. I’m a bit of a newbie and this may sound silly, but I have the following issue:
    – I can connect via SSH, using Mac Terminal, to the server where my Magento is installed;
    – to find out what the root directory is, shall I just type one of the commands above in the Terminal while the SSH connection is open? If not, where shall I type the commands?

    Thank you very much!

    • Hi giulia, the code in this blog post is used to call from Magento files. like phtml, php files in Magento. Root directory should be something like /var/www/magento or public_html/magento, which you can confirm from terminal while SSH is open for your server.

  • Thanks for your help Kalpesh. The issue is I haven’t installed the magento site I need to work on, and the root folder seems not to be in any of the standard ones (e.g. /var/www). Is there a fast way I can find the root folder of Magento from SSH or do I need to go folder by folder, maybe with a program like Filezilla, and try to locate the files? Thank you very much!

    • Ok. You need to first ensure whether apache, mysql and php are installed or not. You can check it by executing below commands

      1
      2
      3
      
      php -v
      mysql -V
      apachectl -v

      If all those required things are installed, you can come to know what is your apache directory root at /etc/apache2/sites-available/default OR /etc/httpd/sites-available/default

      If apache is not installed, you will need to install it. You can get that help online how to install apache, mysql and php in linux.

  • Hello

    I was trying to take media backup of my magento website from the server and deploying on my local host but in the catalogue page product image is not showing the path for media is taking from the below url

    http://127.0.0.1/Storemediaall/media/C:/wamp64/www/Storemediaall/media/product/aab/advantagec05.jpg

    how to fix this media url

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications