CodingTricks LogoCodingTricks
HomePostsTipsCopy/PasteLinksContact UsAbout Us
2024 - 2025 CodingTricks.co | All rights reserved
Privacy PolicyTerms of Service
How to Customize FrankenPHP

How to Customize FrankenPHP

Posted by

kamlesh paul

on

Dec 18, 2024

| 3 min read

Last updated on : Dec 18, 2024

Server
193 views

In my previous article, Boost Laravel Performance: Running Octane with FrankenPHP in Production (Zero Downtime), I demonstrated a great solution, but some key details were missing. Specifically:

  • How to add php extensions
  • Which extensions are supported
  • How to modify php.ini settings
  • How to change the PHP version and which versions are supported

If you’re looking for answers to these questions, let’s cover them in this article.

#Table of contents

  • How to add php extensions
  • Which extensions are supported
  • How to modify php.ini settings
  • How to change the PHP version and which versions are supported
  • Copy FrankenPHP binary
  • Conclusion
  • FAQ
    • Can I add custom PHP extensions that are not listed?
    • How do I know which PHP version to use?
    • Can I change PHP settings on a live server?

#How to add php extensions

  • By default, most popular PHP extensions are compiled. To reduce the size of the binary and to reduce the attack surface, you can choose the list of extensions to build using the PHP_EXTENSIONS Docker ARG.

For instance, run the following command to only build the redis extension:

docker buildx bake \
  --load \
  --set static-builder.args.PHP_EXTENSIONS=redis \
  static-builder

To add libraries enabling additional functionality to the extensions you’ve enabled, you can pass use the PHP_EXTENSION_LIBS Docker ARG:

docker buildx bake \
  --load \
  --set static-builder.args.PHP_EXTENSIONS=redis \
  --set static-builder.args.PHP_EXTENSION_LIBS=libjpeg,libwebp \
  static-builder

#Which extensions are supported

  • FrankenPHP use static-php under the hood to compile PHP binary here is the list https://static-php.dev/en/guide/extensions.html

#How to modify php.ini settings

  • You can achieve this using the ini_set() and set_time_limit() functions. For example:
ini_set('memory_limit', '256M');
set_time_limit(60); // Limit script execution to 60 seconds

This approach lets you adjust settings such as memory limits and execution time without affecting the global configuration, providing flexibility in how your PHP scripts run.

#How to change the PHP version and which versions are supported

docker buildx bake \
  --load \
  --set static-builder.args.PHP_EXTENSIONS=redis \
  --set static-builder.args.PHP_EXTENSION_LIBS=libjpeg,libwebp \
  --set static-builder.args. PHP_VERSION=8.0 \
  static-builder

#Copy FrankenPHP binary

docker cp $(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp ; docker rm static-builder

#Conclusion

Customize FrankenPHP allows you to optimize your Laravel applications effectively. By adjusting PHP extensions, changing settings, and managing PHP versions, you can create a tailored environment that meets your application’s needs. These enhancements can significantly improve performance and flexibility, ensuring a smooth deployment process.

For more information about FrankenPHP, check out the FrankenPHP documentation.

#FAQ

#Can I add custom PHP extensions that are not listed?

Yes, you can add custom extensions by compiling them yourself. Refer to the static-php documentation for guidance on adding unsupported extensions.


#How do I know which PHP version to use?

The best PHP version depends on your application requirements and compatibility with Laravel. It’s generally recommended to use the latest stable version supported by your Laravel version.


#Can I change PHP settings on a live server?

Yes, you can change PHP settings dynamically using ini_set() in your PHP scripts. However, be cautious when adjusting critical settings on a live server.

Related Posts

  • How to Protect Your Laravel from Spam IPs Using the Laravel Abuse IP PackageHow to Protect Your Laravel from Spam IPs Using the Laravel Abuse IP Package
  • How to setup Laravel Queues on cPanel: A Step-by-Step GuideHow to setup Laravel Queues on cPanel: A Step-by-Step Guide
  • How to Protect Your Linux Server from Brute Force SSH AttacksHow to Protect Your Linux Server from Brute Force SSH Attacks
  • How to Manage Multiple GitHub Accounts on the Same ComputerHow to Manage Multiple GitHub Accounts on the Same Computer
  • Next.js Deployment Script for Zero Downtime on VPS with PM2Next.js Deployment Script for Zero Downtime on VPS with PM2

Tags

Api(1)Authentication(5)Backup (1)Copy Paste(12)Email(2)Express(1)Firebase(1)Github Action(2)News(8)Push Notification(1)Queue(2)Server(11)Server Action(3)Testing(1)Tips(17)Websocket(1)

Popular Posts

  • TweakPHP 0.1.0 Beta: A Free and Open-Source Alternative to Tinkerwell Is Here!  TweakPHP 0.1.0 Beta: A Free and Open-Source Alternative to Tinkerwell Is Here!
  • How to use WebSocket in NextJS App router with Socket.IOHow to use WebSocket in NextJS App router with Socket.IO
  • How to Set Up Queue Jobs in NextJS Using BullMQHow to Set Up Queue Jobs in NextJS Using BullMQ
  • Boost Laravel Performance: Running Octane with FrankenPHP in Production ( Zero downtime)Boost Laravel Performance: Running Octane with FrankenPHP in Production ( Zero downtime)
  • How to Set Up NextJS cron jobs without VercelHow to Set Up NextJS cron jobs without Vercel
  • Mastering Laravel Streamed Responses: Boost Performance with Fast Data DeliveryMastering Laravel Streamed Responses: Boost Performance with Fast Data Delivery
  • Tinkerwell Alternative: Free and Open-Source PHP Debugging with TweakPHPTinkerwell Alternative: Free and Open-Source PHP Debugging with TweakPHP
  • Nextjs 14 roles and permissions (RBAC) : Step-by-Step GuideNextjs 14 roles and permissions (RBAC) : Step-by-Step Guide

Get updates directly to your inbox.

Join 500+ developers getting updates on Laravel & Next.js tips. No spam,
unsubscribe anytime.


Share this article:

193 views