# Backend guidelines

# Requirements

You will need some things installed before you can start hacking away. We will start with the basic things.

# Programs

WARNING

For Composer, choose the default version and not the v2.0+. Some packages are not yet compatible with the new version of composer.

TIP

For Windows users, I suggest installing Windows Terminal for a smoother terminal experience and cleaner outputs.

# PHP, MySQL and Apache

For installing these services, you can either use an all-in-one development environment which does all of it for you or you can install them one-by-one manually. For manual installation, refer to the operating system you are using.

As far as development environments go, you can pick one from these:

Whichever route you take, make sure that the following minimum requirements are met:

  • PHP >= 7.4.3
    • BCMath Extension
    • Ctype Extension
    • Exif Extension
    • Fileinfo Extension
    • GD Extension
    • JSON Extension
    • Mbstring Extension
    • OpenSSL Extension
    • PDO Extension
    • Redis Extension
    • Tokenizer Extension
    • XML Extension
  • MySQL >= 5.7.8 or MariaDB >= 10.2.3
  • Apache modules
    • mod_rewrite
    • mod_ssl

For information about enabling specific php extensions, refer to the documentation of the development environment you chose from the above list.

WARNING

Do not edit the php.ini and other configuration files directly if you use one the above development environments, cause they tend to overwrite the configuration files if you change a service version or just restart the service which means that your changes will be lost. For information about properly changing configuration values, refer to the official documentation of your chosen environment.

If you want to use WampServer...

Make sure you follow their guide here: http://forum.wampserver.com/read.php?2,138295.

NOTE

Installing these services on Windows manually is not recommended. If you are using Windows, kindly pick one of the suggestions from above. You will spare yourself a lot of headache.

# Installing Redis

Redis is an in-memory data structure store and we use it specifically for caching. Installing it is optional, but if you want to recreate the real server environment as much as possible on your local machine, it's best to install it.

# Windows

One way to install Redis is using Chocolatey. Once you installed the windows package manager, you can install redis by running the following command:

choco install redis-64 --version 3.0.503

NOTE

As it turns out, the current version of redis-64 via Chocolatey has some issues which is why we use the --version 3.0.503 in the above command.

Now you have redis installed. To add the redis client as a service (so you don't have to start it manually every time you start windows), run this command:

redis-server --service-install

If you want to install it manually, you can download the msi file from here: https://github.com/microsoftarchive/redis/releases. Don't forget to add the redis client as a service afterwards.

You can verify that everything works as it should by running the following command:

redis-cli ping

The output should be:

PONG

NOTE

You might wonder why I bothered to mention Chocolatey at all, if all you have to do is run an msi file to install redis. I still suggest using Chocolatey because it takes care of any additional requirements for using redis.

NOTE

If you get an error while running redis-cli related commands right after installation with a message like The term 'redis-cli' is not recognized as the name of a cmdlet, function, script file, or operable program., try to restart the terminal you are using. All terminals open at the moment you change something in the windows environment variables will not be affected by those changes.

# Ubuntu

To install it run the following commands as root or user with sudo privileges:

sudo apt update
sudo apt install redis-server

Once the installation is completed, the Redis service will start automatically. To check the status of the service, enter the following command:

sudo systemctl status redis-server

You should see something like this:

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-06-06 20:03:08 UTC; 10s ago
...

You can also verify that everything works as it should by running the following command:

redis-cli ping

The output should be:

PONG

# Installing Redis PHP extension

After you installed the redis client, you will need a way to communicate with it via PHP to be able to use it. For this, we will install the Redis PHP extension.

# Windows

First, we need to know the exact build of the PHP version we are using. We will need the following information (you can see all this on the top of a phpinfo page):

  • PHP version
  • Architecture
  • Thread Safety

Once you have that information, open https://pecl.php.net/package/redis and click on the DLL link in the latest stable version from the list. You will see 4 versions for each supported PHP version at the bottom of the page. Download the one according to the information we just collected from phpinfo.

Extract the contents of the zip folder. You can find a php_redis.dll among the files. You need to copy this dll to the extension directory under your php installation directory.

The path to the extension directory looks something like this (the php version directory might be different depending on the php version you use):

  • Wamp: C:\wamp\bin\php\php7.4.4\ext
  • Laragon: C:\laragon\bin\php\php-7.4.8-Win32-vc15-x64\ext

After you copied the dll file into the extension directory, you need to enable the extension in your php configuration. To do this, you need to find the .ini file your php version is using. The suggested development environments usually have a clickable menu which will open the right configuration file for you. If you don't see any option for this, please refer to the documentation of the program you are using.

Anywho. You need to add this line after the already enabled extensions (just search for extension= in the file and you will find the place):

extension=redis

Save the file and restart PHP. If everything went ok, you should be able to see the Redis PHP extension in phpinfo. Just search for redis and you should be able to find it.

# Ubuntu

To install the extension on Ubuntu, run this command:

sudo apt install php-redis

The installer will automatically enable redis extension for all the pre installed PHP versions.

If you installed a new PHP version after installing the redis php extension, you can use the below command to enable the module for the new php version specifically. For example to enable the extension for PHP 7.4, run:

sudo phpenmod -v 7.4 -s ALL redis

# Image optimization tools

We will use some image optimization tools which needs to be installed separately in order to work. We will install the following tools:

# Windows

Download the packages.zip file by clicking here.
Extract or copy the extracted files into your system drive (so into C:\packages).
Add the bin directory to your PATH environment variables under the system variables (so add C:\packages\bin). If you have no idea how to do this, You can follow this guide: https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/.
That's it. Took you a few minutes, right? Well, it took me 6 hours to get them packages for windows, so if you want to buy me a beer, you have my blessing. =D

# Ubuntu

On Ubuntu, all you have to do is run the following command:

sudo apt install jpegoptim optipng pngquant
Last Updated: 2/2/2021, 10:25:59 AM