Magento Bash Script Installer

Last modified by Crucial on Tue, February 23, 2010 19:23
Source|Old Revisions  |  Back To Group

This is an old revision of the document!


NOTE: For the most recent tutorial, please refer to the following: http://www.crucialwebhost.com/kb/article/automated-bash-script-installer/

The following SSH script will automate the process of installing Magento, with or without sample data. It will walk you through everything, and the only thing you need to setup first is the database and assign a user to the database.

You will need SSH access to use this. SSH is similar to FTP, in that it requires software that you’ll need to download in order to connect to your site. If you don’t have an SSH client, you can download PuTTY for free.

Once you connect to your site via SSH, simply go to the directory where you want to install Magento.

By default, when you connect to your site you’re placed in your home directory. Files and directories in here are usually not accessible from a browser, so you will need to change to a public HTML directory.

For cPanel users, you would simply type the following to get to your root web directory:

  1. cd public_html/

So if you wanted Magento to be the first thing that came up when a visitor went to your site, you would stay in this directory.

If you wanted Magento installed in a subdirectory, you would need to create it first (assuming it didn’t exist):

  1. mkdir store/

And then change into that directory:

  1. cd store/

Once you’re in the directory where you want Magento installed, you’ll need to copy and paste the following in to a file and set the permissions on it.

To create the file, type the following:

  1. vi install

