Install playSMS 1.4.3 on CentOS 7

playSMS version 1.4.3 was released recently and currently it is the recommended playSMS version available. The release fixed critical security vulnerability and contains other bugfixes and improvements. This article shows you step by step howto install playSMS version 1.4.3 on CentOS 7.

I\’m using DigitalOcean (DO) service to test the configuration and commands. Create new Droplet in DO account. Click here to register on DO if you don\’t have an account.

Choose CentOS 7 (currently 7.6) and select at least the cheapest service (USD 5). Create and wait for a minute or two for the SSH to be ready. You can then login via SSH and start playSMS installation.

Login to your CentOS droplet (later we will call droplet as server) using SSH and follow instructions below step by step. Read carefully why you need to do each step correctly. Please pay attention to details.

This article first published in: https://antonraharja.com/2020/03/10/playsms-1-4-3-on-centos-7/

1. Prepare CentOS

There are some adjustment we need to do to our server created by DO. Some of them can be optional, but I recommend to just follow them all.

1.1. Fix Locale Issue

Fix locale issue. After login via SSH to your server you will see error related to locale setting. Fix that by adding 3 lines below to /etc/environment and then logout and re-login SSH.

vi /etc/environment
LC_ALL=\"en_US.UTF-8\"
LC_CTYPE=\"en_US.UTF-8\"
LANGUAGE=\"en_US.UTF-8\"

1.2. Add EPEL Repository

Add EPEL repository. This must be added. PHP 7.3 is in this repository.

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release

1.3. Setup firewalld

firewalld is your server\’s firewall, you need this. And also you might use it later for fail2ban, for added protection.

Install, start and enable firewalld:

yum -y install firewalld
systemctl start firewalld.service
systemctl enable firewalld.service

Don\’t worry your SSH won\’t be blocked.

1.4. Install Text Editor

Install easier text editor. This can be nano or mc/mcedit, or don\’t install it at all, just use vi. I like mc, so I install mc.

yum -y install mc

1.5. Install git and unzip

Install unzip and git now so you won\’t need to switch to root to install them later. We will need them when installing playSMS.

yum -y install git unzip

1.6. Fix ipv6 for composer

Most likely you will get timed-out when getting packages from composer repository, and composer is part of playSMS installation. You will need this fixed before installing playSMS.

The choice would be to disable IPv6 entirely, or run this:

echo \'precedence ::ffff:0:0/96 100\' >> /etc/gai.conf

Reference:

1.7. Add Regular User

Add a new Linux normal user to maintain services, to maintain playSMS later. In this article the user\’s username would be komodo.

adduser komodo

No need to set password as we won\’t need to login via SSH with that user. But if you need to you can add strong password by running passwd komodo.

The home directory for user komodo will be in /home/komodo. Later on our playSMS will be setup there.

1.8. Permissive selinux

You need to set selinux mode into permissive. Default mode, enforcing, will be quite hard to install new stuff manually. You can always use default mode if you know what you\’re doing.

Check current mode:

getenforce
Enforcing

Set mode to Permissive:

setenforce permissive

Make it permanent by editing selinux configuration file and change SELINUX=enforcing to SELINUX=permissive:

mcedit /etc/selinux/config
SELINUX=permissive

Reboot the server:

shutdown -r now

2. Install MySQL Server

We will use MariaDB as our MySQL server.

2.1. Install MariaDB

Install MySQL server MariaDB:

yum -y install mariadb-server mariadb

Starts MariaDB and enable it:

systemctl start mariadb.service
systemctl enable mariadb.service

2.2. MariaDB Secure Installation

Finalised MariaDB secure installation such as setting root password and disabling anonymous users. Pick strong password for root user, but we will not use root for playSMS, we will later create a new regular MySQL user to access MariaDB.

mysql_secure_installation
Enter current password for root (enter for none): <Enter>
Set root password? [Y/n] Y
New password: <strong password>
Re-enter new password: <confirm strong password>
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

2.3. Test MariaDB

Test your MySQL root access:

mysql -u root -p

You should now logged in to your MySQL server. Type quit and <Enter> to exit MySQL console.

3. Install Web Server and PHP 7.3

The web server is Apache and selected PHP version is 7.3.

3.1. Install Apache

Install web server Apache:

yum -y install httpd

Starts Apache and enable it:

systemctl start httpd.service
systemctl enable httpd service

3.2. Allow HTTP and HTTPS

Enable access to http and https port:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

3.3. Install Remi Repository

Install Remi CentOS repository for PHP 7.3:

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum update

3.4. Install PHP 7.3

Install PHP 7.3:

yum-config-manager --enable remi-php73
yum -y install php php-opcache

Restart Apache to enable PHP:

systemctl restart httpd.service

3.5. Install PHP Modules

Install commonly required PHP modules. These modules will be required by playSMS, I suggest to install them now so that you can do playSMS installation without leaving normal user later.

yum -y install php-cli php-mysqli php-gd php-mbstring php-xml php-curl php-zip

Restart Apache to enable PHP modules:

systemctl restart httpd.service

3.6. Test Apache and PHP

Test Apache and PHP by create a test PHP file in default web root. This file need to be removed as soon as the test done.

mcedit /var/www/html/info.php
<?php
phpinfo();

Save the file and browse this file at your web server address, for example browse: http://110.128.xx.xx/info.php (real IP redacted).

Please note that you will get an IP public from DO if you\’re doing this article in DO. If you are doing it locally using VirtualBox for example the IP might be a private IP.

You should see PHP Info on your browser. Remember to remove info.php after testing.

4. Supports HTTPS

HTTPS supports will be added to our web server by requesting, installing and configuring SSL certificate from Let\’s Encrypt on Apache. Let\’s Encrypt provides a free SSL certificate for everyone.

4.1. Setup VirtualHost

This step is required for getting free SSL certificate for our HTTPS service from Let\’s Encrypt.

In this example I will be using demo143.playsms.org domain as my entry in VirtualHost setup. I also have set the DNS to point demo143.playsms.org to my CentOS server\’s public IP. Of course you will need your own domain/subdomain and point to your own CentOS server\’s public IP.

The example VirtualHost configuration will make Apache serve PHP file for domain demo143.playsms.org from our regular user (user komodo) Home Directory (/home/komodo/public_html to be exact).

Prepare user\’s Home Directory:

cd /home/komodo
mkdir -p public_html log
chmod og+rx /home/komodo public_html log
chown komodo.komodo -R /home/komodo
chown apache.apache -R /home/komodo/log

Create VirtualHost configuration file for domain demo143.playsms.org:

mcedit /etc/httpd/conf.d/demo143.playsms.org.conf
<VirtualHost *:80>
    ServerName demo143.playsms.org
    DocumentRoot /home/komodo/public_html
    ErrorLog /home/komodo/log/httpd-error.log
    CustomLog /home/komodo/log/httpd-accesss.log combined
</VirtualHost>

Restart Apache:

systemctl restart httpd.service

Switch user as user komodo and test VirtualHost by create a PHP file in /home/komodo/public_html.

su - komodo
mcedit public_html/test.php
<?php
echo \"<b>Welcome !!</b>\";

Save the file and browse this file at your domain, in this example browse http://demo143.playsms.org/test.php

You know your VirtualHost is working when you see Welcome !! on your browser.

Remove the test.php and then go back to root shell by typing exit and <Enter>.

4.2. Install certbot

We will get the SSL certificate from Let\’s Encrypt and use certbot to install it on the server.

Install certbot:

yum install certbot python2-certbot-apache

4.3. Setup SSL Certificate

Run certbot for Apache:

certbot --apache

Answer questions correctly. You will need to input your email address, choose A to Agree with the ToS and last choose Redirect (selection no. 2) to completely remove HTTP and just serve HTTPS by redirecting all HTTP requests to HTTPS.

Example of successful SSL certificate request and installation:

\"\"

Visit ssllabs.com/ssltest and submit your domain to test your HTTPS configuration.

5. Install playSMS

Now that we have a working web server with PHP and HTTPS supports, and MySQL server, we can then install playSMS 1.4.3.

From now on you have to switch user to normal Linux user. In this article playSMS will be installed under user komodo as mentioned before.

Switch user to user komodo and do commands in this chapter as user komodo:

su - komodo

5.1. Prepare Directories

Here are some important directories that need to be ready before playSMS installation:

  • /home/komodo/public_html
  • /home/komodo/log
  • /home/komodo/bin
  • /home/komodo/etc
  • /home/komodo/lib
  • /home/komodo/src

