Chapters
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
With a Subscription, click any sentence in the script to jump to that part of the video!
Login SubscribeI have a wild idea. Let's deploy this site for real.
AssetMapper Deploy Requirements
You can deploy your code however you want... using any service or web server. It doesn't matter with AssetMapper. The only requirement is that your web server supports HTTP/2 so that our assets - the JavaScript and CSS files - can be downloaded in parallel super fast. HTTP/2 is the reason why it's not terribly important that our files aren't being combined to minimize requests.
All web servers - nginx, Caddy, whatever - do support HTTP/2. Or you could add Cloudflare or a similar service in front of your site which gives you this for free... along with some other benefits.
platform.sh Config File Setup
Anyway, we're going to deploy with Platform.sh, which is a "Platform as a Service". That means we can deploy just by creating a few config files. And this first section is all about getting that set up. Once we're done, we'll talk about some specifics of deploying with AssetMapper.
So, let's get started! We're going to do most of this in the command line with the Symfony binary. Start by running:
symfony project:init
This bootstraps a few platform.sh files, which you can see right here. .platform.app.yaml
contains instructions for how to deploy - like which commands to run, what version of PHP to use, web server configuration and more. services.yaml
is where you set up the services you need - like databases, queues, etc - and routes.yaml
sets up your domains, and is a bit less important. Oh, and you can also add any custom php.ini
config with this file.
I've been committing my progress along the way. So when I run
git status
it just shows these new files. Let's commit these and... great!
Registering the platform.sh Project
Now that we have those local files, we need to dial up the folks at platform.sh and tell them that we want to create a new project. We'll do that with:
symfony cloud:project:create
I already have some projects under Platform.sh.... which means I already have an organization... and it already has my credit card. Thieves! If you're doing this for the first time, you'll have a few extra steps.
Give your project a title, select a region - I'm using "eu-5" - and then it asks which branch will be your production environment. I'm using the default main
branch.
Next, it asks if we want to set "Mixed Vinyl" as the remote for this repository. This is kinda cool because it exposes how platform.sh works. To deploy with platform.sh, we actually push our git repository to a remote repository on their services. They see this, take the code, and deploy!
Anyway, I'm going to say "no" - but you can say "yes". Because I'm saying no, you'll see me do this manually in a minute - and I'll explain more about it.
Finally, it asks to confirm pricing. This $12 USD per month is the developer rate that you can pay to play around with stuff. It will be more expensive when you decide to deploy your site to production for real. I love platform.sh because of how easy it makes my life, but there are cheaper options.
This will take a minute or two to set everything up behind the scenes. When it finishes... ding! We get some info, including the new Project ID.
Side Note: There is also a web interface on Platform.sh, so not everything needs to be done via the command line. But, yea know, nerds like me prefer the command line.
Linking the Local Code to the Remote Project
Copy the Project ID. At this point, we have some local config files - like .platform.app.yaml
- and we created a new "project" on platform.sh. But the two aren't linked together yet: our local code doesn't know that it "belongs" to this project up on platform.sh.
To link them, run
symfony project:set-remote
and paste the Project ID.
Our First Deploy
Done! Ready to deploy? Do it with:
symfony deploy
We're currently on the "main" branch, so it's pushing to, basically our "production" machine, which is called an environment. One of the coolest parts of platform.sh is that you will deploy your main
branch to the "production" environment, but you can also deploy other git branches to other platform.sh environments, which you can think of as other platform.sh servers.
Anyway, as I mentioned, behind the scenes, this command is just a shortcut to git push
our branch up to a git remote on the platform.sh servers. And doing that kicks off the deploy!
Oooh, this looks fancy and geeky. Tons of details here, including a warning about using an old version of Composer. We'll fix that in a minute. Down here, we see that it's running symfony composer install
and doing some other steps: all the basic stuff you need to deploy any Symfony app.
At the bottom, it gives us an SSL certificate, and if we keep scrolling... oooh, we have a message about a database error! Ignore that for now because... when it finishes, it gives us a URL!
Because we haven't configured any domains for the site, it gives us a temporary URL. Copy that, spin over and... our site is alive! It doesn't have any styling... since we haven't talked about AssetMapper, but it at least kinda works!
But how? How did it know to run composer install
and those other things? What about that Composer warning and the database error? Let's dive into all of that next.
17 Comments
Hey @giorgiocba ,
Are you on Windows OS? Hm, instead of dealing with the ucsto PATH config it might be so that you need to install the Platform.sh CLI in an official way first: https://docs.platform.sh/administration/cli.html . I bet if you get that installed properly first, then symfony cloud:project:create
also should work well for you.
But I would recommend you using WSL with a native Linux installation, then such commands should work much stable. I've never executed those on Windows, so it's hard to tell what else you can do.
I hope that helps!
Cheers!


