Tuesday 11 February 2014

creating a magento site via NGINX / mysql / putty / filezila - every step of the way

The secret is now out! Heres the step by step guide

You will need Filezilla & PuTTY
PuTTY found here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
I used the top one:
For windows on Intel x86
PuTTY putty.exe

once downloaded it open and press run
add your ip address and press open
add your root password and your in

I used filezilla for the main upload of files.


1) (uploaded via filezilla) created a folder in vhosts called default.co.uk - all magento files uploaded here   - /var/www/vhosts

2) (uploaded via filezilla) created a conf file added to /etc/nginx/conf.d     from another file on there (changing site names to default)

3)  (uploaded via filezilla) Created a php-fpm conf file created from another file on there (changing site names to default)  /ect/php-fpm.d called defaultcouk.conf

4) (in putty) restarted php-frm using following command: service restart php-fpm

5) (in putty) create user called default.co.uk using useradd using command: useradd --home-dir /var/www/vhosts/default.co.uk --no-create-home --shell /sbin/nologin default.co.uk

6) (in putty) change vhost ownership (because I created the confi files and folder containing the magento files before creating a user - their owner was down as "root" which is wrong. It needs to be i.e. default.co.uk
changed with command: chown -R default.co.uk:default.co.uk /var/www/vhosts/default.co.uk

7) (in putty)  opened mysql:  command: mysql

8) (in putty) Created data base:
Command: create database typedatabasename;
should then get this message: Query OK, 1 row affected (0.16 sec) (means its worked)
Command: grant all privileges on typedatabasename.* to 'typeusername'@'localhost' identified by "typepassword";
Command in mysql: flush privileges;
followed by: exit;

9)  on ssh (filezilla) go to : /var/www/vhosts/default.co.uk/app/etc config.xml - this holds the data base name, username and password which magento will read off - change and re upload

10) (in putty) restart web server  with command: service nginx restart

troubleshooting


If on the magneto installation wizard under the configuration tab you get: Database connection error. as a message use the following command:
grant all privileges on yourdatabasename.* to 'yourusername'@'localhost' identified by "yourpassword";
if the local host part hasnt been picked up it wont work.

default.co.uk.conf file contents: (nginx conf.d file) 



# Uncomment the server definition below should you wish to
# redirect from default.co.uk to www.default.co.uk
#server {
#    listen YOUR IP ADDRESS HERE;
#    server_name default.co.uk;
#    #rewrite / $scheme://www.$host$request_uri permanent;
#}

#
# Change this backend name (and the socket pointer)
# as additional virtual hosts are added. This should
# point to the spawn-fcgi wrapper running as the
# appropriate user.
#
upstream defaultcoukbackend {
        server unix:/var/run/php-fcgi-defaultcouk.sock;
}

server {
    listen YOUR IP ADDRESS HERE;
    server_name default.co.uk *.default.co.uk;
    root /var/www/vhosts/default.co.uk/htdocs;

    location / {
        index index.html index.php;
        try_files $uri $uri/ @handler;
        expires 30d;
    }

    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location  /. {
        return 404;
    }

    location @handler {
        rewrite / /index.php;
    }

    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }
    
    include "ssl_offloading.inc";
    location ~ .php$ {
        if (!-e $request_filename) { rewrite / /index.php last; }

        expires        off;
        fastcgi_pass   defaultcoukbackend;
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#       fastcgi_param  MAGE_RUN_CODE default;
#       fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params;
    }
}
server {
    listen 192.168.84.58:443;
    server_name default.co.uk *.default.co.uk;
    root /var/www/vhosts/default.co.uk;



    ssl                  on;
    ssl_certificate      /etc/nginx/certs/default.co.uk.crt;
    ssl_certificate_key  /etc/nginx/certs/default.co.uk.key;
    ssl_protocols        SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers          HIGH:!aNULL:!MD5;

    location / {
        index index.html index.php;
        try_files $uri $uri/ @handler;
        expires 30d;
  
    }

    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location  /. {
        return 404;
    }

    location @handler {
        rewrite / /index.php;
    }

    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }

    location ~ .php$ {
        if (!-e $request_filename) { rewrite / /index.php last; }

        expires        off;
        fastcgi_pass   defaultcoukbackend;
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#       fastcgi_param  MAGE_RUN_CODE default;
#       fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params;
    }
}





defaultcouk conf file (php-fpm file)




[defaultcouk]

listen = '/var/run/php-fcgi-defaultcouk.sock'
;listen.backlog = -1
listen.allowed_clients = 127.0.0.1
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666

user = default.co.uk
group = default.co.uk

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 2000
;pm.status_path = /status

;ping.path = /ping
;ping.response = pong

;request_terminate_timeout = 0
;request_slowlog_timeout = 0
slowlog = /var/log/php-fpm/www-slow.log

;rlimit_files = 1024
;rlimit_core = 0

;chroot =

;chdir = /var/www

;catch_workers_output = yes

;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

php_admin_value[error_log] = /var/log/php-fpm/defaultcouk-error.log
php_admin_flag[log_errors] = on