[Info] Hướng dẫn cài đặt Magento với Nginx trên CentOS 7

Magento is a very popular open source e-commerce web application. This article will show you how to install Magento with Nginx on a CentOS 7 VPS.

Install Magento with Nginx – Magento is a very popular and feature rich open source e-commerce web application. Magento meets user requirements and allows you to create a fully functional online store in just a few minutes. In this article, HOSTVN will show you how to install Magento on a CentOS 7 VPS with Nginx, PHP-FPM and MariaDB web server.

Install Magento with Nginx on CentOS 7

1. Step 1: Install LEMP (Nginx – MariaDB – PHP)

To install LEMP, follow these instructions: Instructions on how to install LEMP on Centos 7

At the time of writing Magento 2.3 does not support PHP 7.4 so you should only install PHP 7.2 or 7.3

2. Step 2: Create database

For Magento to work, the first thing to do is to create a database for it. To do this, use the following commands in turn

mysql -u root -p
CREATE DATABASE magentodb;
GRANT ALL PRIVILEGES ON magentodb . * TO [email protected]'localhost' IDENTIFIED BY 'YOUR-PASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

Replace YOUR-PASSWORD with the Mysql password you want to create

Screenshot_121 - Installing Magento with Nginx

3. Step 3: Download Magento and install

Replace magentodomain.com with your domain name.

  • Create a folder containing the code

You can create a folder containing Magento code with the following command

mkdir -p /home/magentodomain.com/public_html
cd /home/magentodomain.com/public_html
wget https://github.com/magento/magento2/archive/2.3.tar.gz
tar -xvf 2.3.tar.gz

Move the unzipped source code out public_html

mv magento2-2.3/{.,}* /home/magentodomain.com/public_html

Import A and press Enter when asked

Screenshot_120

Delete unnecessary folders

rm -rf 2.3.tar.gz magento2-2.3

Install the necessary libraries with composer. If your VPS is not installed composer see Tutorial on how to install Composer on CentOS 7.

composer install

After the installation of the library is completed, install Magento with the following command

bin/magento setup:install --backend-frontname="adminlogin" \
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentouser" \
--db-password="MYSQL-PASSWORD" \
--language="en_US" \
--currency="USD" \
--timezone="Asia/Ho_Chi_Minh" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="http://magentodomain.com" \
--base-url-secure="https://magentodomain.com" \
--admin-user=adminuser \
--admin-password=STRONG-PASSWORD \
[email protected] \
--admin-firstname=admin \
--admin-lastname=user \
--cleanup-database

