CentOS 7, MariaDB and nginx php-fpm: login issue

Hello everyone!

There’s something strange trying to install playSMS on CentOS 7 (MariaDB 5.5, PHP 5.4), but just using nginx.

This is the steps I’ve followed, it’s just a bash script with manual installation:

#!/bin/bash -eu

# My environment
WEBDIR=/usr/share/nginx/playsms
CONFDIR=/etc
BINDIR=/usr/local/bin
SRCDIR=/usr/local/src

#Disable SELinux
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
setenforce permissive

# Install required dependencies
yum -y install epel-release
yum -y install mariadb-server nginx php-cli php-curl php-fpm php-gd php-imap \
  php-mcrypt php-mysql

# Download playSMS, untar, install composer
cd $SRCDIR
curl -OL http://downloads.sourceforge.net/project/playsms/playsms/Version%201.4/playsms-1.4.tar.gz
tar zxf playsms-1.4.tar.gz && rm -f playsms-1.4.tar.gz
cd $SRCDIR/playsms-1.4
./getcomposer.sh

# Configure MariaDB
systemctl enable mariadb
systemctl start mariadb

mysql -u root <<EOF
DROP USER ''@'localhost';
DROP DATABASE test;
CREATE DATABASE playsms;
GRANT ALL PRIVILEGES ON playsms.* TO playsms@localhost IDENTIFIED BY 'playsms';
FLUSH PRIVILEGES;
EOF

# Install playSMS DB
mysql -u playsms -pplaysms playsms < $SRCDIR/playsms-1.4/db/playsms.sql

