Skip to content

Installation Guide

Alexis Tan edited this page Jul 1, 2021 · 7 revisions

Throughout this guide you'll learn how to install the app using Git, Composer and Yarn, as-well-as setting up supervisor to handle queued tasks, and how to set up a cronjob to handle schedule tasks, this guide does assume you are at least somewhat familiar with Linux systems, and already have everything defined in the prerequisites set up and ready.

Table of Content

Prerequisites

  • Apache2 / Nginx
  • Yarn
  • Composer
  • Node >= v10.15
  • PHP >= v7.4
    • BCMath PHP Extension
    • Ctype PHP Extension
    • JSON PHP Extension
    • Mbstring PHP Extension
    • OpenSSL PHP Extension
    • PDO PHP Extension
    • Tokenizer PHP Extension
    • XML PHP Extension
    • GD PHP Extension

If you're new to web hosting and unsure of how to set up the prerequisites you can use one of the guides below to help you get started.

LAMP Stack (Linux, Apache2, MySQL, PHP) https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04

LEMP Stack (Linux, Nginx (Engine-X), MySQL, PHP) https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04

Installing Laravel

The app utilizes Composer for installing the PHP dependencies, and Yarn for installing the node dependencies, to get started you'll first need to clone down the repository.

git clone https://github.com/Senither/ShareX-Media-Server.git .

Next, go into the ShareX-Media-Server folder, first, we'll set up the PHP side of the project, to do this install all the dependencies using Composer

composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

Then rename and set up your environment variables by renaming the .env.example file to .env and adding in your settings.

Next, we'll need a unique application key, Laravels artisan helper makes this super easy, just run:

php artisan key:generate

We're now ready to migrate our database, this will create all the tables required for the application.

php artisan migrate

Next, we'll need to make sure that the application can read all the required files, and write to the places where files will be generated later when the app is in-use, the easiest way to do this is by setting the storage and bootstrap cache directories to permission level 775 and changing the ownership of the files with the account that runs our webserver.

chmod -R 775 storage
chmod -R 775 bootstrap/cache

chown -R www-data:www-data storage
chown -R www-data:www-data bootstrap/cache

Hint: If you're planning on sharing files via services like Discord and you'd like to have the file preview embed inside the Discord client you need to set up a link with the storage directory, this can be done by running php artisan storage:link.

Now we'll need to set up our cronjobs for the application, this will allow the app to run tasks like the cleanup task outside of the users request, so we can ensure files are deleted when they should be, this can be done by setting up a cronjob to run the artisan schedule:run command, start by opening the crontab file.

crontab -e

Next, add a new cron command at the bottom of the file that runs every minute.

* * * * * php /path/to/your/ShareX-Media-Server/artisan schedule:run

Setting up queue workers

Next, we'll need to set up a supervisor to run and manage our queues, the queues are used for generating thumbnails, and processing other tasks that would otherwise take a while to be completed, start by installing the supervisor package:

sudo apt-get install supervisor

You can skip this step if you have set the QUEUE_CONNECTION environment variable in the .env file to sync, setting it to sync will run the tasks that would otherwise have been queued right as they're called.

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a media-server-worker.conf file that starts and monitors a queue:work process:

[program:media-server-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/your/ShareX-Media-Server/artisan queue:work --sleep=3 --tries=5
autostart=true
autorestart=true
user=<username>
numprocs=2
redirect_stderr=true
stdout_logfile=/path/to/your/ShareX-Media-Server/worker.log
stopwaitsecs=3600

In this example, the numprocs directive will instruct Supervisor to run two queue:work processes and monitor all of them, automatically restarting them if they fail, you should be fine with a single process if the site is being hosted for a small number of people. You should replace the <username> with the username of the account that should run the queued jobs.

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start media-server-worker:*

The entire server side should now be set up and ready to be used!

Setting up application assets

Lastly, we'll need to build all of the front-end resources so users can view and use the website, this can be done using Yarn.

yarn install

This will install all the node modules required to build our assets, if Yarn is not installed you can use npm install instead, after all the node modules are installed we can build our assets.

yarn prod

This will build and compile all our assets for a production environment, different environment builds can also be used, like dev for development mode, or watch for watch mode, which will re-build all the assets anytime any changes are made to the files.

The entire app should now be setup!

Default login credentials

You can try visiting the site in your browser, if everything is set up correctly you should be presented with a login screen, you can log in using the credentials below as an admin user.

You can also edit the config/fortify.php file and uncomment Features::registration() on line 135 to enable user registration on the site, however, do note that this means anyone can make an account, users created through the registration form are regular users and won't have access to the control panel, however, they can upload images, files, and text snippets through the API using ShareX.


Now that the media server should've been setup you can check out the setting up ShareX guide to learn how to setup ShareX so that it can properly talk to the media server.