Featured image of post Containerizing All Services: Running PHP Code in Containers with Laravel-S

Containerizing All Services: Running PHP Code in Containers with Laravel-S

Recently obsessed with Docker, containerized all services on 1024 Programmer's Day using laravel-s

Preface

  • Recently containerized all Go programs on the server for deployment
  • Combined with CODING’s CI/CD, deployment has become extremely pleasant
  • But there were still several PHP projects remaining on the server

Blog (Originally built with WordPress)

  • Deploy Nginx and PHP containers, then reverse proxy via host machine
  • Discovered Hugo (similar to Hexo), a static site generator
  • Migrated blog to Hugo with fast builds and real-time previews
  • Now runs in a single Nginx container with host reverse proxy
  • Details: My Blog

DreamNote Admin (Laravel)

  • Original Nginx + PHP-FPM container approach
  • Switched to persistent PHP runtime using laravel-s (supports dcat-admin)
  • Official Swoole container docker-swoole with custom Dockerfile:
FROM phpswoole/swoole:php7.4-alpine

# PHP extension installer script
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN install-php-extensions pcntl redis pdo_mysql

WORKDIR /var/www
COPY . .
RUN chmod -R 0777 storage && \
    chmod -R 0777 bootstrap/cache && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && \
    composer install --optimize-autoloader --no-dev && \
    php artisan config:cache && \
    php artisan route:cache && \
    php artisan view:cache && \
    php artisan laravels publish --no-interaction

CMD ["php", "bin/laravels", "start", "--env=product"]

Key Configurations

  1. Provider Registration (config/laravels.php)
\Dcat\Admin\AdminServiceProvider::class,
  1. Cleaners Configuration
Hhxsv5\LaravelS\Illuminate\Cleaners\SessionCleaner::class,
Hhxsv5\LaravelS\Illuminate\Cleaners\AuthCleaner::class,
Hhxsv5\LaravelS\Illuminate\Cleaners\DcatAdminCleaner::class,
  1. Essential Settings:
'listen_ip' => '0.0.0.0',
'handle_static' => true // Enable for static assets

Monday Mall (Laravel)

  • Implemented same containerization approach

Conclusion

  • Successfully removed all native environments (Go/PHP/Python) from server
  • Pure Docker environment now runs all services
  • Easy migration and server replacement possible
  • CODING CI/CD enables seamless container deployment

Containerization achievement unlocked! 🐳🚀