Chapters
Setup! PhpStorm + git
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
I've already opened the project in PhpStorm. It is by far the best editor for working with Symfony. And I'm not even getting paid to say this! Though, if there are any PhpStorm employees watching, I do accept payment in ice cream.
Anyways, it's awesome, but not free, but totally worth it. It has a free trial: so go download it and follow along with me.
The PhpStorm Symfony Plugin
To get really crazy, you'll want to install the amazing, incredible Symfony plugin. This thing makes Symfony development so absurdly fun, I'm going to walk you through its installation right now.
In Preferences, search for Symfony and click the plugins option. From here, click 'Browse Repositories` and then find the Symfony Plugin. You'll recognize it as the one with over 1.3 million downloads.
Tip
You should also find and install the PHP Annotations plugin. That will give you the awesome annotations auto-completion that you'll see in the video.
I already have it installed, but if you don't, you'll see an Install Plugin
button. Click that and then restart PHPStorm. Once you're back, go into Preferences again and search for Symfony to find the new "Symfony Plugin" item. To activate the magic, click the "Enable Plugin for this Project" checkbox. Do this once per project. Oh, and also make sure that these paths say var/cache
instead of app
.
Go Deeper!
If you're interested in more PHPStorm tricks we have an entire screencast on it for you to enjoy.
Starting the git Repository
Ready to code? Wait! Before we break stuff, let's be good developers and start a new git repository. Our terminal is blocked by the built-in web server, so open up a new tab. Here, run:
git init
git add .
git status
The project already has a .gitignore
file that's setup to avoid committing anything we don't want, like the vendor/
directory and the file that holds database credentials. Hey, thanks Symfony! Make the first commit and give it a clever message... hopefully, more clever than mine:
git commit
46 Comments
Hi, at my Symfony plugin settings I see just only "Code Folding" part (time 1:09), but on a movie are more like:
PHP Annotator
PhpTypes Resolver
Twig Annotator
I have installed PHP Annotations.
What should I do to see all parts?
Hey Pablo
Which version of PhpStorm and Symfony plugin are you using? I think you only need to ugprade it, if that's not the case, let us know!
Cheers!
I'm using PHPStorm 2017.2.4 and Symfony Plugin 0.14.155.
I'm working on Lubuntu 16.04 LTS.
Looks like on picture below:
http://123.sax.pl/tmp/symf.png
Hmmm, interesting. Try re-installing Symfony's plugin, if it doesn't work, I think you have to install Twig Support and PHP Annotations too
Still the same...
Twig Support and PHP Annotations already installed :( Have no idea.
Maybe I just need only "Code Folding"? How can I verify that
PHP Annotator
PhpTypes Resolver
Twig Annotator
actually works with Symfony? Maybe not on a list but work?
That's weird, maybe you would like to open a ticket to Symfony's plugin community.
The best way to know if it works, is trying it out :)
Check if you have autocompletion when linking paths in your twig templates. Autocompletion when fetching a service through Controller's get method, and things like that
Is this plugin? https://plugins.jetbrains.c...
Hey Sebastian R.
Exactly, Cheers!
Hmmm - loaded symfony 3.4.3...
Directories don't look anything like the description here... and it runs as advertised.
Mine looks like this
-bin
-composer.jason
-composer.lock
-config
phpunit.xml.dist
public
src
symfony.lock
templates
tests
translations
var
vendor
No APP!
Hey T. Wagner,
Yes, the new version of Symfony 3.4.3 might look a bit different, that's why we recommend you to download the course code and code along with us starting from "start/" directory. Then you will have the exact code that we have in the screencast.
Cheers!
"[PHPStorm] is by far the best editor for working with Symfony", but it is not Open Source and uses a subscription license... I think I pass for now and try the Eclipse PDT first...
Hey Dion,
You can try their Early Access Program that have trials: https://www.jetbrains.com/p... - I hope it helps you. But if you're working every day with PhpStorm - buying license worth it IMHO.
Cheers!
Hi there,
I wanna ask you a general question.
This symfony's track is about realizing websites for educational purpose.
After setting up PhpStorm and git and creating the project, what are your steps which you use when you realizing real websites in symfony??
Thank you.
Hey Mehdi,
Yes, for educational purposes and mostly tutorials are focused on a specific set of topics, but actually this is exactly what you do when developing a real project (you just can have more topics in your project at once). Well, first of all, you need to get a project specification, i.e. what features your project should have. Then, you need to prioritize them - you'd probably want to start with most important features, i.e. with a basic set but constantly improve them. Also, there're a few "hipster" methodologies like TDD and BDD, when you write tests first and only then write code. You can take a look at our new PHPUnit course when we show what' TDD in practice: https://knpuniversity.com/s... and Behat course if you wonder about BDD: https://knpuniversity.com/s... .
But in general, the process *is* the same we show in our screencasts. First of all, you need to have a task with described feature you're going to implement. And then, if you like TDD/BDD, you write a test and then write code to pass the test. Then just repeat the same for a new feature :)
Cheers!
Thank you for taking the time to write this wonderful answer!
I go with using TDD.
My windows terminal (cmd) doesn't swallow ( git init ) command. May be there is a slightly differet analog command for windows,
or have I to use UNIX-like terminal for starting the git repository ?
Best regards!
Hey Andrew!
You nailed the issue :). First, you can of course download a GUI if you'd like to handle your git repository. GitHub itself has one that's very nice. OR, yes, you can use a UNIX-like terminal. For whatever reason, when you install git itself on Windows, it comes with a "Git Bash" utility that is *awesome*. I usually recommend that Windows users try this out. In general, having a UNIX-like terminal for Symfony development will help a lot - commands will work as expected and you'll get cool terminal colors :D.
Cheers!
Which UNIX-like terminal for Symfony development would you recommend?
protip: get yourself cmder with git support (the full version). I used it for a very long time when I had to use Windows laptop to manage my servers and projects during travels. But hey, there isn't much to tell, http://cmder.net/ visit their website and check the screenshots :)
I like "Git Bash" the best, simply because it's "great" and it's so easy to install: just install "Git" and you automatically have it. The GitHub article about install git references the "Git Shell" utility: https://help.github.com/art....
What OS do you use , I guess is Mac but in some tutorial I saw the title of the terminal was Ubuntu .
Hi Favian!
You have a really good attention to detail - I'm impressed :). My OS *is* a Mac. If you see Ubuntu (or something else) in my terminal tab, it's because I ssh'ed to an Ubuntu machine before recording the tutorial, and (for some reason) that title "sticks" even after I exit from ssh.
Cheers!
I could not get the Symfony autocompletion working in phpstorm (checked all settings like a billion times).
I tried atom editor (atom.io) with the following packages: atom-autocomplete-php, atom-symfony2, php-twig; this worked like a charm.
Hmm, that *is* weird! But yes, Atom is a great editor to o- I'm glad there are good packages for Symfony & Twig! Cheers!
Hi there, I am on windows machine , i installed everything and downloaded phpstorm trial version. I put my project in , trying to follow with video but i cant find section PHP Storm which includes option Preferences in order to set plugins we will use in this course.
Hi Lazar!
Welcome! Under Windows, I believe you should go to "File" -> "Settings" - like in this screenshot: https://i.stack.imgur.com/n...
Does that help! A few things *are* different in PhpStorm between Mac and Windows. I try to explain these differences a bit more in our phpstorm tutorial: http://knpuniversity.com/sc...
Let me know if that helps!
Cheers!
I got the phpstorm and mark dracula theme, mark the symfony plugin but my colors are distinct. I would like to have the same as the tutorial to know Im coding properly.
Hmm, that's odd - I also use the darcula theme that comes standard with PHPStorm, and I haven't made many changes. How "different" does your's look? What operating system?
I got it. I compare the Script photos with my code in PhpStorm instead of comparing with the ones in the video. They match with the ones in the video. Thanks.
Awesome - enjoy!
Is there a tutorial on how to develop locally and then deploy to a server? I run a CentOS 6 LAMP server. I can't develop on the server as everything is done via command line (ie there's no graphical user interface to use PHPstorm on).
Hey Terry!
You're absolutely right - you probably don't want to actually develop up on your server (some people actually do do this, but it's not totally normal, and it requires setting something up, for example, that auto-syncs up to your server on save, so that you can have the files locally). A better setup is to develop locally (or perhaps locally inside a virtual machine) and then deploy your code up there.
How to deploy? We actually don't have a (recent) tutorial on this, in part, because it's a changing area and there are so many potential tools, options, or even services! But, I do have one older tutorial, which still covers the essential steps - it's for Symfony 2, so a few minor things have changed: http://knpuniversity.com/screencast/symfony2-ep4/deployment.
But, the essential deploy steps are pretty simple:
1) Get your code up to the server (there are several valid ways to do that)
2) Install your composer vendors
composer install --optimize-autoloader
(the extra flag here is a small performance boost)
3) Clear your cache and maybe execute doctrine migrations
bin/console cache:clear --env=prod
bin/console doctrine:migrations:migrate --env=prod
... and that's about it! Here on KnpU, even to this day, we use a simple shell script to do execute all of this (which is kind of crazy, but it still serves us well enough that we haven't changed it yet)/. We also use platform.sh for some of our services - which is a nice way if you don't like to manage your servers.
Also, the official Symfony guide on this is also good - it'll give you some similar information: http://symfony.com/doc/current/deployment.html#common-post-deployment-tasks
I hope that helps - let me know if it does/doesn't!
Cheers!
I guess my issue is that I work on a Windows machine and my server is Linux. Thus, if I develop locally on a Windows machine and upload to Linux production, I may have errors related to the differences in OS (for instance, say I forget to use PHP_EOL or call a filename where the directory or name causes issues on Linux that isn't a problem on Windows, or maybe the PHP version is different... I don't have a great example, but hopefully you get the idea). That has to be common, and I'm curious if you know what people are doing?
Yo Terry!
About your first question (summarized):
> If I copy all my files, why would I need to run Composer?
You're absolutely right :). If you copy *all* of your files, then you don't need to run composer. But if you, for example, did a "git clone" or "git pull" on your server to get all the files... then you actually *won't* have the vendor directory, because it is ignored by git. Sorry about the confusion - the real answer is "it depends" :). It's of course always safe to run "composer install" - if all the files are already there, Composer won't try to re-download them.
Next! About your developing on Windows versus deploying on Linux concerns. There is definitely some truth to this, but it might be as big of a concern as you think. I actually never use PHP_EOL - so it might be something needed in Windows for some things (I'm a bit ignorant about this), but it's probably not something that you'll need to worry about too often. And for directories, just make sure you always use the "/" directory separator - PHP is smart enough to turn that into "\" on Windows, I believe. So, in general, there really aren't that many differences in PHP land. That being said, you do still need to worry about the same issues that anyone worries about. For example, I develop on a Mac and deploy to Linux (so, similar systems, but not identical). And while I'm not worried about any EOL type of things, I *do* need to make sure that I have similar PHP versions installed locally and on my server, and that both machines have the proper PHP extensions that I'm using, etc.
There's not one solution to all of this... because honestly... there are so many different ways to deploy and to build your servers (we have a tutorial on Ansible coming out soon, which you can use to make sure your servers are built perfectly and have all the right things installed). The best thing to do might be to at least have a staging/beta deploy where you can test things before sending them to production. This would be either a server that you can reasonably make sure is "identical" to production, or just another directory / virtual host on the same server (a lot depends on how "big" your infrastructure and traffic is - we honestly still have staging & production on the same 1 server).
Ok, I'll end my babbling. Let me know if you have more questions - happy to help - it's a wide open area, hence my long answers... :)
Cheers!
Thanks for the help. Did you do any tutorials on git? After I get a hang of Symfony I'll need to learn more about composer and git :)
Hey Terry!
We don't have a tutorial on git here... but that's partly because this one is so good already: https://try.github.io :)
Learning all these tools is a long road, but a good one - and one that'll serve you in the future no matter what you find yourself doing. So, keep it up!
Cheers!
Also.. in step 1) you say to get your code up to the server, then step 2) is to install composer vendors. Won't all the files composer already be installed if I just copy my entire folder structure from my local machine to the remote server? I'm new to Composer so I must be missing something... will it find files that are more specific to the server (ie if the PHP version is different)?
As far as I know, JetBrains has some educational licenses. Have you tried to negotiate those? :)
P.S. Personally I find Netbeans (after some tweaking) more than enough as an ide. Maybe not the fastest one, but at least it's free.
Symfony 3 support is out of the box -- no need to install additional plugins at all.
Hey Maksym,
JetBrains has educational licenses for real classes but not for online education. Actually, NetBeans is a good IDE too, probably it not so good working with Symfony as PhpStorm. I'd give the 2nd place to it after PhpStorm.
P.S. PhpStorm EAP is free, you just need to update it each month to the newest beta version.
Thanks a lot for this EAP advice. I've never heard of it before somehow. :)
You're welcome, it's really a little known fact.
In the portion of the video where you're setting up the Symfony Plugin, you unclick the checkbox for Code Folding/Template (Twig). This occurs just after you change the paths from app/ to var/ (around the -0:43 mark). Is this intentional? If so, why?
Hey rebatch!
Woh, nice catch! This was totally an accident - I was getting a little crazy with my clicking :). To my knowledge, nobody has noticed before - so you have good eyes :). So, there was no reason for this - code folding of all types is just fine :) (though sometimes, it can surprise beginners).
Cheers!
Why we had to change 'app' for 'var'?
Hey,
Because of new Symfony 3.0 directory structure. In this video, Ryan uses Symfony 3.x, where "cache/" directory lives in "var/" instead of "app/". If you use old Symfony structure - keep it as is! In fact, you just need to specify a valid relative path to the cached "translations/" directory and "appDevUrlGenerator.php" file in your project, that's it!
Cheers!
"Houston: no signs of life"
Start the conversation!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.1.*", // v3.1.4
"doctrine/orm": "^2.5", // v2.7.2
"doctrine/doctrine-bundle": "^1.6", // 1.6.4
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
"symfony/swiftmailer-bundle": "^2.3", // v2.3.11
"symfony/monolog-bundle": "^2.8", // 2.11.1
"symfony/polyfill-apcu": "^1.0", // v1.2.0
"sensio/distribution-bundle": "^5.0", // v5.0.22
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
"incenteev/composer-parameter-handler": "^2.0", // v2.1.2
"composer/package-versions-deprecated": "^1.11" // 1.11.99
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.0.7
"symfony/phpunit-bridge": "^3.0" // v3.1.3
}
}
Top tip: If you haven't installed it yet, also install the plugin 'PHP Annotations' for the autocompletion in annotation and auto-inserting use statements for classes in the annotations. I thought this was a feature of the Symfony Plugin, but it seems it is not.