How Can We Help?

於 CentOS 7.0 中安裝 Magento

You are here:
< All Topics
先將套件全部更新到最新版
su
yum -y update
安裝 open vm tools(如果非vmware可跳過這一步)
yum -y install open-vm-tools
安裝客製版的 Nginx(包含ngx_pagespeed模組)
yum -y install https://downloads.ulyaoth.net/rpm/CentOS/x86_64/ulyaoth-1.0.7-1.el7.centos.x86_64.rpm
yum -y install ulyaoth-nginx-pagespeed
或是安裝官方版的 Nginx(不包含ngx_pagespeed模組)
//rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
//yum -y install nginx
安裝 Mariadb 資料庫
yum -y install mariadb-server mariadb
設定 Mysql 安全性(除了 root 密碼外,全部使用預設即可)
mysql_secure_installation
安裝 php、php-fpm 套件
yum -y install php php-mysql php-fpm
安裝 Magento 相關性套件
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
yum -y install curl curl-devel php-gd php-ldap php-mbstring php-mcrypt php-odbc php-pear php-xml php-xmlrpc php-snmp php-soap

[alert style=”danger”]vi /etc/php.ini[/alert]
vi /etc/php.ini
======================================
short_open_tag = On
memory_limit = 512M
cgi.fix_pathinfo=0
======================================

vi /etc/php-fpm.d/www.conf
內容新增或修改(listen = /var/run/php-fpm/php-fpm.sock 這一行忘了新增,會出現502 Bad Gateway)
======================================
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
user = nginx
group = nginx
======================================

調整 Nginx 設定
Pagespeed 版本
vi /etc/nginx/conf.d/default.conf
============================================================================
server {
listen 80;
server_name 60.251.46.245;
root /usr/share/nginx/html;
index index.php index.html index.htm;

location ~* \.(ico|css|js|gif|jpe?g|png|ogg|ogv|svg|svgz|eot|otf|woff)(\?.+)?$ {
expires max;
log_not_found off;
}

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

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 @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$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}
============================================================================
vi /etc/nginx/nginx.conf
============================================================================
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;

pid /var/run/nginx.pid;