You need to change the information in the command as follows:

  • –backend-frontname: Admin login link you want (Example: https://magentodomain.com/adminlogin)
  • key: Replace with any string of characters
  • db-name, db-user, db-password: Replace with the information you created in Step 2: Create database
  • magentodomain.com : Replace with your domain
  • admin-user, admin-password: Replace with the admin login information you want to create. Note that the password must be over 8 characters including uppercase, lowercase and numbers
  • admin-email, admin-firstname, admin-lastname: Replace with your information

After the installation is complete, proceed to set the owner to avoid permission errors

chown -R nginx:nginx /home/magentodomain.com/public_html

4. Step 4: Create VirtualHost

Create file /etc/nginx/conf.d/magentodomain.com.conf

nano /etc/nginx/conf.d/magentodomain.com.conf

Paste the content below

upstream fastcgi_backend {
    server   unix:/var/run/php-fpm.sock;
}

server {
    listen 80;
    server_name www.magentoodomain.com magentodomain.com;
    set $MAGE_ROOT /home/magentodomain.com/public_html;
    set $MAGE_DEBUG_SHOW_ARGS 1;

    root $MAGE_ROOT/pub;

    index index.html index.htm index.php;
    autoindex off;
    charset UTF-8;
    error_page 404 403 = /errors/404.php;
    #add_header "X-UA-Compatible" "IE=Edge";


    # Deny access to sensitive files
    location /.user.ini {
        deny all;
    }

    # PHP entry point for setup application
    location ~* ^/setup($|/) {
        root $MAGE_ROOT;
        location ~ ^/setup/index.php {
            fastcgi_pass   fastcgi_backend;

            fastcgi_param  PHP_FLAG  "session.auto_start=off n suhosin.session.cryptua=off";
            fastcgi_param  PHP_VALUE "memory_limit=756M n max_execution_time=600";
            fastcgi_read_timeout 600s;
            fastcgi_connect_timeout 600s;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ ^/setup/(?!pub/). {
            deny all;
        }

        location ~ ^/setup/pub/ {
            add_header X-Frame-Options "SAMEORIGIN";
        }
    }

    # PHP entry point for update application
    location ~* ^/update($|/) {
        root $MAGE_ROOT;

        location ~ ^/update/index.php {
            fastcgi_split_path_info ^(/update/index.php)(/.+)$;
            fastcgi_pass   fastcgi_backend;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO        $fastcgi_path_info;
            include        fastcgi_params;
        }

        # Deny everything but index.php
        location ~ ^/update/(?!pub/). {
            deny all;
        }

        location ~ ^/update/pub/ {
            add_header X-Frame-Options "SAMEORIGIN";
        }
    }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location /pub/ {
        location ~ ^/pub/media/(downloadable|customer|import|custom_options|theme_customization/.*.xml) {
            deny all;
        }
        alias $MAGE_ROOT/pub/;
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /static/ {
        # Uncomment the following line in production mode
        # expires max;

        # Remove signature of the static files that is used to overcome the browser cache
        location ~ ^/static/version {
            rewrite ^/static/(versiond*/)?(.*)$ /static/$2 last;
        }

        location ~* .(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$ {
            add_header Cache-Control "public";
            add_header X-Frame-Options "SAMEORIGIN";
            expires +1y;

            if (!-f $request_filename) {
                rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
            }
        }
        location ~* .(zip|gz|gzip|bz2|csv|xml)$ {
            add_header Cache-Control "no-store";
            add_header X-Frame-Options "SAMEORIGIN";
            expires    off;

            if (!-f $request_filename) {
               rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
            }
        }
        if (!-f $request_filename) {
            rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
        }
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /media/ {
        try_files $uri $uri/ /get.php$is_args$args;

        location ~ ^/media/theme_customization/.*.xml {
            deny all;
        }

        location ~* .(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
            add_header Cache-Control "public";
            add_header X-Frame-Options "SAMEORIGIN";
            expires +1y;
            try_files $uri $uri/ /get.php$is_args$args;
        }
        location ~* .(zip|gz|gzip|bz2|csv|xml)$ {
            add_header Cache-Control "no-store";
            add_header X-Frame-Options "SAMEORIGIN";
            expires    off;
            try_files $uri $uri/ /get.php$is_args$args;
        }
        add_header X-Frame-Options "SAMEORIGIN";
    }

    location /media/customer/ {
        deny all;
    }

    location /media/downloadable/ {
        deny all;
    }

    location /media/import/ {
        deny all;
    }

    location /media/custom_options/ {
        deny all;
    }

    location /errors/ {
        location ~* .xml$ {
            deny all;
        }
    }

    # PHP entry point for main application
    location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check).php$ {
        try_files $uri =404;
        fastcgi_pass   fastcgi_backend;
        fastcgi_buffers 1024 4k;

        fastcgi_param  PHP_FLAG  "session.auto_start=off n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=756M n max_execution_time=18000";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # Banned locations (only reached if the earlier PHP entry point regexes don't match)
    location ~* (.php$|.phtml$|.htaccess$|.git) {
        deny all;
    }
}

Press Ctrl + o and press Enter to save files, Ctrl + x to get rid of nano. Restart Nginx to load the configuration

service nginx restart

5. Search

Once completed, you can access your domain name with a web browser to check.

Screenshot_138

6. Conclusion

Through this post HOSTVN I showed you how to install Magento on a CentOS 7 VPS with Nginx, PHP-FPM and MariaDB web server. If you have any suggestions, you can leave a comment below. In addition, you can see more Instructions for installing Laravel on CentOS 7.

Viết một bình luận

bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
antalya bayan escort
antalya bayan escort
antalya bayan escort