Learn How to Install Shopware 6 with NGINX

Learn How to Install Shopware 6 with NGINX

Shopware is one of the best free and open-source platforms that helps you to start your own e-commerce website. It provides you useful tools to help you build and customize a fully responsive and functional online store in a matter of a few minutes. We have all heard about other ecommerce platforms such as Magento, BigCommerce and WooCommerce but like other platforms, Shopware is powerful, easy-to-use, and a flexible application with an ever growing open source community. It has an intuitive interface which makes it easier to create and manage content and products and on top of that, it is super quick.

While Shopware support is not officially available on Nginx but in this tutorial, we will show you how to install Shopware with Nginx and have it up and running in a matter of few mins.

Prerequisites:

  • A development server running PHP7.3 (or higher), MySQL and Nginx.
  • A valid domain name or a local host file override
  • Full root level access to your server.

Installation

Download Shopware

Let’s suppose you are using a local domain i.e. local.shopware.com and updated your OS hosts file with the domain name to point to your local server i.e. 127.0.0.1.

For us to install shopware, first we will create an installation directory on your local server:

mkdir /var/www/htdocs/local.shopware.com

Next, download the Shopware with the following command:

wget https://www.shopware.com/en/Download/redirect/version/sw6/file/install_v6.3.5.0_ba08dbfc07784b5cefe7837f2abbda69dbf5b8b7.zip -O shopware.zip

Once the download is complete, unzip shopware.zip to the shopware directory:

unzip shopware.zip -d /var/www/htdocs/local.shopware.com

Next, set proper permission and ownership with the following command:

chown -R root:root /var/www/htdocs/local.shopware.com
chmod -R 775 /var/www/htdocs/local.shopware.com

NOTE: We have set ROOT as the directory owner purely because it is a local installation. Please do not set ROOT as the file owner on your live production or development environment.

Create a Database for Shopware

You can either create a new database using the shopware installation wizard or do it beforehand using the following commands:

First, connect to the MySQL server using the following command:

mysql -uroot -p -hlocalhost

Once connected, create a database and user with the following command:

MySQL [(none)]> CREATE DATABASE shopware;
MySQL [(none)]> GRANT ALL ON shopware.* TO 'shopware' IDENTIFIED BY 'password';
MySQL [(none)]> FLUSH PRIVILEGES;
MySQL [(none)]> EXIT;

Once you are finished, you can proceed to the next step to configure Nginx.

Configure Nginx for Shopware

Shopware entry point is in its public directory so you will need to create an Nginx virtual host file for Shopware with the following command:

nano /etc/nginx/conf.d/shopware.conf

And add the following block:

server {
    listen 80;

    # Handle / to index.php
    index index.php;

    # Our server name
    server_name local.shopware.com;

    # Where the code is located
    root /var/www/htdocs/local.shopware.com/public;

    # Needed for Shopware install / update
    location /recovery/install {
        index index.php;
        try_files $uri /recovery/install/index.php$is_args$args;
    }

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

    # Forward any not found file to index.php. Also allows to have beautiful urls like /homemade-products/
    location / {
        try_files $uri /index.php$is_args$args;
    }

    # Let php-fpm handle .php files
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi.conf;
        fastcgi_param HTTP_PROXY "";
        fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_read_timeout 300s;
        client_body_buffer_size 128k;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        http2_push_preload on;
    }
}

Finally, save the file and restart Nginx.

Access Your Local Shopware Website

We will now complete final step of the installation using the web installation wizard.

So, open your web browser and type the URL http://local.shopware.com.

Select your language and click on the Next button. Make sure all the requirements have been met then click on the Next button. You should see the following page:

Agree to the GTC and click on the Next button to head to the Database configuration section:

Provide your database, username, password and click on the Start installation button and follow the steps to complete the configuration.

Once you have completed the installation wizard and shopware installed, you will be redirected to the dashboard. That’s all!

Learn how to install Magento 2.4.2 on a docker instance

Learn how to install Magento 2.4.2 on a docker instance

We will be using MGT Commerce’s Docker container to install the latest version of Magento 2.4.2.

If you haven’t setup the MGT Commerce’s Docker image then you can simply run the following command to set one up on your local:

docker run -d --net=bridge -v /var/lib/mysql -v /home/cloudpanel --restart=always --privileged -h mgt-dev --name mgt-dev -it -p 80:80 -p 443:443 -p 8443:8443 -p 22:22 -p 3306:3306 -p 9200:9200 -p 15672:15672 mgtcommerce/mgt-dev:v2

Once the image is installed, you will need to go to https://127.0.0.1:8443/ as that’s where the docker image is installed.

Next, click on the Add Domain button to add a new local domain to install your Magento:

Important: Magento has removed the root index.php in Magento 2.4.2 and moved it to the ./pub directory so you will need to add ./pub to your document root as shown in the image above. 

Once the domain is setup, you will need to create a database which you can create by clicking on the Databases link from the left hand menu.

Next, it is now time to download Magento on your local server but first you will need to login to the MGT Commerce’s Docker Image.

Open terminal and ssh using the following details:

FTP HOST: 127.0.0.1:22

USERNAME: root

PASSWORD: root

.. then navigate to the htdocs directory i.e.cd htdocs/playground.magento.com/

Finally, run the following to download Magento to the site root:

php7.4 /usr/local/bin/composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition playground.magento.com

This should download Magento and finally install it using the following command:

