Over years, Symfony has consolidated its position as the preferred development framework for PHP projects. With the recent release of Symfony Flex, the framework is now in a great position to help developers launch RAD enabled apps quickly.
At Cloudways, we try to facilitate Symfony developers in launching their projects without worrying about the hassles of server management. Our about-to-be-released Content Delivery System (CDN) is a continuation of this commitment. In this article, I will go over the process of enabling and configuring Cloudways CDN for your Symfony applications.
- Cloudways server with PHP application
- Symfony installed on the server (or Symfony Flex enabled application)
- Your domain should be mapped
You might also like: Install Symfony 4 On Cloud
You can follow the following GIF to launch a server and a PHP application on Cloudways. By default, you will get PHP 7.0; however, you could downgrade or upgrade to PHP 5.6 or 7.1.
First of all, let’s talk about CDN, and why you need to integrate it into Symfony projects.
What is CDN ?
A CDN is a system of multiple servers which delivers static content (such as text, images) to the users. Instead of serving the static content from the original server, a CDN ensures that the user is served the data from the nearest location (a.k.a., points of presence, or PoPs). Each PoP contains a number of caching servers responsible for content delivery to visitors within its proximity.
Why CDN is Necessary?
CDN ensures speedy delivery of content, thus improving the speed of websites and web apps deployed on any PHP MySQL Hosting. When a CDN is active, the actual location of the website does not matter. The CDN ensures that the visitor receives the data from the nearest location. Since Symfony is well known for powering fintech and ecommerce applications, CDn plays a central role in speeding up the user experience.
Enable CDN for PHP Apps on Cloudways
When you login to your server, move to the Application tab and open the PHP application. You will see the tab for configuring CDN at the end of the options. When you click the tab, you will enter the CDN configuration screen. Here you will find the URL of the application to be inserted in the WEBSITE URL field and click the Create button.
Next you will get the newly generated URL for you Symfony application:
Few things to note here:
- You can view the bandwidth usage on this screen.
- You can always purge old content from CDN by using the Purge button.
- You can always remove your subscription anytime.
Integrate CDN URL in Symfony Assets
Symfony provides easy configuration options for CDN services. If you know about `base_url`, you are good to go. In the standard Symfony installation, move to `app >> config` and open config.yml.
You need to find the asset settings in framework configs. Since our CDN is asset based, I will concatenate on the CDN Url as base_url to every asset file in Symfony.
framework: assets: base_urls: - 'https://3971-7889-2-raikfcquaxqncofqfm.stackpathdns.com/'
Now clear your cache by running `rm -fr var/cache/*` and check your Symfony application asset URL’s:
If you are using Symfony Flex for application management, then in your project folder, move to `config >> packages` folder and open framework.yaml file. Add the same asset config as shown above.
Cloudways have partnered with StackPath (formerly known as MaxCDN) and provide one-click activation for the Cloudways CDN. Note that, for a single website, the Monthly Subscription costs $1 per 25GB of bandwidth. You can avail this for any PHP website and framework based application.