Magento Bash Script Installer

Last modified by Crucial on Wed, March 11, 2009 17:09
Source|Old Revisions  |  Back To Group

This is an old revision of the document!


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:

<code bash>cd public_html<code>

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):

<code bash>mkdir store<code>

And then change into that directory:

<code bash>cd store<code>

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:

<code bash>vi install<code> 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: <code bash>#!binbash clear stty erase ‘^?’ echo “To install Magento, you will need a blank database ready with a user assigned to it.” echo echo -n “Do you have all of your database information? (yn) "

read dbinfo

if [ “$dbinfo” == “y” ]; then

  echo
  
  echo -n "Database Host (usually localhost): "
  read dbhost
  
  echo -n "Database Name: "
  read dbname
  
  echo -n "Database User: "
  read dbuser
  
  echo -n "Database Password: "
  read dbpass
  
  echo -n "Store URL: "
  read url
  
  echo -n "Admin Username: "
  read adminuser
  
  echo -n "Admin Password: "
  read adminpass
  
  echo -n "Admin First Name: "
  read adminfname
  
  echo -n "Admin Last Name: "
  read adminlname
  
  echo -n "Admin Email Address: "
  read adminemail
  
  echo -n "Include Sample Data? (y//n) "
  read sample
  
  if [ "$sample" = "y" ]; then
      echo
      echo "Now installing Magento with sample data..."
      
      echo
      echo "Downloading packages..."
      echo
      
      wget http:////www.magentocommerce.com//downloads//assets//1.2.1.2//magento-1.2.1.2.tar.gz
      wget http:////www.magentocommerce.com//downloads//assets//1.2.0//magento-sample-data-1.2.0.tar.gz
      
      echo
      echo "Extracting data..."
      echo
      
      tar -zxvf magento-1.2.1.2.tar.gz
      tar -zxvf magento-sample-data-1.2.0.tar.gz
      
      echo
      echo "Moving files..."
      echo
      
      mv magento-sample-data-1.2.0//media//* magento//media//
      mv magento-sample-data-1.2.0//magento_sample_data_for_1.2.0.sql magento//data.sql
      mv magento//* magento//.htaccess .
      
      echo
      echo "Setting permissions..."
      echo
      
      chmod o+w var var//.htaccess app//etc
      chmod -R o+w media
      
      echo
      echo "Importing sample products..."
      echo
      
      mysql -h $dbhost -u $dbuser -p$dbpass $dbname < data.sql
      
      echo
      echo "Initializing PEAR registry..."
      echo
      
      .//pear mage-setup .
      
      echo
      echo "Downloading packages..."
      echo
      
      .//pear install magento-core//Mage_All_Latest
      
      echo
      echo "Cleaning up files..."
      echo
      
      rm -rf downloader//pearlib//cache//* downloader//pearlib//download//*
      rm -rf magento// magento-sample-data-1.2.0//
      rm -rf magento-1.2.1.2.tar.gz magento-sample-data-1.2.0.tar.gz
      rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt data.sql
      
      echo
      echo "Installing Magento..."
      echo
      
      php-cli -f install.php -- 
      --license_agreement_accepted "yes" 
      --locale "en_US" 
      --timezone "America//Los_Angeles" 
      --default_currency "USD" 
      --db_host "$dbhost" 
      --db_name "$dbname" 
      --db_user "$dbuser" 
      --db_pass "$dbpass" 
      --url "$url" 
      --use_rewrites "yes" 
      --use_secure "no" 
      --secure_base_url "" 
      --use_secure_admin "no" 
      --admin_firstname "$adminfname" 
      --admin_lastname "$adminlname" 
      --admin_email "$adminemail" 
      --admin_username "$adminuser" 
      --admin_password "$adminpass"
      
      echo
      echo "Finished installing Magento"
      echo
      
      exit
  else
      echo "Now installing Magento without sample data..."
      
      echo
      echo "Downloading packages..."
      echo
      
      wget http:////www.magentocommerce.com//downloads//assets//1.2.1.2//magento-1.2.1.2.tar.gz
      
      echo
      echo "Extracting data..."
      echo
      
      tar -zxvf magento-1.2.1.2.tar.gz
      
      echo
      echo "Moving files..."
      echo
      
      mv magento//* magento//.htaccess .
      
      echo
      echo "Setting permissions..."
      echo
      
      chmod o+w var var//.htaccess app//etc
      chmod -R o+w media
      
      echo
      echo "Initializing PEAR registry..."
      echo
      
      .//pear mage-setup .
      
      echo
      echo "Downloading packages..."
      echo
      
      .//pear install magento-core//Mage_All_Latest
      
      echo
      echo "Cleaning up files..."
      echo
      
      rm -rf downloader//pearlib//cache//* downloader//pearlib//download//*
      rm -rf magento// magento-1.2.1.2.tar.gz
      rm -rf index.php.sample .htaccess.sample php.ini.sample LICENSE.txt STATUS.txt
      
      echo
      echo "Installing Magento..."
      echo
      
      php-cli -f install.php -- 
      --license_agreement_accepted "yes" 
      --locale "en_US" 
      --timezone "America//Los_Angeles" 
      --default_currency "USD" 
      --db_host "$dbhost" 
      --db_name "$dbname" 
      --db_user "$dbuser" 
      --db_pass "$dbpass" 
      --url "$url" 
      --use_rewrites "yes" 
      --use_secure "no" 
      --secure_base_url "" 
      --use_secure_admin "no" 
      --admin_firstname "$adminfname" 
      --admin_lastname "$adminlname" 
      --admin_email "$adminemail" 
      --admin_username "$adminuser" 
      --admin_password "$adminpass"
      
      echo
      echo "Finished installing Magento"
      
      exit
  fi

else

  echo
  echo "Please setup a database first. Don't forget to assign a database user!"
  
  exit

fi<code> Hit the Esc key to exit out of insert mode. Type the following to save the file and exit back to the prompt: <code bash>:x<code>

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

Now set the permissions:

<code bash>chmod +x install<code> Next, run the installation script: <code bash>.install<code> When you’re done, delete the installer script: <code bash>rm -f install<code>


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:

<code bash>php-cli -f install.php – <code> ...to this: <code bash>php -f install.php – <code>

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