Setup Magento 2.3.4 Development Environment on Mac

1
538
Setup Magento 2.3.4 Development Environment on Mac
Setup Magento 2.3.4 Development Environment on Mac

In this tutorial, I will show you how to setup Magento 2.3.4 Development Environment on Mac the easy way using Homebrew.

Setup Magento 2.3.4 Development Environment on Mac

I’m a Mac user and I use Homebrew for package management.

First, make sure to have Homebrew in your Mac first.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

1. Install nginx

We will use nginx as the web server to serve Magento code, install it by following command:

$ brew install nginx

then you can start nginx server by:

$ brew services start nginx

2. Install MariaDB

We need a database for Magento, for that, I will use MariaDB 10.4.11 at the time of this tutorial.

$ brew install mariadb

We also need to create a database, a new user for Magento; so first, access into MariaDB shell client:

$ mysql -u root

If you setup a password already, then add the option -p and type in the password.

Now, in MySQL shell, let’s create a new database:

> CREATE DATABASE magento;

and then, create a new user magento with password secret along with assigning all privileges into magento database created in previous command.

> GRANT ALL PRIVILEGES ON magento.* TO magento@localhost IDENTIFIED BY 'secret';

> FLUSH PRIVILEDGES;

3. Install PHP 7.3

For Magento 2.3.4, it is only compatible with PHP 7.1~7.3; however, if you try to install php with:

$ brew install php

Homebrew will install the latest PHP version, which is PHP 7.4 at the moment, which is not ideal. Therefore, we need to install a prior PHP version, and PHP 7.3 is the best option for now. We install PHP 7.3 by this command:

$ brew install php@7.3

We need to override with default PHP binary on Mac:

$  echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
$  echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc

If you use Bash shell, the replace .zshrc into .bashrc.

Verify it by typing:

$ php -v
PHP 7.3.16 (cli) (built: Mar 19 2020 11:19:09) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.16, Copyright (c) 1999-2018, by Zend Technologies

If your output doesn’t look like mine above, then try setting up PHP again.

4. Configure PHP options

The default PHP options doesn’t work for Magento, we need to do some updates by editing php.ini file:

$ sudo vi /usr/local/etc/php/7.3/php.ini

Update following options:

memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On

upload_max_filesize = 64M 
post_max_size = 128M 
max_input_vars = 3000 
max_input_time = 1000

Save the file and start php-fpm.

$ brew services start php-fpm

5. Install Composer

Composer is PHP package management, we need it to manage Magento dependencies.

Install it by using Homebrew:

$ brew install composer

6. Install Magento

We will install Magento into the document root of nginx at ~/Sites using composer.

$ cd ~/Sites
$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento

After downloading the project, we execute Magento command to setup the project:

$ cd ~/Sites/magento
$ php bin/magento setup:install --base-url=http://127.0.0.1/ --db-host=localhost --db-name=magento --db-user=magento --db-password=secret --admin-firstname=pete --admin-lastname=houston --admin-email=contact@petehouston.com --admin-user=admin --admin-password=secret20 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1

You need to update arguments for the setup command; however, for --use-rewrites , keep its value 1.

For local development environment, --base-url can be 127.0.0.1 or localhost or anything you want to use.

Moreover, to enable development mode for Magento, execute this command:

$ php bin/magento deploy:mode:set developer

7. Configure nginx

We need to map Magento into nginx.

$ vi /usr/local/etc/nginx/sites-enabled/magento.conf

Add following content:

upstream fastcgi_backend {
     server  127.0.0.1:9000;
 }

 server {
     listen 8000;
     server_name 127.0.0.1;
     set $MAGE_ROOT /Users/petehouston/Sites/magento;
     include /Users/petehouston/Sites/magento/nginx.conf.sample;
 }

You need to change values to map with your Mac machine. Then verify the config by:

$ nginx -t

then restart server:

$ brew services restart nginx

8. Verify Magento installation

After all above steps, open web browser, navigate into http://127.0.0.1 to see your Magento up and running.

Conclusion

Congratulation! You have setup Magento 2.3.4 Development Environment on Mac successfully. Feel free to ask me in comment section below if you have any problem.

Good luck ~