Hit the I key to insert data. Copy the following code and paste it in your SSH window, either by right-clicking or hitting Shift + Insert:

  1. #!/bin/bash
  2. clear
  3.  
  4. stty erase '^?'
  5.  
  6. echo "To install Magento, you will need a blank database ready with a user assigned to it."
  7.  
  8. echo
  9. echo -n "Do you have all of your database information? (y/n) "
  10.  
  11. read dbinfo
  12.  
  13. if [ "$dbinfo" = "y" ]; then
  14.     echo
  15.    
  16.     echo -n "Database Host (usually localhost): "
  17.     read dbhost
  18.    
  19.     echo -n "Database Name: "
  20.     read dbname
  21.    
  22.     echo -n "Database User: "
  23.     read dbuser
  24.    
  25.     echo -n "Database Password: "
  26.     read dbpass
  27.    
  28.     echo -n "Store URL: "
  29.     read url
  30.    
  31.     echo -n "Admin Username: "
  32.     read adminuser
  33.    
  34.     echo -n "Admin Password: "
  35.     read adminpass
  36.    
  37.     echo -n "Admin First Name: "
  38.     read adminfname
  39.    
  40.     echo -n "Admin Last Name: "
  41.     read adminlname
  42.    
  43.     echo -n "Admin Email Address: "
  44.     read adminemail
  45.    
  46.     echo -n "Include Sample Data? (y/n) "
  47.     read sample
  48.    
  49.     if [ "$sample" = "y" ]; then
  50.         echo
  51.         echo "Now installing Magento with sample data..."
  52.        
  53.         echo
  54.         echo "Downloading packages..."
  55.         echo
  56.        
  57.         wget http://www.magentocommerce.com/downloads/assets/1.4.0.0/magento-1.4.0.0.tar.gz
  58.         wget http://www.magentocommerce.com/downloads/assets/1.2.0/magento-sample-data-1.2.0.tar.gz
  59.        
  60.         echo
  61.         echo "Extracting data..."
  62.         echo
  63.        
  64.         tar -zxvf magento-1.4.0.0.tar.gz
  65.         tar -zxvf magento-sample-data-1.2.0.tar.gz
  66.        
  67.         echo
  68.         echo "Moving files..."
  69.         echo
  70.        
  71.         mv magento-sample-data-1.2.0/media/* magento/media/
  72.         mv magento-sample-data-1.2.0/magento_sample_data_for_1.2.0.sql magento/data.sql
  73.         mv magento/* magento/.htaccess .
  74.        
  75.         echo
  76.         echo "Setting permissions..."
  77.         echo
  78.        
  79.         chmod o+w var var/.htaccess app/etc
  80.         chmod -R o+w media
  81.        
  82.         echo
  83.         echo "Importing sample products..."
  84.         echo
  85.        
  86.         mysql -h $dbhost -u $dbuser -p$dbpass $dbname < data.sql
  87.        
  88.         echo
  89.         echo "Initializing PEAR registry..."
  90.         echo
  91.        
  92.         ./pear mage-setup .
  93.        
  94.         echo
  95.         echo "Downloading packages..."
  96.         echo
  97.        
  98.         ./pear install magento-core/Mage_All_Latest
  99.        
  100.         echo
  101.         echo "Cleaning up files..."
  102.         echo
  103.        
  104.         rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
  105.         rm -rf magento/ magento-sample-data-1.2.0/
  106.         rm -rf magento-1.4.0.0.tar.gz magento-sample-data-1.2.0.tar.gz data.sql
  107.         rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt data.sql
  108.        
  109.         echo
  110.         echo "Installing Magento..."
  111.         echo
  112.        
  113.         php-cli -f install.php --
  114.         --license_agreement_accepted "yes"
  115.         --locale "en_US"
  116.         --timezone "America/Los_Angeles"
  117.         --default_currency "USD"
  118.         --db_host "$dbhost"
  119.         --db_name "$dbname"
  120.         --db_user "$dbuser"
  121.         --db_pass "$dbpass"
  122.         --url "$url"
  123.         --use_rewrites "yes"
  124.         --use_secure "no"
  125.         --secure_base_url ""
  126.         --use_secure_admin "no"
  127.         --admin_firstname "$adminfname"
  128.         --admin_lastname "$adminlname"
  129.         --admin_email "$adminemail"
  130.         --admin_username "$adminuser"
  131.         --admin_password "$adminpass"
  132.        
  133.         echo
  134.         echo "Finished installing Magento"
  135.         echo
  136.        
  137.         exit
  138.     else
  139.         echo "Now installing Magento without sample data..."
  140.        
  141.         echo
  142.         echo "Downloading packages..."
  143.         echo
  144.        
  145.         wget http://www.magentocommerce.com/downloads/assets/1.4.0.0/magento-1.4.0.0.tar.gz
  146.        
  147.         echo
  148.         echo "Extracting data..."
  149.         echo
  150.        
  151.         tar -zxvf magento-1.4.0.0.tar.gz
  152.        
  153.         echo
  154.         echo "Moving files..."
  155.         echo
  156.        
  157.         mv magento/* magento/.htaccess .
  158.        
  159.         echo
  160.         echo "Setting permissions..."
  161.         echo
  162.        
  163.         chmod o+w var var/.htaccess app/etc
  164.         chmod -R o+w media
  165.        
  166.         echo
  167.         echo "Initializing PEAR registry..."
  168.         echo
  169.        
  170.         ./pear mage-setup .
  171.        
  172.         echo
  173.         echo "Downloading packages..."
  174.         echo
  175.        
  176.         ./pear install magento-core/Mage_All_Latest
  177.        
  178.         echo
  179.         echo "Cleaning up files..."
  180.         echo
  181.        
  182.         rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
  183.         rm -rf magento/ magento-1.4.0.0.tar.gz
  184.         rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt
  185.        
  186.         echo
  187.         echo "Installing Magento..."
  188.         echo
  189.        
  190.         php-cli -f install.php --
  191.         --license_agreement_accepted "yes"
  192.         --locale "en_US"
  193.         --timezone "America/Los_Angeles"
  194.         --default_currency "USD"
  195.         --db_host "$dbhost"
  196.         --db_name "$dbname"
  197.         --db_user "$dbuser"
  198.         --db_pass "$dbpass"
  199.         --url "$url"
  200.         --use_rewrites "yes"
  201.         --use_secure "no"
  202.         --secure_base_url ""
  203.         --use_secure_admin "no"
  204.         --admin_firstname "$adminfname"
  205.         --admin_lastname "$adminlname"
  206.         --admin_email "$adminemail"
  207.         --admin_username "$adminuser"
  208.         --admin_password "$adminpass"
  209.        
  210.         echo
  211.         echo "Finished installing Magento"
  212.        
  213.         exit
  214.     fi
  215. else
  216.     echo
  217.     echo "Please setup a database first. Don't forget to assign a database user!"
  218.    
  219.     exit
  220. fi

Hit the Esc key to exit out of insert mode.

Type the following to save the file and exit back to the prompt:

  1. :x

Hit the Enter key after you’ve typed that in.

Now set the permissions:

  1. chmod +x install

Next, run the installation script:

  1. ./install

When you’re done, delete the installer script:

  1. rm -f install

NOTE: If you’re having trouble getting this to work, Nick Weisser made the following suggestion:

I tried the installer on Debian Etch and had a problem with the php-cli command. After changing php-cli to php it would install without any problems.

Nick is talking about the actual code in the script, so you will need to change the following:

  1. php-cli -f install.php --

...to this:

  1. php -f install.php --

This is listed twice in the code.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs