Setup! PhpStorm + git

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

Leave a comment!

  • 2016-10-24 weaverryan

    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!

  • 2016-10-24 Terry Caliendo

    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 :)

  • 2016-10-24 weaverryan

    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!

  • 2016-10-22 Terry Caliendo

    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)?

  • 2016-10-22 Terry Caliendo

    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?

  • 2016-10-21 weaverryan

    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/scree....

    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...

    I hope that helps - let me know if it does/doesn't!

    Cheers!

  • 2016-10-20 Terry Caliendo

    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).

  • 2016-09-26 Victor Bocharsky

    You're welcome, it's really a little known fact.

  • 2016-09-26 Maksym Minenko

    Thanks a lot for this EAP advice. I've never heard of it before somehow. :)

  • 2016-09-26 Victor Bocharsky

    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.

  • 2016-09-26 Maksym Minenko

    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.

  • 2016-08-04 Victor Bocharsky

    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!

  • 2016-08-03 3amprogrammer

    Why we had to change 'app' for 'var'?

  • 2016-07-04 keiosweb

    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 :)

  • 2016-04-29 weaverryan

    Awesome - enjoy!

  • 2016-04-29 BondashMaster

    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.

  • 2016-04-29 weaverryan

    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?

  • 2016-04-28 BondashMaster

    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.

  • 2016-04-24 weaverryan

    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!

  • 2016-04-24 Favian Ioel

    What OS do you use , I guess is Mac but in some tutorial I saw the title of the terminal was Ubuntu .

  • 2016-03-24 Hermen

    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.

  • 2016-03-17 weaverryan

    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/articl....

  • 2016-03-17 Andrew Grudin

    Which UNIX-like terminal for Symfony development would you recommend?

  • 2016-03-14 weaverryan

    Hmm, that *is* weird! But yes, Atom is a great editor to o- I'm glad there are good packages for Symfony & Twig! Cheers!

  • 2016-03-12 Eddy de Boer

    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.

  • 2016-03-08 weaverryan

    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!

  • 2016-03-07 Andrew Grudin

    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!