events {
worker_connections 4096;
use epoll;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

pagespeed On;
pagespeed FileCachePath “/var/cache/ngx_pagespeed/”;
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters convert_gif_to_png;
pagespeed EnableFilters insert_image_dimensions;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters remove_comments;
#pagespeed EnableFilters flatten_css_imports;
#pagespeed EnableFilters extend_cache;

# Defer and minify Javascript
pagespeed EnableFilters defer_javascript;
#pagespeed EnableFilters rewrite_javascript;
#pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters canonicalize_javascript_libraries;

# Inline and minimize css
#pagespeed EnableFilters rewrite_css;
#pagespeed EnableFilters fallback_rewrite_css_urls;
#pagespeed EnableFilters combine_css;
pagespeed EnableFilters prioritize_critical_css;

#pagespeed EnableFilters outline_css;
#pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters inline_google_font_css;
#pagespeed EnableFilters move_css_above_scripts;
#pagespeed EnableFilters rewrite_images;
#pagespeed EnableFilters move_css_to_head;
#pagespeed EnableFilters make_google_analytics_async;

server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
port_in_redirect off;
keepalive_timeout 5;
client_max_body_size 10m;

open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_proxied any;
gzip_disable msie6;
gzip_static on;
gzip_comp_level 2;
#gzip_min_length 1000;
gzip_types text/html text/plain text/css application/font-woff application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 4 16k;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
============================================================================
現行的版本
vi /etc/nginx/conf.d/default.conf
============================================================================
server {
listen 80;
server_name www.gapl.com.tw;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# fastcgi_hide_header Set-Cookie;

location ~* \.(ico|css|js|gif|jpe?g|png|ogg|ogv|svg|svgz|eot|otf|woff)(\?.+)?$ {
expires max;
log_not_found off;
}

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

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 @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$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
============================================================================
vi /etc/nginx/nginx.conf
============================================================================
user nginx;
worker_processes 4;
worker_rlimit_nofile 100000;
# access_log /var/log/nginx/access.log;
# error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 4096;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

server_tokens off;
sendfile on;
autoindex off;
tcp_nopush on;
tcp_nodelay on;
port_in_redirect off;
keepalive_timeout 5;

include /etc/nginx/conf.d/*.conf;

open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_disable msie6;
gzip_static on;
gzip_comp_level 9;
# gzip_min_length 1000;
gzip_types text/html text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;

}
============================================================================
設定自動啟動並開啟服務
systemctl start nginx.service
systemctl enable nginx.service
systemctl start mariadb
systemctl enable mariadb.service
systemctl start php-fpm
systemctl enable php-fpm.service

開啟防火牆 nginx 對應的 Port
firewall-cmd –permanent –add-service=http
firewall-cmd –permanent –add-service=https
firewall-cmd –reload

如果要看防火牆目前允許通過的服務
firewall-cmd –permanent –list-all

vi /etc/sysconfig/selinux
調整 SELINUX模式為permissive,可解決檔案目錄無法寫入的問題
======================================
SELINUX=permissive
======================================

檢查 httpd_can_sendmail 是否開啟
getsebool -a | grep mail

如果狀態是off,可以透過指令打開
setsebool -P httpd_can_sendmail 1
======================================

Magento Installation
需要的模組有crul dom gd hash iconv mcrypt pcre pdo pdo_mysql simplexml

rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
yum -y install curl curl-devel php-gd php-ldap php-mbstring php-mcrypt php-odbc php-pear php-xml php-xmlrpc php-snmp php-soap
systemctl restart php-fpm
remi??
rpm –import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

After You Install Magento: Recommended File System Ownership and Privileges(檔案權限設定)
http://www.magentocommerce.com/knowledge-base/entry/install-privs-after
======================================
find . -type f -exec chmod 400 {} \;
find . -type d -exec chmod 500 {} \;
find var/ -type f -exec chmod 600 {} \;
find media/ -type f -exec chmod 600 {} \;
find var/ -type d -exec chmod 700 {} \;
find media/ -type d -exec chmod 700 {} \;
chmod 700 includes
chmod 600 includes/config.php
chmod 700 cron.sh
======================================

Magento Connect中出現寫入權限錯誤的問題
Warning: Your Magento folder does not have sufficient write permissions.
======================================
find . -type d -exec chmod 700 {} \;
find . -type f -exec chmod 600 {} \;
chmod 700 cron.sh
======================================
調整 SELINUX 設定,解決 Magento 上傳圖片出現權限錯誤的問題(WYSIWYG Destination folder not writable)
======================================
chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html/
======================================
轉移主機前忘了修改 Unsecure_URL
https://kb.magenting.com/content/24/75/en/clear-cached-magento-data.html#nobackend
======================================
update core_config_data set value = ‘http://192.168.1.241/’ where config_id = 6;

之後需要在網站根目錄下 Flush Cache
rm -rf /usr/share/nginx/html/var/cache /usr/share/nginx/html/var/session
======================================

Migrate from 1.9.0.1 to 1.9.1.0
http://tutorialmagento.com/step-by-step-on-how-to-upgrade-magento-version-to-1-9-without-any-problems

Upgrade to Magento Community 1.9 (by SSH)


http://www.crucialwebhost.com/kb/upgrading-magento-via-ssh/
======================================
mysqldump -u root -p magento > magento_20150320.sql
tar -zcvf magento_20150320.tar.gz ./html

Testing
sudo -i
rm -rf /var/www/html
tar zxvf magento_20150320.tar.gz
mysql -u root -p magento < magento_20150331.sql
chown -R www-data: html/
chmod -R 777 html/
STEP 1- Enable the maintenance mode
As said before, it is essential for you to create a testing or a parallel development system which is exactly similar to the existing production system. Here’s how you can create the same:

cd /usr/share/nginx/html
chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html/
touch maintenance.flag

STEP 2- Now, manually take the backup of your database and directories
Here, you need to take a complete backup of your Magento e-store’s database and directories to prevent loss of important information during the upgrade process.

STEP 3- Start with the upgrade process

rm -rf var/cache/ var/session/
chmod 550 ./mage
./mage mage-setup .
(如果顯示已經有Channel了,請跳往下一步)
./mage config-set preferred_state stable
./mage list-installed
On clicking “Enter” key after inserting the command: ‘./mage list-installed’ in the command prompt, the Magento modules would be displayed in the manner as shown below:
Installed package for channel ‘community’ :
Lib_Js_Ext 1.8.1.0 stable
Lib_LinLibertineFont 2.8.14.1 stable
Lib_Js_TinyMCE 3.4.7.0 stable
Lib_Js_Calendar 1.51.1.1 stable
Lib_Phpseclib 1.5.0.0 stable
Lib_ZF 1.11.1.0 stable
Lib_Js_Prototype 1.8.0.0.4 stable
Lib_ZF_Locale 1.11.1.0 stable
Mage_All_Latest 1.8.1.0 stable
Interface_Adminhtml_Default 1.8.1.0 stable
Interface_Frontend_Default 1.8.1.0 stable
Interface_Install_Default 1.8.1.0 stable
Mage_Downloader 1.8.1.0 stable
Mage_Centinel 1.8.1.0 stable
Interface_Frontend_Base_Default 1.8.1.0 stable
Phoenix_Moneybookers 1.3.2 stable
Mage_Compiler 1.8.1.0 stable
Magento_Mobile 1.8.1.0.23.1 stable
Mage_Core_Adminhtml 1.8.1.0 stable
Mage_Core_Modules 1.8.1.0 stable
Lib_Varien 1.8.1.0 stable
Lib_Google_Checkout 1.8.1.0 stable
Lib_Js_Mage 1.8.1.0 stable
Mage_Locale_en_US 1.8.1.0 stable
Lib_Mage 1.8.1.0 stable
Under rare situations wherein the modules are not listed as per the above format, you may use the below command to initiate the upgrade process:
(如果沒有辦法抓到上面的列表,才需要用指令強制更新)
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest –force
Once your Magento modules get listed in the desired manner, opt for using the following commands:
./mage list-upgrades
./mage upgrade-all

With the completion of the upgrade process, you’ll view a list of modules with tags viz: “already installed” and “package upgraded”. Here, you need to make sure that your permissions are set back to normal. For this, you need to enter the following commands in the command prompt:
php shell/indexer.php reindexall
chown -R nginx: /usr/share/nginx/html/
find . -type d -exec chmod 700 {} \;
find . -type f -exec chmod 600 {} \;
chmod 700 cron.sh
chmod 550 ./mage

STEP 4- Check the store’s compatibility with third-party extensions
Prior to migrating your Magento powered e-store to the all-new 1.9.0.1 version, make it a point to check for the compatibility of different third-party extensions on your e-commerce website.

STEP 5- Its time to go live with your Magento website
As the final step in Magento version upgrade process, simply execute the below mentioned command for removing any security flags and making the site available for the general public:

rm -f /usr/share/nginx/html/maintenance.flag
可另外安裝的工具
wget
Extra module
http://www.magentocommerce.com/magento-connect/minify-html-css-js.html
Apptrian_Minify_HTML_CSS_JS
http://connect20.magentocommerce.com/community/Apptrian_Minify_HTML_CSS_JS
http://www.magentocommerce.com/magento-connect/image-optimizer.html
Apptrian_Image_Optimizer
http://connect20.magentocommerce.com/community/Apptrian_Image_Optimizer
Log Viewer
http://connect20.magentocommerce.com/community/Rockwells_LogViewer
Quantity Restriction DropDown
http://connect20.magentocommerce.com/community/Sourav_QuantityDropdown
Bought Together Products
http://www.magentocommerce.com/magento-connect/bought-together-products.html
http://connect20.magentocommerce.com/community/CP_BoughtTogether
Dashboard Reviews
http://www.magentocommerce.com/magento-connect/dashboard-reviews.html
http://connect20.magentocommerce.com/community/Clockworkgeek_DashboardReviews
Also Viewed Products
https://github.com/vovayatsyuk/magento-alsoviewed
http://www.magentocommerce.com/magento-connect/also-viewed-products.html
http://connect20.magentocommerce.com/community/alsoviewed
Price layout extension
http://www.magentocommerce.com/magento-connect/price-layout-extension.html
http://connect20.magentocommerce.com/community/wp_price_decimal

Ngx_Pagespeed setting

add_head
combine_css
combine_javascript
convert_meta_tags
extend_cache
fallback_rewrite_css_urls
flatten_css_imports
inline_css
inline_import_to_link
inline_javascript
rewrite_css
rewrite_images
rewrite_javascript
rewrite_style_attributes_with_url

pagespeed EnableFilters defer_javascript; => 有這行才會Combine css and js
pagespeed EnableFilters lazyload_images; => 有這行才會Combine css and js

The Listed Product ids [‘395 No Variant Ids Found!!!’, ‘245 No Variant Ids Found!!!’, ‘244 No Variant Ids Found!!!’, ’91 No Variant Ids Found!!!’] has been sucessfully updated to Magento.
The Listed Product ids [“6118<Fault 101: ‘Product not exists.’>”, “2175<Fault 101: ‘Product not exists.’>”] does not updated on magento.

 

參考資料:

How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

How To Install Magento eCommerce Software In CentOS 7

無堅不摧,唯快不破!快改用 Nginx + PHP-FPM 取代 Apache 吧!

Magento Error 404 after moving from Apache to nginX

nginx + magento unable to edit categories

Table of Contents