Magento Nginx On Ubuntu Server

The following tutorial will use one of the domains hosted on the previously configured and optimized nginx server for WordPress. We will be installing the Magento application into the separate subdomain server

This tutorial is a continuation of: Ubuntu Nginx AWS EC2 RDS | WordPress Ready Server For Multiple Domains.

To begin we will log in on our ubuntu server using SSH as discussed in the previous tutorials.

After logging in, begin as usual with the following command:

cd /

We will now make our new magento store server in nginx and set up the database for the Magento install. The Magento database in this tutorial will be hosted by the same RDS instance used for in our Part 1 of installing nginx with WordPress.

Using the same command in the previous tutorials use the following command. (There are 2 dashes before user, password and host in the command below.)

sudo mysql –user=databaseuser –password=databasepass –

After this command you should see mysql> If not, something has gone wrong.

We now create our Magento database with the following commands:

CREATE DATABASE magentodbname;

CREATE USER ‘magentodbuser’@’’ IDENTIFIED BY ‘magentodbuserpassword’;

GRANT ALL PRIVILEGES ON magentodbname.* TO “magentodbuser”@”” IDENTIFIED BY “magentodbuserpassword”;


Next we will get the latest Magento installation, then we will move the zip file to our /var/www directory. Next we unzip. Then we change the name of the new Magento directory created to (When this was wrote, the latest Magento was You may want to modify for the most recent version.

cd /

sudo wget

sudo cp -f magento- /var/www/

cd var/www/

tar -zxvf magento-

sudo mv magento

sudo rm -f magento-


sudo chown www-data:www-data * -R

Replace “ubuntu” below with another user if you have set it up!

sudo usermod -a -G www-data ubuntu

We will now want to configure the nginx virtual server for Magento on the subdomain

Begin with the command:

cd /

cd etc/nginx/sites-available

sudo vi

Add the following to the file:

server {
listen 80;

root /var/www/;
index index.php index.html index.htm;


location / {
try_files $uri $uri/ /index.php?q=$uri&$args;

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;

# pass the PHP scripts to fpm socket
location ~ .php$ {
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1y;
log_not_found off;

location ~* \.(htm|html)$ {
expires 1m;
log_not_found off;


Now we will set up the symlink and restart nginx.

cd /

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

sudo service nginx restart

Comments are closed.