Installing Magento 2 on Fedora 29

Last year, I moved to openSUSE, and started tinkering Magento 2. I have posted about the installation of Magento 2 on openSUSE as well. Then, recently, I missed Fedora and installed it back on my Thinkpad. Also, I am still developing Magento 2, so I got a bit struggle in setting it up with nginx in Fedora 29. But it turned out the most time-consuming part was just because of… typo.

Prerequisites

As in the official website said, Magento 2 required PHP up to version 7.1, which still preserves mcrypt extension. Since starting 7.2 it’s considered obsolete and removed due to no more maintained for long time. But, unfortunately the latest version of some Linux distros only provides PHP 7.2 in the main repository, including openSUSE and Fedora.

But no worries, thanks to community’s public repo, you are still able to install PHP 7.1 on them. In this case, I write how to set it up in Fedora 29, along with LEMP stack. So you need to install, at least nginx, mariadb, and php 7.1. As for PHP, we would need Remi’s COPR repo. He is the core contributor of both Fedora and PHP.

  1. Follow along the wizard on https://rpms.remirepo.net/wizard/ where the type of installation is multiple, since the single version is unavailable.
  2. Then, you need to install some packages: nginx mariadb-server php71-php-fpm php71-php-pdo php71-php-mysqlnd php71-php-opcache php71-php-xml php71-php-mcrypt php71-php-gd php71-php-devel php71-php-mysql php71-php-intl php71-php-mbstring php71-php-bcmath php71-php-json php71-php-iconv php71-php-soap php71-php-zip php71-php-cli.
  3. Check whether nginx is running by visiting localhost in your browser.
  4. Also, you need to make soft link of php cli executable /usr/bin/php71 to /usr/bin/php
  5. As for composer, don’t install it from Fedora repo, just download it from the official website instead https://getcomposer.org/download/

Configure nginx Virtualhost / Server Block

Magento has provide the configuration for nginx in the root directory, that is nginx.conf.sample file.

Create an nginx config file in ​/etc/nginx/sites-available/magento for example.

upstream fastcgi_backend {
server unix:/var/opt/remi/php71/run/php-fpm/www.sock;
}

server {
listen 80;
listen [::]:80;
server_name magento.test;
set $MAGE_ROOT /var/www/magento/html; # change as needed
include /var/www/html/magento/nginx.conf.sample;
}

Don’t forget to append magento.test in /etc/hosts at 127.0.0.1 and ::1 lines. Then create /etc/nginx/sites-enabled and make soft link of file above into it. Then you need to add a line in /etc/nginx/nginx.conf before server {} block.

include /etc/nginx/sites-enabled/*;

Test the configuration with sudo nginx -t whether it’s OK or failed. If OK, restart it with systemctl restart nginx.

File and Folder Permissions (and SELinux)

Make user www-data as the runner of nginx and php-fpm. Then add your Fedora user to its group, and edit conf files to adjust the user.

In /etc/opt/remi/php71/php-fpm.d/www.conf edit user, group, listen-user and listen-group to www-data. Also in /etc/nginx/nginx.conf change user to www-data. Restart nginx and php71-php-fpm systemd process. useradd -Mr www-data && usermod -aG <user> www-data then chmod -R :www-data * from Magento root.

Then you need to take into account the SELinux in Fedora, as well as firewall.

semanage permissive -a httpd_t
chcon -R -t httpd_sys_content_t /var/www/html/magento
chcon -R -t httpd_sys_rw_content_t /var/www/html/magento

Bonus: Alternative of Local Sendmail

Download Mailhog from https://github.com/mailhog/MailHog/releases then run it. Then you just need to edit a line in /etc/opt/remi/php71/php-fpm.d/www.conf earlier.

php_admin_value[sendmail_path] = "~/MailHog_linux_amd64 sendmail test@example.org"

Adjust the mailhog path to your own. Restart php-fpm systemd. Or you may need to restart Fedora.

Advertisements

2 thoughts on “Installing Magento 2 on Fedora 29

Share your idea here (markdown enabled)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.