Thank you very much for your suggestion. I'm actually running Windows 10, but I have WSL installed. I'll try the deployment again now.
Yeah, on WSL it should do the installation of the Platform.sh CLI in the background without problems or needed changes.
Cheers!


Hi all and thank your for pointing me to Platform.sh. I'm currently scouting it and (my own mistakes aside) it's really as simple as in the video (even without either the Symfony CLI or the Platform CLI!).
But what bugs me right now is the time it takes to build webpack stuff. Nearly on every new commit, (aside from pure platform.sh configuration) the whole build process is executed, even when there are no changes to the JS. Is there any way to cache the build, maybe by using a mount? Right now (in the free trial dev tier) a deployment takes about five minutes or so (which gets annoying when playing around with environment variables). I'm using the standard symfony build hook.
Hey @Manuel-B!
Sorry for my slow reply!
Is there any way to cache the build, maybe by using a mount?
You should try Asset Mapper ;). But to actually answer your question, the last time I asked this, no, there wasn't a built-in "build cache". But, it would be worth asking them again via support or on their Slack channel.
I agree with you that the Webpack builds on deploy can be annoying (and funnily enough, I know that platform.sh doesn't like them either - it takes resources, so everyone would be better off if they were cached). I think, to accomplish this, you'd need to write something by hand :/. There is a concept of mounts, which are directories that are shared across deploys. So, in theory, you could create some sort of a checksum of the assets/
directory and the package-lock.json
and use that as your own personal "cache" key - e.g. looking for /some/directory/cached_assets/{key}
. And if it's present, copying that to public/assets/
and skipping Encore. Else, build Encore then copy into the cached dir.
Unfortunate that there is, I believe, nothing built-in. But it does seem possible :).
Cheers!


Hi Ryan!
Thank you for sharing your ideas with me, they have sent me on an interesting journey of how to build a JS build cache and dash. Yet another learning experience for me. :)
In the end, my trials unfortunately failed, because the mounts are not available during build time. I'll keep digging (and asking) and I'll share my solution here, if I find one.
That being said, switching to Asset Mapper is already on our todo, it's just a matter of time. :)


The answer is quite simple, now that I know about it. Thanks to Chad from Platform.sh for pointing me to the solution!
There is variable called "PLATFORM_CACHE_DIR" that is available during build time for all your environments (see list of available variables). And that just does the trick. :)
This is fantastic! I didn't know about PLATFORM_CACHE_DIR
. I think we may use it also, just to speed up the build part of the deploy. Super cool!
Hi all, I've an old symfony 3.4 project that I would like to rewrite with the recent symfony 6.4, but this used the 'smart admin' theme which used dynamic loading via ajax of contents, with the window.location library and use of hashes. Do you think the hotwired system could be a valid substitute?
Hey @pasquale_pellicani!
Sorry for the slow reply - holidays!
but this used the 'smart admin' theme which used dynamic loading via ajax of contents, with the window.location library and use of hashes. Do you think the hotwired system could be a valid substitute?
Hmm. I want to say yes - but I'm not familiar with this "smart admin" theme system. But, generally-speaking, that does sound a lot like what Turbo offers: changing the URL on click, ability to AJAX-load contents.... it's all there.
Anyway, that's a weak answer - so let me know if I can offer more details :).
Cheers and happy 2024!
Sure, I take this opportunity to ask another question, but is this topic of the turbo and the hotwire very new ? I have had to search around for information or even pre-made templates but without success. Thank you
Hey again!
but is this topic of the turbo and the hotwire very new
Fortunately, no. Both Turbo and Stimulus are about 10 (yes 10!) years old. Though the most recent version of both was released 2-3 years ago, and that's when the Symfony world starting using it. It also started to grow more popular and get more features around then.
I have had to search around for information or even pre-made templates but without success. Thank you
This is an interesting statement. There are many pre-made Stimulus controllers - e.g. - https://www.stimulus-components.com/ - but no central place to find them... and no place to really find pre-made HTML markup + Stimulus controllers. Only moments ago, I was chatting about this with someone else - https://symfonycasts.com/screencast/last-stack/tailwind#comment-31337 - I would be interested what you think about my idea at the end.
Cheers!
thank you very much for the answers, at this point the question comes naturally, why choose stimulus/turbo and not react or vue js? I would like to understand the pros and cons between the two choices. ^_^
Hey Pasquale,
Choosing between Stimulus/Turbo and frontend frameworks such as React or Vue.js depends on the type of application you're building, the complexity of the features, and your personal preferences among other factors. Here're some ideas that I believe will help you to understand the diff:
Nature of the application: If you plan on building a Single Page Application (SPA), React or Vue might be the go-to choice as they are specifically designed to create rich interactive user interfaces with complex state handling. They allow you to return JSON from your server and build HTML 100% in JavaScript. On the other hand, if you prefer apps that primarily returns HTML from the server, Stimulus and Turbo might be a better option.
Use of existing technologies and best practices: Another reason to choose Stimulus/Turbo is if you have a preference for certain backend technologies or wish to make use of existing tools and best practices. The context mentions liking PHP, Symfony, and Twig and points out the various tools Symfony provides, like form handling and CSRF protection. If you've been building traditional server-rendered apps, then there are a plethora of tools you're familiar with that can speed up your development process.
Avoiding Full Page Refreshes: Stimulus and Turbo give you the option to create a SPA-like experience by avoiding full page refreshes without having to create an actual SPA. Turbo allows your applications to load every link click and form submit via Ajax, giving fluidity to the user experience.
Complex Features: React and Vue.js still have a place even if your application primarily returns HTML from the server and use Stimulus. If you have a particularly complex feature or widget to build on your site, React or Vue might just be the best tools for the job. They do well when complex interactivity and state management comes into play, and those components can fit perfectly into Stimulus.
Ultimately, the choice depends on your project requirements, the kind of user experience you're intending to deliver, where you want to handle most of your app’s logic (client side or server side), and personal preference.
You should add the +100 thumb below, it was the answer I was looking for, thank you all so much for the precious info ^_^
Hey Pasquale,
I'm happy to hear that comment was useful to you. I highlighted that comment, hope it will be useful for other users too :)
Cheers!

"Houston: no signs of life"
Start the conversation!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^4.0", // v4.2.0
"doctrine/doctrine-bundle": "^2.7", // 2.10.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.4
"doctrine/orm": "^2.12", // 2.15.2
"knplabs/knp-time-bundle": "^1.18", // v1.20.0
"pagerfanta/doctrine-orm-adapter": "^4.0", // v4.1.0
"pagerfanta/twig": "^4.0", // v4.1.0
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.1
"symfony/asset": "6.3.*", // v6.3.0
"symfony/asset-mapper": "6.3.*", // v6.3.0
"symfony/console": "6.3.*", // v6.3.0
"symfony/dotenv": "6.3.*", // v6.3.0
"symfony/flex": "^2", // v2.3.1
"symfony/framework-bundle": "6.3.*", // v6.3.0
"symfony/http-client": "6.3.*", // v6.3.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "6.3.*", // v6.3.0
"symfony/runtime": "6.3.*", // v6.3.0
"symfony/stimulus-bundle": "^2.9", // v2.9.1
"symfony/twig-bundle": "6.3.*", // v6.3.0
"symfony/ux-turbo": "^2.9", // v2.9.1
"symfony/web-link": "6.3.*", // v6.3.0
"symfony/yaml": "6.3.*", // v6.3.0
"twig/extra-bundle": "^2.12|^3.0", // v3.6.1
"twig/twig": "^2.12|^3.0" // v3.6.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.4
"symfony/debug-bundle": "6.3.*", // v6.3.0
"symfony/maker-bundle": "^1.41", // v1.49.0
"symfony/stopwatch": "6.3.*", // v6.3.0
"symfony/web-profiler-bundle": "6.3.*", // v6.3.0
"zenstruck/foundry": "^1.21" // v1.33.0
}
}
Hi
I'm trying to run this chapter from the project root:
symfony cloud:project:create
but I get the following error:
Downloading Platform.sh CLI version 5.2.0 0% |
and then:
executable file not found in %PATH%