Setup Magento 2.3.4 Development Environment on Ubuntu

1
4918
Setup Magento 2.3.4 Development Environment on Ubuntu
Setup Magento 2.3.4 Development Environment on Ubuntu

In this tutorial, I will show you how to setup Magento 2.3.4 Development Environment on Ubuntu Linux.

Setup Magento 2.3.4 Development Environment on Ubuntu

This tutorial has been done and works perfectly on Ubuntu 18.04, but it should also work for Ubuntu 16.04 and similar Debian-based Linux distros.

Moreover, in Ubuntu 18.04, you can use apt instead of apt-get, they are basically the same. I will use apt-get in this tutorial, as it is more familiar to Ubuntu users before.

Before installing anything, let’s start by updating all repos to latest.

$ sudo apt-get update

1. Install web server: nginx

First, we need an web server to run Magento PHP code, for that, we will use nginx.

$ sudo apt-get install nginx

2. Install PHP

For Magento 2.3.4 version, specifically, it only allows PHP 7.1~7.3; therefore, we need to install a PHP version in this range. Even though, at the time of this writing, PHP 7.4 is already available, but we should not use it as Magento will verify PHP compatible during installation. Let’s just use PHP 7.3 then.

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update

3. Configure php-fpm for nginx

Now, we need to have php-fpm for nginx to handle PHP request.

$ sudo apt-get install php7.3-fpm php7.3-cli

After that, edit the following two files:

  • /etc/php/7.3/fpm/php.ini
  • /etc/php/7.3/cli/php.ini

and update following values as below:

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

These values are required to install Magento because it consumes a lot of memory and its execution takes a long time to complete. I recommend to config values as above but you can try with different values on your own.

Save the config file and restart php-fpm:

$ sudo systemctl restart php7.3-fpm

4. Install MySQL server

Issue following commands:

$ sudo apt-get install -y mysql-server mysql-client
$ sudo mysql_secure_installation

Next, you should have access to MySQL from terminal:

$ mysql -u root -p

Type the password created during installation, and let’s create a new database and a new user for Magento.

> CREATE DATABASE magento;

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

> FLUSH PRIVILEDGES;

The SQL command above will create a new database magento and assign all privileges for new user magento with password secret. You can change into your own values.

5. Install Composer

We will use Composer to manage Magento dependencies, install it by following command:

$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer

Verifying Composer by using:

$ composer --version

6. Install Magento

We will install Magento into the document root of nginx at /var/www/html using composer.

$ cd /var/www/html
$ 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 /var/www/html/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.

For production, replace --base-url with your domain name.

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

$ php bin/magento deploy:mode:set developer

7. Configure Magento site in nginx

We need to serve Magento in nginx. Create and edit this file:

$ sudo vi /etc/nginx/sites-available/magento

Add following contents:

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

 server {
     listen 80;
     server_name 127.0.0.1;
     set $MAGE_ROOT /var/www/html/magento;
     include /var/www/html/magento/nginx.conf.sample;
 }

Activate it,

$ sudo ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled

Verifying the syntax before restarting nginx.

$ sudo nginx -t

If there is no problem, then restart server by:

$ sudo systemctl 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

If you follow my tutorial step by step thoroughly, you should have a local Magento right now and you know how to setup Magento 2.3.4 Development Environment on Ubuntu Linux. Feel free to ask in comment section below if you have any problem.