# Setup files, folders and permissions
mkdir -p $WEBDIR
mkdir -p /var/{lib,log}/playsms
cp -rf $SRCDIR/playsms-1.4/web/* $WEBDIR
cp -rf $SRCDIR/playsms-1.4/daemon/linux/etc/playsmsd.conf $CONFDIR/playsmsd.conf
cp -rf $SRCDIR/playsms-1.4/daemon/linux/bin/playsmsd.php $BINDIR/playsmsd
chmod +x $BINDIR/playsmsd
chown -R nginx. $WEBDIR
chown -R nginx. /var/{lib,log}/playsms

# Fix playSMS web path
sed -i "s@PLAYSMS_PATH=\"/var/www/playsms\"@PLAYSMS_PATH=\"$WEBDIR\"@g" $CONFDIR/playsmsd.conf

# DB string
cp -f $WEBDIR/config-dist.php $WEBDIR/config.php
echo "\$core_config['db']['dsn'] = 'mysql://playsms:playsms@localhost/playsms';" >> $WEBDIR/config.php

# Fix PHP cgi.fix_pathinfo
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php.ini

# FPM Worker
cat >/etc/php-fpm.d/www.conf <<EOF
[www]
catch_workers_output = yes
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 5
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
EOF

# nginx new website in port 8080
cat >/etc/nginx/conf.d/playsms.conf <<EOF
server {
        listen 8080 default_server;
        listen [::]:8080 default_server;
        root $WEBDIR;
        client_max_body_size 8M;
        index index.php index.html index.htm;
        server_name _;
        location / {
                try_files \$uri \$uri/ /index.php;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)\$;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 256 4k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
        }
}
EOF

# Enable and start web server
systemctl enable php-fpm
systemctl enable nginx
systemctl start php-fpm
systemctl start nginx

All installation goes without any issue. No errors, all OK. At the end, I run:

$ sudo /usr/local/bin/playsmsd start
playsmsd has been started
schedule at pid 1761
ratesmsd at pid 1763
dlrssmsd at pid 1765
recvsmsd at pid 1768
sendsmsd at pid 1771

$ sudo /usr/local/bin/playsmsd check
PLAYSMSD_CONF = /etc/playsmsd.conf
PLAYSMS_PATH = /usr/share/nginx/playsms
PLAYSMS_LIB = /var/lib/playsms
PLAYSMS_BIN = /usr/local/bin
PLAYSMS_LOG = /var/log/playsms
DAEMON_SLEEP = 1
ERROR_REPORTING = E_ALL ^ (E_NOTICE | E_WARNING)
IS_RUNNING = 1
PIDS schedule = 1761
PIDS ratesmsd = 1763
PIDS dlrssmsd = 1765
PIDS recvsmsd = 1768
PIDS sendsmsd = 1771

All seems OK:

$ ps aux | grep -iE "play|maria|nginx|php"
mysql     1506  0.5  8.6 1169116 88072 ?       Sl   12:02   0:01 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root      1597  0.0  1.1 365164 11616 ?        Ss   12:02   0:00 php-fpm: master process (/etc/php-fpm.conf)
nginx     1599  0.1  0.9 366092  9488 ?        S    12:02   0:00 php-fpm: pool www
nginx     1600  0.1  1.3 370604 13804 ?        S    12:02   0:00 php-fpm: pool www
root      1614  0.0  0.2 122220  2108 ?        Ss   12:02   0:00 nginx: master process /usr/sbin/nginx
nginx     1615  0.0  0.3 122824  3824 ?        S    12:02   0:00 nginx: worker process
root      1761  0.4  1.7 367308 17556 pts/0    S    12:03   0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf schedule
root      1763  0.4  1.7 367308 17476 pts/0    S    12:03   0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf ratesmsd
root      1765  0.4  1.7 367308 17468 pts/0    S    12:03   0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf dlrssmsd
root      1768  0.4  1.7 367308 17448 pts/0    S    12:03   0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf recvsmsd
root      1771  0.4  1.7 367308 17452 pts/0    S    12:03   0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf sendsmsd
technic+  1961  0.0  0.0 112664   984 pts/0    R+   12:05   0:00 grep --color=auto -iE play|maria|nginx|php

Then, I go to my browser:

Seems to work. However, when I use admin/admin to login, it simply returns to the exact same page.

Nothing in /var/log/php-fpm/error.log, nothing in /var/log/nginx/error.log, nothing in Chromium console, nothing in /var/log/playsms, nothing in nowhere!

I’ve tried with Firefox: Same story.

HOWEVER:

If i just do:

#!/bin/bash -eu
systemctl stop nginx     # Disable nginx
yum -y install php # note this will also install Apache httpd server as a dependency
cp -r /usr/share/nginx/playsms/* /var/www/html # Just copy the entire site
systemctl start httpd # Start Apache

And then I go to my browser and try to login with admin/admin… IT WORKS! From Chromium or from Firefox.

OK, maybe it’s an issue with the port, no? then:

#!/bin/bash -eu
systemctl stop httpd     # Disable Apache again
sed -i "s/8080 default_server/80 default_server/g" /etc/nginx/conf.d/playsms.conf
sed -i "s/80 default_server/8080 default_server/g" /etc/nginx/nginx.conf # Just exchange ports
systemctl start nginx # Start nginx

And then I go to my browser and try to login with admin/admin… IT DOESN’T WORKS :cry:

Any hint about it? I think I’ll follow the tutorial from Anton’s blog, and check the differences between nginx and PHP-FPM setup there, and compare with mine, because the idea is to use CentOS and not Ubuntu.

Any idea would be appreciated.

Thanks!

Fixed! nginx was unable to write in /var/lib/php/session, this directory is not automatically created by php-fpm; however mod_php is able to automatically create it, I don’t know why.

The solution is to simply create that directory and give to php-fpm user permission to write there. This is the script fixed, if anyone wish to use it:

#!/bin/bash -eu

# My environment
WEBDIR=/usr/share/nginx/playsms
CONFDIR=/etc
BINDIR=/usr/local/bin
SRCDIR=/usr/local/src

# Disable SELinux
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
setenforce permissive

# Install required dependencies
yum -y install epel-release
yum -y install mariadb-server nginx php-cli php-curl php-fpm php-gd php-imap \
  php-mcrypt php-mysql

# Download playSMS, untar, install composer
cd $SRCDIR
curl -OL http://downloads.sourceforge.net/project/playsms/playsms/Version%201.4/playsms-1.4.tar.gz
tar zxf playsms-1.4.tar.gz && rm -f playsms-1.4.tar.gz
cd $SRCDIR/playsms-1.4
./getcomposer.sh

# Configure MariaDB
systemctl enable mariadb
systemctl start mariadb

mysql -u root <<EOF
DROP USER ''@'localhost';
DROP DATABASE test;
CREATE DATABASE playsms;
GRANT ALL PRIVILEGES ON playsms.* TO playsms@localhost IDENTIFIED BY 'playsms';
FLUSH PRIVILEGES;
EOF

# Install playSMS DB
mysql -u playsms -pplaysms playsms < $SRCDIR/playsms-1.4/db/playsms.sql

# Setup files, folders and permissions
mkdir -p $WEBDIR
mkdir -p /var/{lib,log}/playsms
mkdir -p /var/lib/php/session
cp -rf $SRCDIR/playsms-1.4/web/* $WEBDIR
cp -rf $SRCDIR/playsms-1.4/daemon/linux/etc/playsmsd.conf $CONFDIR/playsmsd.conf
cp -rf $SRCDIR/playsms-1.4/daemon/linux/bin/playsmsd.php $BINDIR/playsmsd
chmod +x $BINDIR/playsmsd
chown -R nginx. $WEBDIR
chown -R nginx. /var/{lib,log}/playsms
chown -R nginx. /var/lib/php/session

# Fix playSMS web path
sed -i "s@PLAYSMS_PATH=\"/var/www/playsms\"@PLAYSMS_PATH=\"$WEBDIR\"@g" $CONFDIR/playsmsd.conf

# DB string
cp -f $WEBDIR/config-dist.php $WEBDIR/config.php
echo "\$core_config['db']['dsn'] = 'mysql://playsms:playsms@localhost/playsms';" >> $WEBDIR/config.php

# Fix PHP cgi.fix_pathinfo
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php.ini

# FPM Worker
cat >/etc/php-fpm.d/www.conf <<EOF
[www]
catch_workers_output = yes
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 5
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
EOF

# nginx new website in port 8080
cat >/etc/nginx/conf.d/playsms.conf <<EOF
server {
        listen 8080 default_server;
        listen [::]:8080 default_server;
        root $WEBDIR;
        client_max_body_size 8M;
        index index.php index.html index.htm;
        server_name _;
        location / {
                try_files \$uri \$uri/ /index.php;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)\$;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 256 4k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
        }
}
EOF

cat >/etc/systemd/system/playsmsd-dlrssmsd.service <<EOF
[Unit]
Description=playSMS DLR Service
Wants=mariadb.service
After=network.target mariadb.service
[Service]
Type=simple
Environment=HOME=/var/lib/playsms
WorkingDirectory=/var/lib/playsms
User=nginx
Group=nginx
ExecStart=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf dlrssmsd
ExecStop=/bin/kill -KILL $MAINPID
Restart=no
[Install]
WantedBy=multi-user.target
EOF

cat >/etc/systemd/system/playsmsd-ratesmsd.service <<EOF
[Unit]
Description=playSMS Rate Messages Service
Wants=mariadb.service
After=network.target mariadb.service
[Service]
Type=simple
Environment=HOME=/var/lib/playsms
WorkingDirectory=/var/lib/playsms
User=nginx
Group=nginx
ExecStart=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf ratesmsd
ExecStop=/bin/kill -KILL $MAINPID
Restart=no
[Install]
WantedBy=multi-user.target
EOF

cat >/etc/systemd/system/playsmsd-recvsmsd.service <<EOF
[Unit]
Description=playSMS Receiver Service
Wants=mariadb.service
After=network.target mariadb.service
[Service]
Type=simple
Environment=HOME=/var/lib/playsms
WorkingDirectory=/var/lib/playsms
User=nginx
Group=nginx
ExecStart=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf recvsmsd
ExecStop=/bin/kill -KILL $MAINPID
Restart=no
[Install]
WantedBy=multi-user.target
EOF

cat >/etc/systemd/system/playsmsd-schedule.service <<EOF
[Unit]
Description=playSMS Schedule Service
Wants=mariadb.service
After=network.target mariadb.service
[Service]
Type=simple
Environment=HOME=/var/lib/playsms
WorkingDirectory=/var/lib/playsms
User=nginx
Group=nginx
ExecStart=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf schedule
ExecStop=/bin/kill -KILL $MAINPID
Restart=no
[Install]
WantedBy=multi-user.target
EOF

cat >/etc/systemd/system/playsmsd-sendsmsd.service <<EOF
[Unit]
Description=playSMS Sender Service
Wants=mariadb.service
After=network.target mariadb.service
[Service]
Type=simple
Environment=HOME=/var/lib/playsms
WorkingDirectory=/var/lib/playsms
User=nginx
Group=nginx
ExecStart=/usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf sendsmsd
ExecStop=/bin/kill -KILL $MAINPID
Restart=no
[Install]
WantedBy=multi-user.target
EOF

# Enable and start web server
systemctl enable php-fpm
systemctl enable nginx
systemctl enable playsmsd-dlrssmsd
systemctl enable playsmsd-ratesmsd
systemctl enable playsmsd-recvsmsd
systemctl enable playsmsd-schedule
systemctl enable playsmsd-sendsmsd
systemctl start php-fpm
systemctl start nginx
systemctl start playsmsd-dlrssmsd
systemctl start playsmsd-ratesmsd
systemctl start playsmsd-recvsmsd
systemctl start playsmsd-schedule
systemctl start playsmsd-sendsmsd