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

Setting up Magento Local Development in openSUSE

Screenshot_20180301_103321

Finally, I managed to install Magento in my local environment of openSUSE. It’s quite tricky to get it up and running. It’s mainly due to filesystem permissions issue, as well as Apache virtual host configuration. I don’t have many experience with Apache, so it took more time to configure the virtual host. Because I prefer LEMP stack, and since a couple of months ago, I use Docker for local development environment instead.

Actually, I have successfully installed it in Fedora as well. But, I delete the installation due to the low disk capacity. The overall steps I did to eventually get Magento served in my localhost are:

  1. Downloading Magento from its official website, and I had to log in first, I downloaded the latest version (2.3)
  2. Installing the prerequisites as described in Magento dev docs, I got a little trouble to fulfill the minimum requirements, i.e. PHP version and extensions. openSUSE Tumbleweed has PHP v 7.2 in the main repo, but Magento didn’t support this version, so I used other repo to install v 7.1. But the issue hasn’t stopped, as that repo didn’t have php-mcrypt package. So I had to download the RPM from somewhere (likely rpmfind.net) which had the nearly compatible version.
  3. Configuring Apache in localhost, where I struggled to get the right configuration
  4. Extracting the Magento tarball and setting filesystem permissions. Actually this step was the hardest phase, although I had followed the instruction from official Magento website.
  5. Running the installation step. Since I didn’t get the right configuration of filesystem permissions, so that the front end installer didn’t show up, I used the Magento command line installer module instead. It’s quite tricky as well, actually. But it worked.
  6. Setting up PHP session directory permission manually. As I put the Magento source files in my home partition, and Apache run as wwwrun user, it cannot access the PHP session directory to write a new session. Actually Magento can make use of other session handler system like memcached and redis, but I didn’t find the corresponding packages in the custom zypper repo I mentioned before.

This is the final result of the installation of Magento in my openSUSE.

Magento dashboard

Screenshot_20180301_223633

my command line history

Get notified when Woocommerce payment received

I’ll show you how to get notification when there’s a new completed payment in your Woocommerce website. You’ll be using Slack for this, since it’s free and you can get the notification right away on your phone if you install the app.

First thing first, you need to install some WordPress plugins and create a Slack channel. The plugins are Slack (unofficial) and Slack Woocommerce (kind of extension of the first one). Once you activate those plugins, you have a setting page for adding new Slack integration. But before that, you need to create a custom integration in your Slack channel.

Once you create your workspace and login to it, add an app from <your-workspace>.slack.com/apps. Search for “Incoming Webhook”, and click Add Configuration button. You may need creating a new channel instead of #general for this Custom integration.

slack incoming webhook

Follow along the step to create a webhook, and you’ll get a hook URL. Copy that URL to paste it to the Slack Woocommerce configuration on your website. See below: (the URL format may differs from what it suggested)

woocommerce notification with slack

You can test that configuration by clicking test button below. And if you get a new message in your Slack channel, then the setup is done. To get the push notification on your phone, install Slack app and login to it.

Don’t forget to tick the option “When a payment in Woocommerce marked as complete” in the Events to Notify section. Note that the event it handles is ​woocommerce_order_status_completed that means you may need a kind of automatic payment confirmation. For instance if you have only bank transfer payment option.

My Very First Hacktoberfest Experience

Two months earlier, DigitalOcean –collaborated with Github– held the Hacktoberfest event. It’s a month-long celebration of open source software, which was held on October –every year. Every Github user could join the party. If you have account, then the first thing to do was signing up to the event. After that, you must make four pull requests to any Github repositories / projects –preferably which had “hacktoberfest” label in the issue page of repo though. Just it. And then… you are eligible to get swag from DigitalOcean.

By the end of October last year, there were 31,901 completed challenges made by people around the world, including me. And as other people participated the event, I receive the swag. I like it so much. It’s a kind of perfect gift for the new year! I don’t have to thank them, do I? 😀 As I have posted it on both Twitter and Instagram:

Hacking React Native!

My acquaintance encouraged (or maybe challenged) me to try React Native for developing Android app. Should I endorse you here, kang Chip? 😀  Actually he has told me about React Native a year ago. And by then, I have bought a React Native ebook as well. But, unfortunately, I had so many buts. 😀

I have quite forgot about React Native right now. In additions, a few months ago, there’s been a discourse about its license. It made me discouraged to learn it more. But now, I have set a historical step, by creating a new –dummy– React Native project. These are the screenshots:

Screenshot_20171109_221212

Screenshot_20171109-221208

Oops, that’s error

The most exciting part is: I can code it by Vim! Some kind of killing two birds with one stone! Yeah, I can learn both Vim and React Native at once. It’s not multitasking, but eficiency. 😀

Installing Openshift Origin on Digitalocean Droplet

Lately I wondered why my websites as well as the backend for my app (also available for Android) were so slow that the app was hardly usable. By wondering, I mean, I did’t get it, what’s happened in the underlying service, Openshift Online Starter v3. Actually I knew the cause, which was made by myself though. 😀

I was experimenting with SSL setup in the routes settings of Openshift project configuration page. There are 3 options for the secure route, Edge Termination, Passthrough Termination, Re-encrypt Termination, which are described on the official documentation page here. I have played with all those options, and the results were very very slow download speed, or maybe just the TTL. I had secure route to be activated for one of my subdomain need SSL, which was then to be paired with Full SSL option in CloudFlare. Yeah, I make use of it for the DNS server anyway. And as for SSL certificates for the Openshift route, I obtained it from Cloudflare’s. So, it’s obvious that there was a communication issue between them, particularly at SSL handshake session. Although, according to a comment for my question on Stackoverflow, he said that it’s a known issue on Openshift itself.

So, rather than disabling SSL for the sake of website speed, I was planning to move the data to traditional hosting, or VPS. I tended to choose the latter, as I have enough credit in Digitalocean right now. But, as I quite lazy to setup production server on a bare VPS, and my project was customized for Openshift, I’d rather searching for how to setup Openshift Origin on DigitalOcean. In the first run, I set up a Fedora Atomic droplet, that actually I didn’t understand what it was. 😀 Thanks to buddies on @FedoraID telegram group, I quite enlightened about it now. 🙂

Eventually, I found a thorough tutorial how to setup Openshift Origin on VPS. So, here I just want to share some screenshots of my success on setting it up. 🙂 FYI, it only took 2 hours for me to play around with it on Digitalocean droplet, as I realized that a 512 MB droplet would not sufficient to run Openshift service in it, as it encountered sudden stop so often due to the lack of memory.

Screenshot_20171102_005657Screenshot_20171102_015009

Screenshot_20171102_020825

Low resource (memory) on a half gig droplet

 

Removing Expiration Date of Oracle Express Database

oracle_sqlplus

I currently work on a project that uses Oracle database. For the local development, I installed it with Docker. I’ve found a handy docker file of Oracle Database Express Edition 11g published by wnameless in Github or in the official page in Docker Hub.

It’s so easy to use, that I just need to type sudo docker start oracle to get it up and running. Of course by reading the Readme first.

But then I noticed an error: ORA-28002: the password will expire within 7 days. Although it doesn’t affect the app, I feel a bit annoyed. So I googled it, and found the solution afterward. But I lost the URL. My bad!

Just take a look at above picture. I won’t type in the command here, as you can found it somewhere in Stackoverflow, actually. 😀