CentOS 7: Magento 2.1 / NGINX / PHP 7 /PHP-FPM

Home » Uncategorized » CentOS 7: Magento 2.1 / NGINX / PHP 7 /PHP-FPM
Uncategorized No Comments

Well this was a bugger, mainly because I fart arsed about setting up NGINX/PHP-FPM individual pools on a UAT box using a script I found on that there “internet”. To be fair it is a good script, but I was too lazy for my own good and didn’t debug well. Here it is.

Moral of the story though, be lazy, don’t re-invent the wheel until you have too. The of course write it down so you don’t have to work hard a second time. Ok, so…
1) Get your LEMP sorted.
2) Grab the Seb Dangerfield scripts. You look at the site it’s cool, better than this shower of shyte, I’ll just be copying and pasting the crap below though

wget http://www.sebdangerfield.me.uk/wp-content/uploads/2012/05/create_php_vhost.tar.gz
tar zxvf create_php_vhost.tar.gz

You’ll need to edit (create_php_site.sh) the script a bit for you own shizzle, and for centOS. I dropped in.

# Modify the following to match your system
NGINX_CONFIG='/etc/nginx/sites-available'
NGINX_SITES_ENABLED='/etc/nginx/conf.d'
PHP_INI_DIR='/etc/php-fpm.d'
WEB_SERVER_GROUP='nginx'
NGINX_INIT='systemctl restart'
PHP_FPM_INIT='systemctl restart'
PASSWD="$(openssl rand -base64 12)"

and because I can’t be arsed with setting a password, bastardised it with this:
read USERNAME
HOME_DIR=$USERNAME
adduser $USERNAME
echo $PASSWD | passwd --stdin $USERNAME

I changed the PUBLIC_HTML_DIR because I prefer this to be the domain name:

echo "Would you like to change to web root directory (y/n)?"
read CHANGEROOT
if [ $CHANGEROOT == "y" ]; then
echo "Enter the new web root dir (after the public_html/)"
read DIR
PUBLIC_HTML_DIR='/public_html/'$DIR
else
PUBLIC_HTML_DIR='/'$DOMAIN
fi

I also dropped in a quick php info because it’s the first thing we all do don’t we, we’re paranoid this shit actually works, we are just winging it like.

echo -e "\nSite Created for $DOMAIN with PHP support"
echo -e '' > /home/$HOME_DIR$PUBLIC_HTML_DIR/info.php
curl -I http://$PUBLIC_HTML_DIR/info.php ; sleep 1

Oh the password if you want to know it for like, SSH or FTP
echo $PASSWD > /insecure/place/so/you/better/delete/.$HOME_DIR.pass

3) Download Magento and log in as your user (su - youruser) and extract it.

4) Nagigate to yourdomain.com/setup/

5) Boom!! Doesn’t work does it.

6) Probably missing some important modules, this from their docs should sort that right out..
yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel php70u-mysql php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv
systemctl restart php-fpm
systemctl restart nginx

7) Nope still no, I can click that ‘Readiness Check’ but it doesn’t even see PHP (YOU’RE LOAD A PHP PAGE GRRR)

8) I basically fannied around for ages because looking at the nginx config, ended up find that it should look a little like this (restart after change):

upstream fastcgi_backend {
server server unix:/var/run/my_user_fpm.sock;
}

server {

listen 80;
server_name your_domain.com;
set $MAGE_ROOT /path/to/webdir;
set $MAGE_MODE developer;
# set $MAGE_MODE default;
# set $MAGE_MODE production;

include /path/to/webdir/nginx.conf.sample;
}

9) Yeah still no.

10) Turns out it was only the bloomin’ “listen.owner” / “listen.group” in my fpm pool! changed it from user to nginx, fixed!
[my_pool]
user = my_user
group = my_user
listen = /var/run/my_user_fpm.sock
listen.owner = nginx
listen.group = nginx
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
catch_workers_output = 1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /