This is the repository of Peer Networks Backend Code.
Instructions for contributing to the Project can be found here:
Follow these steps to set up the backend on your local machine:
sudo apt install php8.3-cli
sudo apt-get install php-pgsql php-bcmath php-xml
sudo apt install php8.3-curl php8.3-gmp
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Add to PATH (recommended)
sudo mv composer.phar /usr/local/bin/composer
# Install PostgreSQL
apt install postgresql
# Start service
sudo systemctl enable postgresql
sudo service postgresql start
-- Log into postgres Terminal from the shell:
sudo -u postgres psql
-- In PostgreSQL terminal:
ALTER USER postgres WITH PASSWORD 'test';
CREATE DATABASE peer;
GRANT ALL PRIVILEGES ON DATABASE peer TO postgres;
\q
# Open .conf file:
sudo nano /etc/postgresql/<version>/main/pg_hba.conf
# Change the method from peer to md5 in the following line:
# TYPE DATABASE USER ADDRESS METHOD
local all postgres md5
# Restart postgres for changes to take affect:
sudo service postgresql restart
# These commands will add the schema and some optional data to the Database peer:
# From project-root directory:
psql -U postgres -d peer -f sql/structure.psql
psql -U postgres -d peer -f sql/optional_data.psql
# Access database:
psql -U postgres -d peer
Install Dependencies:
# From project-root directory:
sudo composer require james-heinrich/getid3
composer install
Create .env
from .env.schema
Set these values:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=test
DB_DATABASE=peer
And change these value:
PRIVATE_KEY_PATH=../keys/private.key -> keys/private.key
PUBLIC_KEY_PATH=../keys/public.key -> keys/public.key
REFRESH_PRIVATE_KEY_PATH=../keys/refresh_private.key -> keys/refresh_private.key
REFRESH_PUBLIC_KEY_PATH=../keys/refresh_public.key -> keys/refresh_public.key
# From project-root/keys directory:
openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in private.pem -out public.pem
openssl genpkey -algorithm RSA -out refresh_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in refresh_private.pem -out refresh_public.pem
# Rename files
mv private.pem private.key
mv public.pem public.key
mv refresh_private.pem refresh_private.key
mv refresh_public.pem refresh_public.key
# From project-root directory:
php -S localhost:8888 -t public/
Endpoint:
http://localhost:8888/graphql
Recommended Testing Tool:
Postman API Platform
(Use GraphQL format for requests)
Note: All credentials and security keys in this example are for development purposes only. Always use secure credentials in production environments.