index.php<\/strong> file, which will serve as the homepage.<\/p>\nIn this example, let\u2019s keep it simple. I will just print the PHP info table.<\/p>\n
\r\n<?php \r\n phpinfo();\r\n<\/pre>\nYou can now run the following Docker command to start the site:<\/p>\n
\r\ndocker run -v $PWD:\/app\/public -p 80:80 -p 443:443 -p 443:443\/udp dunglas\/frankenphp\r\n<\/pre>\nThis command mounts the current directory to the \/app\/public<\/code> directory in the Docker container and maps ports 80<\/strong> and 443<\/strong> from the container to the host machine, as well as 443\/udp<\/strong> to enable HTTP3.<\/p>\nCaddy also generates SSL certificates and loads the site over HTTPS. However, your browser won\u2019t recognize the SSL certificate for localhost, so you will receive an error when you load the site.<\/p>\n <\/figure>\nThere are a few ways we can create a workaround to let HTTPS load on localhost. The easiest and quickest method that works in different scenarios is to enable the flag in Chrome at chrome:\/\/flags\/#allow-insecure-localhost<\/code>. Restart Chrome, and then reload the page.<\/p>\n <\/figure>\nNow, your localhost runs on the FrankenPHP server API. If you inspect the response in Chrome, you\u2019ll see that it\u2019s compressed with zstd and served through HTTP3.<\/p>\n
It\u2019s impressive that we can have it running with just a single command.<\/p>\n
Running a Framework<\/h4>\n FrankenPHP is not limited to just running a simple PHP file. It is compatible and can run a full-fledged PHP framework such as Symfony, Laravel, or any other PHP framework. The only thing you need to do is mount the framework directory to the \/app\/public<\/code> directory in the Docker container. For example, to run a Laravel application, you can run the following command:<\/p>\n\r\ndocker run -v $PWD:\/app -p 80:80 -p 443:443 -p 443:443\/udp dunglas\/frankenphp\r\n<\/pre>\nIt\u2019s that simple. FrankenPHP will automatically detect the files and serve the Laravel application.<\/p>\n <\/figure>\nWrapping Up<\/h4>\n All these features like automatic SSL, HTTP3, and modern compression make developing and running PHP applications much easier and faster. If you\u2019re coming from nginx or Apache, like me, the only thing you need to get used to is the Caddyfile configuration. But once you get accustomed to it, you\u2019ll find it much simpler and more powerful than traditional web server configurations.<\/p>\n
I think FrankenPHP is a great choice for modern PHP applications. It\u2019s fast, scalable, and easy to use. I highly recommend it for any PHP developers looking to give it a try.<\/p>\n
The post Introduction to FrankenPHP<\/a> appeared first on Hongkiat<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"FrankenPHP is a new PHP runtime designed to modernize PHP architecture. It is built on top of Caddy, and it includes Caddy\u2019s built-in features such as automatic SSL, native support for HTTP3, and Early Hints. It also supports compression methods like Gzip, Brotli, and Zstd. Additionally, it features a built-in Mercure hub, enabling real-time push […]<\/p>\n","protected":false},"author":1,"featured_media":421,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/415"}],"collection":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/comments?post=415"}],"version-history":[{"count":3,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":427,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions\/427"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media\/421"}],"wp:attachment":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media?parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/categories?post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/tags?post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}