How to Customize FrankenPHP
Posted By
kamlesh paulon
Dec 18, 2024In 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
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:
To add libraries enabling additional functionality to the extensions you’ve enabled, you can pass use the PHP_EXTENSION_LIBS
Docker ARG:
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()
andset_time_limit()
functions. For example:
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
Copy FrankenPHP binary
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.