php7.4 bin/magento setup:install --backend-frontname='admin' --key='18Av6ITivOZG3gwY1DhMDWtlLfx1spLP' --session-save='files' --db-host='127.0.0.1' --db-name='playground' --db-user='root' --db-password='root' --base-url='https://playground.magento.com/' --base-url-secure='https://playground.magento.com/' --admin-user='admin' --admin-password='!admin123!' --admin-email='john@doe.com' --admin-firstname='John' --admin-lastname='Doe'

Once the installation is complete, you should be able to access Magento on https://playground.magento.com/ (but remember you will need to add this entry in your hosts file to access the site). 

Setup Magento 2 on Docker with elasticsearch in less than 2 mins!

Setup Magento 2 on Docker with elasticsearch in less than 2 mins!

I’m sure you’ll agree that Magento is a very resource heavy software and requires a stable setup to run it smoothly. We’ve all been in a situation where we’ve complained how slow the Magento system is to run locally but what if I told you there is a docker setup for Magento which is ready to use and only requires one command to have your environment ready? Yes only command!

In my early days as a Magento developer, I’d marry with a fact that we should never rely on a local WAMP/XAMP setup to run Magento and I was introduced to Docker but that being said, there were so many Magento instances to choose from. Some required custom integrations/plugins and some were not good enough to use.

I then stumbled upon a ready-to-use Docker cloundpanel instance which was purely focused on providing developers with a stable Magento development setup in one step, and the step was to install the Docker image locally and viola you have a cloudpanel quite similar to CPanel which allows us to create/list multiple development domains and it was packaged with Elasticsearch, MySQL and Varnish to support Magento.

The Docker instance I’m referring to is create by MGT-Commerce which is a Magento cloud hosting providers. I’ve detailed the steps below to install and setup a Magento development domain.

The MGT Docker image comes in all stable version of PHP starting from PHP 7.0 up to PHP 7.4. You can pick and choose the PHP image you need and even you can run multiple instances at the same time (just ensure each instance has a unique port).

Since Magento 2.4 is now our and ready to use so let’s setup a PHP 7.3 instance and install Magento.

First, we need to install the PHP 7.4 image and to do that, run the following command in your Docker CLI.

Install PHP 7.3 Docker Image

docker run -d --net=bridge -v /var/lib/mysql --restart=always --privileged -h mgt-dev-73 --name mgt-dev-73 -it -p 80:80 -p 443:443 -p 22:22 -p 3306:3306 -p 3333:3333 -p 9200:9200 mgtcommerce/mgt-development-environment-7.3

Once the image is installed, you can access it at http://127.0.0.1:3333/ and the panel should look similar to the following image:

Cloudpanel to setup development domains

Install Magento 2.4 on Docker

First, we need a domain to setup/install Magento 2. Simply click on Add New to create a domain space and click Create Domain.

Next, we need to setup a MySQL database to install Magento so simply click on Databases from the left nav panel and click Add New.

Now, we should have a database ready to install Magento, a domain name and a web/disc space created in our Docker container to install Magento.

You can also access the website root via SFTP or SSH.

To connect, simply use the following:

FTP HOST: 127.0.0.1:22

USERNAME: root

PASSWORD: root

DOCUMENT ROOT: /home/cloudpanel/htdocs/local.magento.com

Finally, simply download the Magento 2.4 composer file or the whole package from their GIT repo and upload to the directory specified above. Once done, connect to the server using SSH and you can safe run the Magento installation commands to install Magento.

That’s all! No rocket science!

Do you have any questions or feedback? Please let me know in the comments!

Solved: Getting TypeError: $.widget is not a function Magento 2 and customers cannot checkout

Solved: Getting TypeError: $.widget is not a function Magento 2 and customers cannot checkout

Recently, one of our clients started to get $.widget is not a function JS error on their Magento 2 store and as a result, customers weren’t able to complete their checkout.

The error was present on Minicart, Product view page, and Checkout page and even changing to default Magento 2 template did not fix the issue.  Eventually, I found that the issue was with Magento JS merging and I was able to fix the issue by making the following changes:

Merge all javascript files:

In Backend go to:

Stores -> Configuration -> Advanced -> Developer -> JavaScript Settings

Activate:

  • Enable JavaScript Bundling
  • Merge JavaScript Files
  • Minify JavaScript Files (Optional)

Deploy the static files

bin/magento setup:static-content:deploy

Clear cache under System -> Cache Management

  • In Additional Cache Management region choose the Button Flush CSS/Javascript Cache
  • And Flush Magento Cache afterwards

Now clear Cache in Browser and reload. Everything should be back to normal now. 

Solved: Learn how to fix 500 Internal Server Error on Magento 2.2.2

Solved: Learn how to fix 500 Internal Server Error on Magento 2.2.2

I’ve used Magento v2.1.x for a while and then decided to give Magento v2.2.2 a try because why not, upgrading the tech stack is always good, isn’t it?

As usual, I opted in for CLI based installation and Magento was installed successfully, however, I was served a 500 Internal Server Error whenever I tried to access the website.

I’ve learnt from my experience is this error usually occurs when something is wrong with .htaccess file and that’s where I looked for this fix as well.

I removed .htaccess file and the site was back online, however, it still didn’t work properly. I then added the .htaccess file back and the error came up again.

I also looked at the server error log but there wasn’t much information available. Eventually, I decided to play around with apache modules and noticed that mod_version was disabled. I activated mod_version, restarted apache service and hello world, the site was back online.

So in a nutshell: 

  1. Check webserver modules – in my case, the problem was with mod_version as it was disabled. Enabling it fixed the issue.
  2. Enable/Disable your htaccess file to see if it resolves your issue
  3. Disable third-party extensions one by one to troubleshoot
  4. If the issue persists, visit the Magento community forums and post your issue there.  

Let me know if mod_version fixed your issue :)

Happy coding.