public_html and log is already exists and prepared, they are created previously on section 4.1 as part as VirtualHost configuration. So now we need to create the rest and set proper permission.

Remember to switch user as user komodo first if you haven\’t:

su - komodo

Then create directories:

cd /home/komodo
mkdir -p bin etc lib src
chmod og+rw bin etc lib src

5.2. Check PHP Modules

Required PHP modules should already be installed if you follow this article from the start, it is on section 3.5. But before proceeding with playSMS installation you need to make sure that required PHP modules are installed:

php -m

Make sure you see at least curl, gd, mbstring, mysqli and xml on the list. If they are not on the list then please install them, see section 3.5.

5.3. Prepare Database

Create MySQL database that will be used by playSMS:

mysqladmin -u root -p create playsms

Login as MySQL user root and create a new MySQL user for above database:

mysql -u root -p
CREATE USER \'playsms\'@\'localhost\' IDENTIFIED BY \'strongpasswordhere\';
GRANT ALL PRIVILEGES ON playsms.* TO \'playsms\'@\'localhost\';
FLUSH PRIVILEGES;
exit

As of this section you will have a MySQL database named playsms and MySQL normal user playsms with your own strong password which only have access to database playsms.

5.4. Get playSMS Source Code

playSMS source code available on Github, you will need git to get them. See section 1.5 if you haven\’t install git yet.

Go to src folder:

cd /home/komodo/src

Get playSMS version 1.4.3:

git clone -b 1.4.3 --depth=1 https://github.com/antonraharja/playSMS

As of now your playSMS 1.4.3 source code is available at /home/komodo/src/playSMS.

5.5. Prepare install.conf

Go to playSMS source code directory, copy install.conf.dist to install.conf and then edit it.

Go to playSMS source code directory:

cd /home/komodo/src/playSMS

Edit install.conf:

cp install.conf.dist install.conf
mcedit install.conf

These are values I set on install.conf:

DBUSER=\"playsms\"
DBPASS=\"strongpasswordhere\"
DBNAME=\"playsms\"
DBHOST=\"localhost\"
DBPORT=\"3306\"
WEBSERVERUSER=\"apache\"
WEBSERVERGROUP=\"apache\"
PATHSRC=\"/home/komodo/src/playSMS\"
PATHWEB=\"/home/komodo/public_html\"
PATHLIB=\"/home/komodo/lib\"
PATHBIN=\"/home/komodo/bin\"
PATHLOG=\"/home/komodo/log\"
PATHCONF=\"/home/komodo/etc\"

 

Values need to reflect your server configuration. If you follow this article from the start then above values should be correct, with exception your true database password (DBPASS) of course.

Save install.conf and ready to run install script.

5.6. Run playSMS Install Script

playSMS install script will download composer and download packages from repo.packagist.org. After that the script will copy necessary files from playSMS source code to public_html and bin.

Since theres requirement to be able to download from external site (repo.packagist.org), you have to make sure that external site is working and reachable.

But you can just start the install script, because you\’ll know if something not right, for example the script fail to download packages. When that happens you can fix the problem first, like fix your networking setup and perhaps firewall, or simply wait (theres a chance the external site down too), and then go back to re-run the install script.

Just to make sure that networking stuff is right, please see section 1.6.

OK, let\’s start the installation:

cd ~/src/playSMS/
./install-playsms.sh

Verify installation:

~/bin/playsmsd ~/etc/playsmsd.conf check
\"\"

All playSMS daemon should be running. And of course, browse your server too, you should see playSMS web login (don\’t worry if the page seems broken for now).

5.7. Adjust config.php

Edit playSMS config.php and adjust some value, or just one part, the HTTPS support.

mcedit ~/public_html/config.php

Inside config.php:

  • Search for logstate and set it to 3
  • Search for ishttps and set it to true.

5.8. Change Default Password

Go to your browser, browse the server and login as playSMS administrator.

Default admin access:

  • Username: admin
  • Password: admin

After login as admin, go to My account -> Preferences and change admin password.

5.9. Installation Done

Installation is done, you got a working playSMS now.

I would suggest you to visit these articles and do that too:

Don\’t forget to join the Forum and ask/answer playSMS questions there:

6. References

Please visit these websites: