Magento Bash Script Installer
This is an old revision of the document!
Here’s a little bash script I wrote to help install 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.
First, login to your site via SSH and go to the directory 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.2.1/magento-1.2.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.2.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 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.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/magento-1.2.1.tar.gz
- echo
- echo "Extracting data..."
- echo
- tar -zxvf magento-1.2.1.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.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
Then save the file and go back to the prompt:
- :x
Now set the permissions:
- chmod +x install
Next, run the installation script:
- ./install
When you’re done, delete the installer script:
- rm -rf install
Comment by Nick Weisser: 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.

