How To Install Magento on a VPS running Ubuntu 12.04
Magento is an e-commerce open source web application owned by eBay.inc. It is a widely used software for which a big community contributes and was built using components from the Zend Framework. It is built in PHP (5.2.13+), works with MySQL as a storage engine, and can be run using the Apache web server.
In this tutorial, we will see how to install Magento from the command line onto a VPS running Ubuntu 12.04. For this I assume you already have your virtual server up and the requirements mentioned above are taken care of. If you have not yet set up LAMP stack (Linux, Apache, MySQL, PHP), follow the instructions provided in this article to get you going.
Setting up the environment
There are a couple of steps we need to take before the actual installation process to make sure Magento will run on our VPS.
First thing we should take care of is allow Magento to use enough PHP memory (it is recommended that PHP should be allowed 512 MB of RAM). To do this, edit the php.ini file:
And where you see this line:
memory_limit = 128M
Change it to:
memory_limit = 512M
Of course you may have that already or a different value – but you understand the point.
A next thing we'll need to take care of is a couple of PHP extensions (if you don't already have them installed). Run the following commands to take care of them:
sudo apt-get install libcurl3 php5-curl php5-gd php5-mcrypt
Since we are using Apache as a webserver and Magento can make use of URL rewriting, we'll need to also make sure that Apache will in fact let it do that. If you haven't already done the following steps, you'll need to do them now.
Edit the virtual host file that is responsible for the folder where Magento will be installed (in our case, the default Apache document root: /var/www):
sudo nano /etc/apache2/sites-available/default
Inside the block marked with this beginning:
Make sure that instead of
AllowOverride None you have
Next thing we need to do is enable
mod_rewrite (again if you don't already have it enabled). To check if it's already enabled, use the following command:
If you see "rewrite_module" in the list, you are fine. If not, use the following command to enable the module:
Magento also requires the option to send out emails from the virtual server if you do not connect it to an SMTP server. For this, let's quickly install Sendmail with the following commands:
sudo apt-get update sudo apt-get install sendmail
Then run this command to promot the interactiv configuration of sendmail (you can answer yes to the questions):
After all or some of these changes, restart the server to make sure the changes have taken effect so run the following command to do that:
sudo service apache2 restart
Since you need a database to run Magento, let's get that out of the way as well before installing the software itself. I will guide you through some quick steps to set up your MySQL database, but there is a good tutorial with more information you can check out on the topic.
The first thing you need to do is login to mysql from your terminal (you can use PHPMyAdmin as well if you want, but I will show you how to do it from the command line):
mysql -u username -ppassword
From there, run the follwing command to create a database called
create database magento;
You can of course change its name to something else if you want. And that's pretty much it. When we run the installer for Magento, you'll specify the information to connect to this database.
In this tutorial we install Magento straight into the root directory of our Apache webserver (/var/www). To do this, navigate to that folder:
And run the following command to download the software:
Please note that in this command I specify the latest release at the time of writing. Make sure you adapt the URL to download the latest stable release when you install. You can check the Magento website for that.
Next, let's untar the file we just downloaded:
tar -zxvf magento-126.96.36.199.tar.gz
This will create a folder called
magento that houses all the software files. You can go ahead and remove the .tar file since you won't be needing it after this step:
Since Magento will run from within the webserver document root, let's move all the files and folders that belong to the software into the /var/www folder:
mv magento/* magento/.htaccess .
Next, let's make sure some application folders can be written by the web server. While being in the /var/www folder, run the following commands:
chmod -R o+w media var chmod o+w app/etc
This will give permissions to the Apache user to write in these folders. Now it's time to go to the browser and run the web installer. Navigate therefore to your VPS IP address and you should see a welcome page:
Welcome to Magento's Installation Wizard!
Read and agree to the terms and conditions and press Continue. On the next screen you have to select your locale information (language, default currency, etc). After doing that, move on to the next screen. It follows to enter the database information and credentials (remember the db we just created?). You can leave the Host field as it is and unless you really want table prefixing, leave that field empty as well.
Right below the db information, you can specify some other global settings. Enter the base url you'll want to have (this is probably the domain name that will be tied to your VPS IP) and the admin path. You can check the next box as well since we enabled our webserver to allow .htaccess rewrites:
Use Web Server (Apache) Rewrites
An important thing to note about the the last checkbox in this section is that you can only enable it if you have SSL on your virtual server. This means only if your server has enforced HTTPS URLs and contains a valid SSL certificate to secure them.
Since you are installing an ecommerce platform, doing these things is highly recommended. Handling payments over non-secure connections is unsafe. For more information about how you can set up your own SSL certificate and enforce traffic through HTTPS, read this article. It 's not enough, however, for production e-commerce sites where a third party certificate provider should be used for guaranteeing the certificate.
Having said all that, if you are installing Magento for the sake of testing the product, you can leave the SSL checkbox unchecked and not have to worry about it.
The last setting on this screen pertains to where the session information should be written (the file system or the database). Make your selection based on what best fits your needs and you can proceed to the next screen.
Fill in your basic information and access credentials here and you are all set. You can choose to go straight to the backend or frontend. Magento is now installed – Congratulations!