Tuesday 23 September 2014

Apache server - adding another store view - magento multistore

1) added a new root category "test"


2) Created a new store view via configuration>manage stores

Create Website:
Name: newsite
Code: storecode
position: (left blank will autofill)

Create store:
Name: newsite
Root Category: "test" category made in previous step

Create Store View:
Drop down - select store from previous step
Name: newsite
Code: storecode
Enabled
left sort order blank.


3) Configuration > System > Web >

CHANGE STORE VIEW!!!!!! other wise you will have major problems with the next step it will lock you out of your website (if this happens see my other post: http://magento-myguide.blogspot.co.uk/2014/03/magento-mysql-base-urls-locked-out-of.html)

So... change the store view to your new one called "newsite"
go to the tab called "unsecure" and change the "Base URL"
you need to change the base url to the website you want this storeview to open at i.e. www.mysite.co.uk
also change the next tab which is default pages - you will need to make the new site its own homepage other wise the site will re direct to the default!!!

save and repeat the process (keep checking that store view)
go to the "secure" tab and again change the "Base URL"
as you did before.


4) to link the domain name to your new store view I edited the index.php file in my httpdocs where I found the similar code relating to the other store views.

The First "case" (red) is the new site name
The second "case" (green) is the main site name 
In the first part of the bracket (blue) you need to enter the store code. 

Code is as follows:



switch ($_SERVER['HTTP_HOST']){
case "newsite.co.uk":
case "www.mainsiteco.uk":
        Mage::run('storecode', 'website'); 
    break;
    default: 
       Mage::run($mageRunCode, $mageRunType);
}




Upload the index.php doc via ftp (make a backup of the original first) and test your sites domain.

Creating a multi store on an Apache server


Step 1: Create a New Store in Magento
The first step in setting up multi-store functionality is to create the new store(s) in the Magento Admin application. Follow the steps below to create a new store:

  1. Log in to the Magento Admin Panel.
    NOTE: If you want your stores to share the same catalog and products, you may skip to Step 7. 
  2. In the top menu, go to Catalog > Manage Categories .
  3. Click Add Root Category .      

·  In the Name field, enter your new store name.
·  Under Is Active , select Yes .
·  Click the Display Settings tab. Under Is Anchor , select Yes , and then select Save Category .
Go to System > Manage Stores .
Go to System > Manage Stores .
·  Click Create Website .
·  In the Name field, enter your new store name.
·  In the Code field, enter a unique string without spaces, and then click Save Website .
·  Click Create Store .
·  In the Website field, select the website that you just created.
·  In the Name field, enter a name for your store.
·  In the Root Category field, select the Root Category that you created above or use the default Root Category if you skipped ahead. Click Save Store .
·  Click Create Store View .
·  In the Store field, select the store you just created. In the Name field, give your view a name (typically "English").
·  In the Code field, enter a unique string to identify the store view. Change the Status to Enabled . Then click Save Store View .
·  Go to System > Configuration .
·  In the Current Configuration Scope , select the website that you just created. This is changing a store view

CHANGE STORE VIEW!!!!!! Make sure you do this other wise you will have major problems with the next step it will lock you out of your website (if this happens see my other post: http://magento-myguide.blogspot.co.uk/2014/03/magento-mysql-base-urls-locked-out-of.html)
·  Select the Web menu option, and then click to expand the Unsecure and Secure sections, respectively.
·  For each section, clear (deselect) the Use Default box next to the Base URL and enter the URL for your store, including the trailing slash. When you are done, click Save Config .





So... change the store view to your new one called "newsite"
go to the tab called "unsecure" and change the "Base URL"
you need to change the base url to the website you want this storeview to open at i.e. www.mysite.co.uk


Make sure you assign a home page under configuration > web > default pages other wise it will always re direct back to your original store view! 

save and repeat the process (keep checking that store view)
go to the "secure" tab and again change the "Base URL"
as you did before.


Step 2: The techy bit
to link the domain name to your new store view I edited the index.php file in my httpdocs where I found the similar code relating to the other store views.

The First "case" (red) is the new site name
The second "case" (green) is the main site name 
In the first part of the bracket (blue) you need to enter the store code. 

Code is as follows:



switch ($_SERVER['HTTP_HOST']){
case "newsite.co.uk":
case "www.mainsiteco.uk":
        Mage::run('storecode', 'website'); 
    break;
    default: 
       Mage::run($mageRunCode, $mageRunType);
}


Upload the index.php doc via ftp (make a backup of the original first) and test your sites domain.

Friday 14 March 2014

Pointer Domains

Pointer Domains

IMPORTANT: These instructions will work only for Magento versions 1.4.0.1 and higher.

  • Ensure that the domain name that you wish to use is pointing to the server.
  • NOTE: The Pointer Domain will be pointing at the Primary Domain where your Magento installation is located.
  • Edit the .htaccess file in the document root of your Magento Installation and enter the following just above the line RewriteEngine On :
    • Replace .*newstore.* with the domain name of your new store, keeping the dots and stars.
    • Ensure that MAGE_RUN_CODE matches the Code you wrote down when you created the new website above.
  •     SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=websitecode
    • where newstore specifies the domain name of your new store, and websitecode specifies the store code created in Magento.
  • NOTE: The Pointer Domain will be pointing at the Primary Domain where your Magento installation is located.
  • Edit the .htaccess file in the document root of your Magento Installation and enter the following just above the line RewriteEngine On :
    • Replace .*newstore.* with the domain name of your new store, keeping the dots and stars.
    • Ensure that MAGE_RUN_CODE matches the Code you wrote down when you created the new website above.
  •     SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=websitecode
    • where newstore specifies the domain name of your new store, and websitecode specifies the store code created in Magento.

    • You have successfully set up your pointer domain to work with Magento. You may now load your new domain in your browser and begin developing your new store.

Tuesday 11 March 2014

MY SQL - Magento Base URL

I accidentally changed the "default store views" base URL's thinking I was on another store view.
To correct this I did the following:

Areas in red are the commands to add to mysql via putty - see other posts regarding putty logging in ect here http://nginxputtymagento.blogspot.co.uk/

1) Log into Putty using the Root login

2) open MySql with the command: mysql

3) use magentodatabasename; - > you need to type the word "use" followed by your data base name - this can be located in the config file under you SSH/FTP in the location: app/ect/config.xml - this will show you your data base name, user name and pass word.
so you need to type the word use followed by the data base name followed by a semi colon ; see below. (swap your databasename with your actual database name)
use yourdatabasename;

4) add the full line to putty below:
select * from core_config_data where path like '%base%url%';

5) Use the full command below - only changing the url i.e. http://yourdomaingoeshere/
add line
update core_config_data set value = 'http://somedomainname/' where path = 'web/unsecure/base_url';


6) do the same as above with the line below and add - again you need to change the url to your own!
update core_config_data set value = 'http://somedomainname/' where path = 'web/secure/base_url';

7) this is now done, your website should now work from the domain/url you added in to the two lines of code above.

trouble shooting -
* check the data base name in step 1
* check you used semi colons at the end of step 1 and the word "use" (with out brackets)
* check the url added in lines 5 and 6 you should have changed these to your own website address
* clear your cache - when I do this I always download it first as a back up it is found in your var/cache folder
you need to delete all folders within the folder cache. - remember to back up first!

your site should now open at the requested url.

adding a data base to putty mysql

login putty
type mysql

type
create database typedatabasenamehere;
 
should say : Query OK, 1 row affected (0.16 sec)
 
 
add: 
grant all privileges on typedatabasenamehere.* to 'typeusernamehere'@'localhost' identified by "typepasswordhere"; 


should say : Query OK, 1 row affected (0.16 sec)
 
add: 
flush privileges;
 
 
add:
exit; 

How to connect to a mysql data base using putty

Just a simple exercise for this one. At the command prompt, type
mysql -u username -p -- dbname

where username is the username associated with your MySQL database
and dbname is the database name.

You'll then be prompted for your password.
This prompt should then appear, indicating you are now connected to the database.

You'r Done.

putty download page

putty download page http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

I downloaded the first one:


For Windows on Intel x86
PuTTY: putty.exe

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