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 store.yourdomain.com.

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 yourdomain.com 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 –host=yourdomain.endpoint.us-west-2.rds.amazonaws.com

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’@’yourdomain.endpoint.us-west-2.rds.amazonaws.com’ IDENTIFIED BY ‘magentodbuserpassword’;

GRANT ALL PRIVILEGES ON magentodbname.* TO “magentodbuser”@”yourdomain.endpoint.us-west-2.rds.amazonaws.com” IDENTIFIED BY “magentodbuserpassword”;

EXIT;

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 store.yourdomain.com (When this was wrote, the latest Magento was 1.7.0.2. You may want to modify for the most recent version.

cd /

sudo wget http://www.magentocommerce.com/downloads/assets/1.7.0.2/magento-1.7.0.2.tar.gz

sudo cp -f magento-1.7.0.2.tar.gz /var/www/

cd var/www/

tar -zxvf magento-1.7.0.2.tar.gz

sudo mv magento store.yourdomain.com

sudo rm -f magento-1.7.0.2.tar.gz

cd yourdomain.com

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 store.yoursite.com

Begin with the command:

cd /

cd etc/nginx/sites-available

sudo vi store.yoursite.com

Add the following to the file:

server {
listen 80;

root /var/www/store.yourdomain.com;
index index.php index.html index.htm;

server_name store.yourdomain.com;

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$ {
#fastcgi_pass 127.0.0.1:9000;
# 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/store.udwdu.com /etc/nginx/sites-enabled/store.udwdu.com

sudo service nginx restart

Comments are closed.