8. Feb 2022 |

How to install Magento on local nginx

Not a tutorial but notes for myself

Creating vitual host (tutorial), user rights in /var/www/ (rights to group, user to group) and here even better guidance.

Before Magento I usually set up default WordPress installation first to test if php works well, database is ok and nginx has started.

Useful command: sudo mv wordpress/* /var/www/html – how to move content of whole directory somewhere

Order of Magento installation

As it is in the documentation. But you can be sure something goes wrong.

  1. Composer create-project to get the metapackage: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento/
  2. Permissions, also sudo chown -R rbrt:www-data .  It is occasionally needed later too.
  3. php bin/magento install... (this is very long command you can find here)*
  4. If you need then you can also install sample data: php bin/magento sampledata:deploy (takes very long time) and you may also need to run php bin/magento catalog:images:resize to get the images shown in the store.

Clean Magento install with sample data is 1.4 GB, 109 thousand files (so creating and deleting may take long time), 410 database tables. For comparison, clean WordPress is just 12 tables.

*For this step you need ElasticSearch running. sudo systemctl start elasticsearchInstructions can be found here on Digital Ocean website.

Nginx conf

/etc/nginx/ -> nginx.conf

Restart: sudo systemctl reload nginx

Get ownership
sudo chown -R robert /var/www/html
Give ownership back to the webserver system user www-data.
sudo chown -R www-data:www-data /var/www/html

Conf

Create .conf to /etc/nginx/sites-available

Symlink conf to sites-enabled

sudo ln -s /etc/nginx/sites-available/abc.conf /etc/nginx/sites-enabled/

Symlinked conf updates itself automatically

Add custom domain to hosts file

sudo code /etc/hosts --user-data-dir

Rights

This did not work well…

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/www

Set file permissions before Magento installation

https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions – but I am not shure what the before means.

Disable 2FA

php bin/magento module:disable Magento_TwoFactorAuth

Because otherwise you can not log into admin (because mail server does not work)

Post installation commands

php bin/magento setup:di:compile
php bin/magento indexer:reindex or php bin/magento indexer:status
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento module:disable Magento_Csp
php bin/magento module:disable Magento_TwoFactorAuth

Leave a Reply

Your email address will not be published. Required fields are marked *