Migrate and install Magento 2.3.2 on Ubuntu 18.04 Server

Passionaute
4 min readMay 6, 2021

--

Setup Magento 2.3.2 on Ubuntu 18.04

I assume you have the backups from your Magento 2 instance that you want to migrate. You should have these 3 files.

  • Database: 1620165604_db.sql
  • Source Code: 1620165604_filesystem_code.tgz
  • Medias: 1620165604_filesystem_media.tgz

If you want to know how to back up your Magento 2 installation, have a look here [LINK_TO_BE_PROVIDED]

I also assume that you just freshly installed Ubuntu Server 18.04.

Let’s go!

To prevent future problems, update and upgrade your operating system to make sure you have the latest security and software fixes.

Run the following commands with root privileges

$ apt-get update$ apt-get upgrade

Install Nginx

$ apt-get -y install nginx

Install and configure php-fpm

$ apt-get -y install php7.2-fpm php7.2-cli

Open php configuration files using vi:

$ vi /etc/php/7.2/fpm/php.ini
$ vi /etc/php/7.2/cli/php.ini

Edit both files to match the following lines:

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

Restart the service

$ systemctl restart php7.2-fpm

Make sure it’s running

$ systemctl status php7.2-fpm● php7.2-fpm.service — The PHP 7.2 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021–05–05 18:53:54 UTC; 12s ago
Docs: man:php-fpm7.2(8)
Main PID: 25232 (php-fpm7.2)
Status: “Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec”
Tasks: 3 (limit: 2361)
CGroup: /system.slice/php7.2-fpm.service
├─25232 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
├─25244 php-fpm: pool www
└─25245 php-fpm: pool www
May 05 18:53:54 ubuntu1804 systemd[1]: Starting The PHP 7.2 FastCGI Process Manager…
May 05 18:53:54 ubuntu1804 systemd[1]: Started The PHP 7.2 FastCGI Process Manager.

Install and configure Mysql

$ apt-get install mysql-server

Check if Mysql is running

$ service mysql status● mysql.service — MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021–05–05 18:55:01 UTC; 24s ago
Main PID: 25874 (mysqld)
Tasks: 27 (limit: 2361)
CGroup: /system.slice/mysql.service
└─25874 /usr/sbin/mysqld — daemonize — pid-file=/run/mysqld/mysqld.pid
May 05 18:55:01 ubuntu1804 systemd[1]: Starting MySQL Community Server...
May 05 18:55:01 ubuntu1804 systemd[1]: Started MySQL Community Server.
$ ss -tap | grep mysqlLISTEN 0 80 127.0.0.1:mysql 0.0.0.0:* users ((“mysqld”,pid=25874,fd=30))

Create database

$ mysql -pmysql> CREATE DATABASE magentodatabase;

Create user

mysql> CREATE USER magentodbuser@localhost IDENTIFIED BY 'my_complicated_db_password';

Set access and flush

mysql> GRANT ALL ON magentodatabase.* TO magentodbuser@localhost IDENTIFIED BY 'my_complicated_db_password';mysql> FLUSH PRIVILEGES;

Restore Magento 2 database

$ mysql -p magentodatabase < 1620165604_db.sql

Install Composer (Bonus)

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

Since Composer 2 is not supported by Magento version 2.3.2, you’ll need to downgrade it.

$ composer self-update 1.4.1
$ composer --version
Composer version 1.4.1 2017-03-10 09:29:45

Set up and prepare Magento 2 directory

$ cd /var/www/html
$ mkdir magento2

Go to your Magento 2 directory, retrieve the backups there and untar or unzip them.

$ tar -xvzf 1620165604_filesystem_code.tgz
$ tar -xvzf 1620165604_filesystem_media.tgz

Some folders are not archived during the backup, so you need to create them. I’m not sure if those folders are automatically created after refreshing Magento cache (to be investigated). Just in case, here we go.

$ mkdir var pub/static

Set the right permissions so that the command line can write files to the Magento file system.

$ 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 :www-data .$ chmod u+x bin/magento

We’re almost there, hang on.

PHP modules

We need to check that we have all the PHP modules that Magento 2 needs.

$ php -m

Make sure you have the modules listed here https://devdocs.magento.com/guides/v2.4/install-gde/prereq/php-settings.html#verify-installed-extensions

In my case, I had to install some missing modules

$ apt-get install php-bcmath php-curl php-dom php-gd php-intl php-mbstring php-mysql php-simplexml php-soap php-xsl php-zip

Nginx configuration

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

Add the below configuration

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

server {

listen 80;
server_name mystore.com;
set $MAGE_ROOT /var/www/html/magento2;
include /var/www/html/magento2/nginx.conf.sample;
}

Enable Magento 2 Nginx configuration

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

Test the syntax and restart Nginx

$ nginx -t
$ systemctl restart nginx

Good!

Install Magento 2

We have all we need now to install Magento using the command line.

$ php bin/magento setup:install --base-url=http://mystore.com/ \
--admin-firstname="Firstname" \
--admin-lastname="Lastname" \
--admin-email="my@email.com" \
--admin-user="admin" \
--admin-password="my_admin_password" \
--db-name="magentodatabase" \
--db-host="localhost" \
--db-user="magentodbuser" \
--currency=EUR \
--timezone=Europe/Paris \
--use-rewrites=1 \
--db-password="my_complicated_db_password"

One last step.

Build and refresh Magento 2 cache.

$ php bin/magento setup:static-content:deploy -f
$ php bin/magento setup:static-content:deploy -f fr_FR
$ php bin/magento cache:clean
$ php bin/magento cache:flush

Your Magento 2 shop is ready! http://mystore.com/

Next step! HTTPS => https://passionaute.medium.com/how-to-install-ssl-certificate-and-enable-https-on-magento-2-nginx-ee80dee24618

Sources:

--

--