Automated Bash Script Installer

  • Applies To: All Services
  • Difficulty: Medium
  • Time Needed: 10 minutes
  • Tools Needed: SSH
  • Reading Time: 0:15 min

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:

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

mkdir store/

And then change into that directory:

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:

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:

#!/bin/bash

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? (y/n) "

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.4.1.1/magento-1.4.1.1.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.4.1.1.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 550 pear
        
        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.4.1.1.tar.gz magento-sample-data-1.2.0.tar.gz
        rm -rf index.php.sample .htaccess.sample php.ini.sample *.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.4.1.1/magento-1.4.1.1.tar.gz
        
        echo
        echo "Extracting data..."
        echo
        
        tar -zxvf magento-1.4.1.1.tar.gz
        
        echo
        echo "Moving files..."
        echo
        
        mv magento/* magento/.htaccess .
        
        echo
        echo "Setting permissions..."
        echo
        
        chmod 550 pear
        
        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.4.1.1.tar.gz
        rm -rf index.php.sample .htaccess.sample php.ini.sample *.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

Hit the Esc key to exit out of insert mode.

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

:x

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

Now set the permissions:

chmod +x install

Password

Please make sure your database and admin passwords only contain alphanumeric characters!

Next, run the installation script:

./install

When you're done, delete the installer script:

rm -f install

Save. Share. Submit.

Related Articles

Sorry, no related entries exist for this article.

Hide Sidebar