Skip to content

YilanBoy/docfunc

Repository files navigation

Badge changing depending on mode.

Tests Build images Codecov

Introduction

This is a simple blog project, mainly used to help me learn about Laravel. The entire project uses the TALL stack, which is:

This project contains certain basic functions, such as membership system, writing articles and replies.

Post editor use CKEditor 5, You can upload image to AWS S3 in blog post. You can search post by Algolia.

Requirements

Installation

Clone the repository to your local machine:

git clone https://github.com/YilanBoy/docfunc.git

Change the current working directory to the repository:

cd docfunc

Install the composer package:

composer install

Install the npm package:

npm install

Running laravel mix:

npm run dev

Create the .env file, and set up the config, such as database connection, reCAPTCHA key, S3 key, mail service etc:

cp .env-example .env

Generate application key (for session and cookie encryption):

php artisan key:generate

Running migrations command to generate the database schema:

php artisan migrate

Generate ide-helper:

php artisan ide-helper:generate

Generate model ide-helper:

php artisan ide-helper:models

Service Used

Deployment

Supervisor

You could deploy this project use Laravel Octane, supercharges the performance by serving application using Swoole, RoadRunner, or FrankenPHP.

Note

If you want to use swoole server, you must install swoole extension first.

Using PECL to install swoole extension:

pecl install swoole

Using package manager to install swoole extension (Linux):

sudo add-apt-repository ppa:ondrej/php
sudo apt-get php8.2-swoole

Setting octane in .env file

OCTANE_SERVER=swoole
OCTANE_HTTPS=false

Start the service by swoole server:

php artisan ocatane:start

In production, you can use Supervisor to start swoole server and laravel queue worker.

Using supervisor to start swoole server process, we have to create a docfunc-octane-worker.conf config file in /etc/supervisor/conf.d/.

[program:docfunc-octane-worker]
command=/usr/bin/php -d variables_order=EGPCS /var/www/docfunc/artisan octane:start --workers=2 --server=swoole --host=0.0.0.0 --port=8000
user=www-data
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=/var/log/docfunc-octane-worker.log

Using supervisor to start laravel queue worker process, we have to create a docfunc-queue-worker.conf config file in /etc/supervisor/conf.d/.

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

Set crontab to run Laravel Task Schedule.

Editing crontab.

crontab -e

Add this line to run the Scheduler.

0 * * * * cd /var/www/docfunc && php artisan schedule:run >> /dev/null 2>&1

Docker

Note

You must install Docker first.

The container is divided into 3 parts, which are app, queue and scheduler.

Dockerfiles is placed in the folder dockerfiles. The php settings and entrypoint files in the container are placed in the folder deployment. You can use Docker and these files to build images.

cd docfunc

# build blog app
docker buildx build -f containerize/dockerfiles/Dockerfile.app --platform linux/amd64,linux/arm64 --push -t docfunc:latest .

# build queue
docker buildx build -f containerize/dockerfiles/Dockerfile.queue --platform linux/amd64,linux/arm64 --push -t docfunc-queue:latest .

# build scheduler
docker buildx build -f containerize/dockerfiles/Dockerfile.scheduler --platform linux/amd64,linux/arm64 --push -t docfunc-scheduler:latest .