Installation - Server

This documents contains instructions for installing the server side code on cPanel or a standard LAMP appliance from any reputed cloud service provider.

Keep in mind

  1. The server steps assume you have a clean Ubuntu server running LAMP already with root (SSH) access to it (LAMP/LEMP only, not applicable to cPanel install).

  2. You web server runs under www-data user (LAMP/LEMP only, not applicable to cPanel install).

  3. You have pointed your domain e.g., yourapp.com to your server IP address (via A record at your domain registrar). Throughout these steps, I will use yourapp.com as a placeholder for your website address that you must replace with yours.

cPanel

To install the script on cPanel, we have made an easy to follow video available in our YouTube channel on https://bit.ly/muly-cpanel-install-2 link.

LAMP or LEMP

Below instructions assume that you are familiar with command line and cloud deployments. The steps are inclined towards standard LAMP distribution offered by DigitalOcean here. These would not differ much for any other LAMP distribution on Ubuntu or other Debian derived distros. For LEMP, only the virtual host configuration may differ and rest steps can be easily adapted.

Before getting started, upload the server.zip archive to your server using below command:

scp server.zip root@yourapp.com:/var/www/html/server.zip

Then SSH into the server and proceed with installing dependencies.

ssh root@yourapp.com
# update index with latest packages
sudo apt update

# required to extract the uploaded archive
sudo apt install unzip

# the extensions that do not come by default
sudo apt install php-bcmath php-curl php-mbstring php-redis php-xml

# needed for sending forgot password emails (optional)
sudo apt install sendmail

# needed for background job processing (optional)
sudo apt install redis-server supervisor

# needed for uploading clips from admin panel (optional)
sudo apt install ffmpeg

Now you can extract the uploaded ZIP archive and setup file/folder permissions.

# change to server's document root
cd /var/www/html

# remove the default page
rm index.html

# unzip the archive, symlink storage and setup permissions
unzip server.zip
php artisan storage:link
chown -R www-data:www-data bootstrap/cache storage .env
chmod -R 755 bootstrap/cache storage
chmod -R 664 .env

Now create a copy of apache's default vhost for our app.

# copy the default web host
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/muly.conf

# open it for editing
nano /etc/apache2/sites-available/muly.conf

Then we must update the vhost configuration similar to below example. Being specific, you need to add a ServerName directive to match your domain e.g., yourapp.com. You need to suffix DocumentRoot with /public_html and do similar with the <Directory .../> directive as well.

<VirtualHost *:80>
    ServerName yourapp.com
    ServerAdmin admin@yourapp.com
    DocumentRoot /var/www/html/public_html

    <Directory /var/www/html/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>
</VirtualHost>

Then you must disable the default vhost, enable your created vhost and enable the rewrite module of apache2. Please run below commands to achieve it.

sudo a2dissite 000-default
sudo a2ensite muly
sudo a2enmod rewrite
sudo systemctl restart apache2

Some PHP (assuming version 7.4, replace with yours) settings must also be tweaked to allow bigger uploads (and mostly on slower connections).

# open the file for editing
nano /etc/php/7.4/apache2/php.ini

Then find and update below options as shown. You can use Ctrl+W to quickly locate them.

max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 100M
upload_max_filesize = 100M

Then restart the apache server as below:

sudo systemctl restart apache2

It is not required to have SSL certificate but recommended to have secure your users personal data from MITM and similar attacks. You can also get a free SSL certificate using below command:

certbot --apache -d yourapp.com

# enter details and make sure to enable redirection (option 1)

You also need to create a MySQL database and an associated user to use with the script. You can run below commands to create those but please make sure to replace 12345678 with a strong password and make note of it for use later.

sudo mysql

# run below queries in the mysql prompt
mysql> CREATE DATABASE muly;
mysql> CREATE USER muly@localhost IDENTIFIED WITH mysql_native_password BY '12345678';
mysql> GRANT ALL PRIVILEGES ON muly.* TO muly@localhost;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

You should now open https://yourapp.com/ in your favorite browser, provide all the required information and return here when the installation is done.

You must also setup a cron job to automatically send scheduled notifications (recommended) and update news articles (if needed). To do that, please follow below commands:

crontab -e -u www-data

# now choose your editor (1 for nano) and add below line at bottom
* * * * * cd /var/www/html && php artisan schedule:run

If you wish to use background job queue (highly recommended), you must also configure a process manager for your queue workers. To do that, run below command:

nano /etc/supervisor/conf.d/muly.conf

Put below contents in the file and save.

[program:muly]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --sleep=3 --tries=1 --timeout=300
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/worker.log
stopwaitsecs=3600

Then restart the Supervisor as follows:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start muly:*

The server has now been setup and you can proceed to building the Android app.

Last updated