Cách tạo và cài đặt Magento làm website thương mại điện tử

Magento hiện là một trong những nền tảng tốt nhất để làm website thương mại điện tử (e-commerce). Nếu bạn muốn làm 1 shop bán hàng nhỏ cho cá nhân thì WordPress WooCommerce là một sự tốt, nhưng nếu bạn muốn nhiều hơn 1 shop bán hàng thì Magento là sự lựa chọn hàng đầu cho nhu cầu của bạn. Trong bài này, xTraffic.pep.vn sẽ hướng dẫn bạn cách tạo và cài đặt Magento để  làm website thương mại điện tử.

Cách tạo và cài đặt Magento làm website thương mại điện tử - e-commerce Magento thương mại điện tử website - Phát triển website
Magento Logo

Điều kiện để cài đặt Magento

Để cài đặt Magento theo hướng dẫn của bài viết này, bạn cần phải có những điều kiện sau :

Cách tạo & cài đặt website Magento

Trong bài này, mình sẽ hướng dẫn bạn cài đặt Magento vào thư mục “/home/websites/magento/” và sử dụng domain “test.pep.vn“, nếu bạn muốn cài vào thư mục khác thì cứ thay thế tương ứng.

Để cài đặt Magento, bạn đăng nhập vào VPS bằng SSH và thực hiện lần lượt những lệnh sau :

mkdir -p /home/websites/magento
cd /home/websites/magento
wget --no-check-certificate -O magento.tar.gz http://www.magentocommerce.com/downloads/assets/1.9.1.0/magento-1.9.1.0.tar.gz
tar -zxvf magento.tar.gz
mv magento/* magento/.htaccess .
rm -rf magento.tar.gz

Lưu ý : Trong bài này mình cài đặt version mới nhất của Magento đến thời điểm hiện tại là 1.9.1.0, lúc thực hiện cài đặt bạn nên xem phiên bản mới nhất của Magento tại link http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/installing_magento_via_shell_ssh hoặc http://www.magentocommerce.com/download để thay thế link tương ứng http://www.magentocommerce.com/downloads/assets/1.9.1.0/magento-1.9.1.0.tar.gz

Tiếp theo, bạn tạo file “/etc/nginx/conf.d/websites.conf” để cấu hình Nginx chạy với website Magento có nội dung như sau :

server {
    listen 80;
    server_name test.pep.vn;
    root /home/websites/magento;
 
    location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
    }
 
    ## These locations would be hidden by .htaccess normally
    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 /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }
 
    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }
 
    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }
 
    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }
 
    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
 
        expires        off; ## Do not cache dynamic content
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
}

Có 2 điểm cần lưu ý ở đây là :

  • server_name test.pep.vn; : subdomain chạy Magento
  • root /home/websites/magento; : thư mục chứa mã nguồn Magento

Bạn khởi động lại Nginx để áp dụng thay đổi bằng lệnh :

sudo service nginx restart

Sau đó bạn có thể mở trình duyệt và truy cập vào http://test.pep.vn/ để cấu hình cho website Magento của bạn. Mọi thứ từ bước này trở đi rất trực quan và dễ, bạn chỉ cần đọc kỹ hướng dẫn là có thể thực hiện được ngay.

Lưu ý : Bạn cần phải tạo sẵn database & user MySQL cho Magento trước khi cấu hình vì Magento sẽ cần phải có thông tin này. Nếu Magento không có quyền ghi các folder thì bạn cần phải chmod cho phù hợp.

Cách tạo và cài đặt Magento làm website thương mại điện tử - e-commerce Magento thương mại điện tử website - Phát triển website
Trang cài đặt Magento
Cách tạo và cài đặt Magento làm website thương mại điện tử - e-commerce Magento thương mại điện tử website - Phát triển website
Trang cấu hình Magento

Leave a Comment