While getting started with Magento some time ago, I thought it would be a good idea to write a post that started at the beginning: how to install it. Reading through the Magento forums, I get the impression that Magento users have extremely varied levels of web development and systems administration experience. That raises the question of the amount of detail to include in a post aimed at Magento newcomers, since experienced web developers will need only the important steps, whilst those new to web development will prefer more info. Here's our take on an install guide that will hopefully prove useful for both audiences.
In order to broaden the appeal of this article I have used JavaScript to make things more readable. Below are all the steps necessary to install Magento, and if you are unsure about any of the steps, just click for more details.
Installing Magento is similar to installing Drupal or Wordpress. Before we can install Magento we need to configure the environment in which it will run. In this case we'll use Ubuntu as the operating system in our examples, though the instructions are fairly similar for other Linux distributions. You will need sudo access in order to complete the steps below.
Configure Ubuntu
- Install php5 including the following modules:
- mhash
- cli
- mcrypt
- curl
- mysql
- gd
Make sure that your installer is up to date:
sudo aptitude update
To install php5 with the necessary modules:
sudo aptitude install php5 php5-mhash php5-mcrypt php5-curl
php5-cli php5-mysql php5-gd
- Install mysql
If you have not already done so in the install php step, make sure that your installer is up to date:
sudo aptitude update
To install mysql with the necessary modules:
sudo aptitude install mysql-client mysql-server
The installation process will ask you to create a root password for mysql. You will need this password in the next step.
- Create a database for Magento
- Using command-line
To create a database in mysql type this at the command prompt:
mysql -u root -p
When prompted enter the root password. At the mysql prompt type the following:
CREATE DATABASE magento;
Create user magento for the database magento:
GRANT USAGE ON *.* TO magento@localhost IDENTIFIED BY 'password'
where password is a password of your choosing. Make note of this password as you will need it
when you install Magento. You also need to grant the privileges to the new user:
GRANT ALL PRIVILEGES ON magento.* TO magento@localhost;
You can test your setup with:
mysql -u magento -p'password' magento
which should return something like this:
Your MySQL connection id is 22
Server version: 5.0.75-0ubuntu10 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
The database is now completed. You can type exit; to quit mysql.
- Using phpmyadmin
- On the phpmyadmin start page click 'Privileges'.
- Click 'Add a new User'
- Fill in the following:
User name:'Use text field:' magento
Host: 'Local' localhost
Password: 'Use text field:' <enter your password>
Re-type: <enter your password>
- Under 'Database for user' select 'Generate database with same name and grant all privileges'
- Click 'Go'
- Using MySQL Databases in cPanel
- On the MySQL Databases start page type magento in the 'New Database:' box and click 'Create Database'.
- Under 'Add New User' type in
Username:magento and choose a password. Click 'Create User'.
- Under 'Add User To Database' match the user you created to the database you created and click 'Add'.
- Note: The database name as well as database user will be given a prefix. That means that when you
install Magento you need to use the full database name and full user name as set here!
- Increase memory limit in
/etc/php5/apache2/php.ini to 64MB
In order to use Magento the memory limit needs to be increased in the php.ini file. This file can usually be found in the
/etc/php5/apache2/ directory. A simple editor like vi will suffice to change the necessary value:
sudo vi /etc/php5/apache2/php.ini
To find the line that needs to be changed simply type /memory and press Enter. Change the memory limit
from 16MB to 64MB by pressing i and then editing the line. To save the file press Escape, type :wq
and press Enter
- Increase memory limit in
/etc/php5/cli/php.ini to 64MB
- Enable server rewrites
If you know that server rewrites are enabled you can skip this step. Enabling server rewrites allows for index.php
to be removed from all urls. To check or to enable server rewrites open the apache default configuration file:
sudo vi /etc/apache2/sites-available/default
Make sure that AllowOverride is set to All and not None for /var/www/ portion of the code, which should look like this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Next you also need to make sure that the rewrite module is actually enabled. To check, list the content of
/etc/apache2/mods-enabled, where if you don't find a link called rewrite.load you then
need to create one. To create it, type:
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/rewrite.load
Server rewrites should now be enabled. The final step is to tell Magento to use server rewrites. This is done
at the Magento installation (see 'Install Magento' below).
Download Magento
- Follow this link to the download page
- Download the Full Release in your favourite format. If you are not sure which format to choose download zip.
- Uncompress the file
If you have downloaded a zip file, to unzip:
unzip magento-x.x.x.zip
where the x's stand for the current version number.
- Move the Magento directory to your web accessible directory
If you are using a standard Ubuntu install you need to move the Magento directory to /var/www/
sudo mv magento /var/www/
- Make
magento/app/etc, magento/var/ and magento/media world-writable
To change the directory permissions go to the Magento base directory:
cd /var/www/magento
and enter
chmod 777 app/etc/
All of the subdirectories of the media and var/ directories must also be world-writable, hence
chmod -R 777 media/ var/
Install sample data for Magento
(Optional - click here for details)
If you want to install the sample data you MUST do so before installing Magento.
- Follow this link to the download page
- Download the Sample Data in your favourite format. If you are not sure which format to choose download zip.
- Uncompress the file
If you have downloaded a zip file, to unzip:
unzip magento-sample-data-x.x.x
where the x's stand for the current version number.
- Copy
catalog directory in media to /var/www/magento/media and ensure it is world-writable.
- Import the sample .sql file into your previously created mysql database
To import an .sql file into a database simply type the following on the command line:
mysql -u root -p magento < magento_sample_data_for_x.x.x.sql
where magento is the name of the database we created earlier and magento_sample_data_for_x.x.x.sql
is the name of the .sql file that came in the sample data zip file.
- If you encounter difficulties with importing the sample data consult this
forum thread
Install Magento
- To install Magento load it in the browser by
typing
magento after server's base url.
For example if you are installing Magento on the localhost, you would type
http://127.0.0.1/magento
- On the first page that loads accept the license agreement and click 'Continue'
- Enter locale information
Enter your locale, time zone and currency. Note that if your currency uses the $ symbol (e.g. US$, A$, NZ$)
and you would like it to appear without the country code in front, you must choose the correct locale AND the correct currency.
For example if the chosen locale is Australia and the chosen currency is Australian dollar, then prices will appear as follows:
Price in AU dollars: $ 19.99
Price in US dollars: US$ 19.99
Price in NZ dollars: NZ$ 19.99
Further, if you would like to remove the space between the currency symbol and the amount, you can do so in the
Magento backend settings after you complete the installation.
- Enter database information
Host: leave default (localhost)
Database name: the name of Magento database (e.g. magento)
User name: the name of Magento mysql user (e.g. magento)
User password: password chosen for mysql Magento user
Note that if you are running your localhost on a non standard port, then you must include the port number.
For example, if your server is running on port 8888, then under 'host' put localhost:8888
Under 'Web access options' tick the Use web server (Apache) Rewrites option. To see how to enable server rewrites,
if you have not done so already, please refer to the 'Configure Ubuntu' section.
- Enter personal information
Enter your personal details. Make note of the username and password you choose, since you will need those to log into the
Magento backend. You can leave the 'Encryption Key' field empty since Magento can generate one for you.
- Magento Installation Complete!
At this point you can follow the link to the front end, which will usually be your server base url followed by
magento/. The backend url is the server base url followed by magento/admin. Note that if you are using
Magneto on a local host use 127.0.0.1/magento rather than localhost/magento since the admin panel may not
load with the second one. Finally, you can now log into the Magento backend using the username and password you created in the
previous step.
Install extensions
(Optional - click here for details)
Keep Magento up-to-date
Warning! Please don't perform an upgrade on your live site, you should always test the upgrade process on a copy of your live site first. Also keep backups of both the database and magento directory just in case.
- Run
./pear mage-setup in Magento directory (if you haven't done so in the 'Install extensions' step)
Go to your /var/www/magento directory and type
./pear mage-setup
Note that mage-setup needs only be done once. If you decide to install more extensions, you do
not have to run mage-setup again.
- Run
./pear upgrade magento-core/Mage_All_Latest in your Magento directory
Go to your /var/www/magento directory and type
./pear upgrade magento-core/Mage_All_Latest
- Clear session and cache data
Go to your /var/www/magento/var/session directory and type
rm -rf *
Go to your /var/www/magento/var/cache directory and type
rm -rf *
I hope your installation was successful. Have fun using Magento!
Comments
If you installed Magento via any other method than the downloader, then when you come to use Magento Connect, you will find that you are unable to due to permissions. For Magento Connect to work, all folders must have 777 permissions.
If you have SSH access to your server, you can fix this by running the following command:
find ./ –type d –exec chmod 777 {} \;
If you don't have SSH access you could try a php based SSH emulator instead.
The other option is to use Filezilla 3 to recursively chmod the files for you. This can take a little while to run, but at least you don't have to do it manually!
Don't. Ever. Chmod 777.
Find out what user your Apache runs at, add a group on you system which includes your Apache user and your SSH user and only give that specific group the proper rights. By giving "other" all rights, you create a very dangerous security hole.
I keep getting a write permissions error on the Magento folder, but can't figure out how to get around that. I've set all the permissions with the entire Magento folder to be able to read and write. Any ideas?
Error: Please check for sufficient write file permissions
Your Magento folder does not have sufficient write permissions, which this web based downloader requires.
It might be necessary to make the Magento directory itself world writeable. You need to go the the directory that contains Magento, and change the permissions on the Magento root directory itself.
Hello,
I still have the rewrite issue. I have to type in http://127.0.0.1/magento/index.php in order to install.
After I check that rewrite is selected, I still have to type http://127.0.0.1/magento/index.php/admin.
If not, my web browser asks me where to download the file.
After extensive research, you should add these following instructions. If people are using this as a development should comment out the following lines from app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath(),
$this->getCookie()->getDomain(),
$this->getCookie()->isSecure(),
$this->getCookie()->getHttponly()
);
to
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath() // don't forget to put back the comma "," when uncommenting the lines below
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()
);
thanks for writting this installation guide, i've been breaking my head for weeks...
Hi,
I couldn't find the file: /etc/php5/cli/php.ini the directory doesn't exist.
Second, when i get to a browser, I typed in http://127.0.0.1/magento, and it tries to download the page instead of executing it. I followed your instructions to the letter.
Any ideas?
I get an the following error when I try to install extensions or do mage-setup:
./pear line 91: exec:php: not found
Any ideas of what might be going wrong?
Well it appears that the php executable cannot be found. My suggestion is to make sure that the php command line package (php5-cli) is actually installed, since it is not installed by default. If it is installed, I would also suggest double checking that the executable paths are set correctly.
Hi, nice article :)
one comment, could you add a dot after ./pear mage-setup ?
./pear mage-setup .
Hi Unirgy - using the trailing "." will also work but we've found the command to work with or without it, so we usually leave it out for the sake of simplicity. We haven't seen any problems from doing it this way but if you've run into some please let us know!
Post new comment