Simplifying Workflows, Maximizing Impact

Call at: 07850 074505

I have worked with Magento since 2009. Installing Magento has always had its quirks, primarily because the web stack for it continually evolves. This means that any installation guide you find online will likely need to be adjusted over time. However, there are some common steps and useful tips that remain relevant, which I will share in this article.

The setup described below is intended for a development environment. Therefore, I use weak passwords, localhost, and do not mention compilation or Varnish.

Steps for Setting Up Magento in a Development Environment:

By following these steps, you can create a functional development environment for Magento.

Composer Install

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-20-04

For recent versions of Magento, using composer 2.x is needed.
The error below is a symptom that composer uses composer 1.x
PHP Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/bin/composer/vendor/symfony/console/Helper/HelperSet.php on line 112

Install Lamp Stack

https://www.digitalocean.com/community/tutorials/how-to-install-lamp-stack-on-ubuntu

I tend to use digitalocean to get my web stack setup. However, depending on our environment, we may want to check we run the right version of php. For my environment, the command below was useful to ensure php8.3 is used:
sudo update-alternatives --set php /usr/bin/php8.3
The next hurdle with regards to php setup, Magento needs various php extensions.

sudo apt install php8.3 php8.3-curl php8.3-intl php8.3-zip php8.3-bcmath php8.3-gd php8.3-soap php8.3-mysql php8.3-xdebug libapache2-mod-php8.3 php8.3-xml php8.3-mbstring php8.3-common php8.3-cli

Install Magento

It seems the easiest way to have opensearch to work locally is by using a docker image.
https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/
Following the article from Experience League is the way forward:
https://experienceleague.adobe.com/en/docs/commerce-operations/installation-guide/composer
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7 magentodemo247

The command above will need Magento access keys to be set:
https://commercemarketplace.adobe.com/customer/accessKeys/
bin/magento setup:install \ --backend-frontname=admin \ --db-host=localhost \ --db-name=magentodemo247 \ --db-user=magentodemo247_user \ --db-password=passw0rd \ --base-url=http://magentodemo247.co.uk/ \ --use-rewrites=1 \ --admin-user=admin \ --admin-password=passw0rd \ --admin-email=info@digitalrisedorset.co.uk \ --admin-firstname=Admin \ --admin-lastname=Admin \ --cleanup-database \ --language=en_GB \ --currency=GBP \ --timezone=Europe/London \ --search-engine=opensearch \ --opensearch-host=127.0.0.7 \ --opensearch-username=admin \ --opensearch-password=yourStrongPassword123! \ --opensearch-enable-auth=1 \ --opensearch-port=9200 \ --opensearch-index-prefix=magento2 \ --opensearch-timeout=15

Disable 2FA as this is a local development environment

bin/magento mod:dis Magento_TwoFactorAuth Magento_AdminAdobeImsTwoFactorAuth

Finally, set the mode in developer mode
bin/magento depl:mode:set developer
The below is for the permissions. I use consistently the recommendations from experience league
sudo usermod -a -G <web server group> <user>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :<web server group> .

Finally install the sample data

https://github.com/magento/magento2-sample-data

I have installed the sample data using a symlink method today.
Adding the sample data in a custom folder at the root of Magento. This method is documented at https://github.com/magento/magento2-sample-data. Once the symlinks are created,
php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"
bin/magento setup:upgrade
then ensure the files ownership and permissions for the sample data modules allow the webserver to use them