Monday, November 12, 2012

Tools #3: Ditto clipboard manager, the ultimate tool in your pocket

Whether you admit it or not, it doesn’t change the fact that the most frequent operation on our PC is in a way or another copy/paste. I copy and paste all the time: code snippets, files, links, you name it.

The problem with copy pasting is that it is one way ticket, you can’t go back and browse all your copy and paste history, search through it and find everything you copied or pasted.

Ditto is the tool that solves all your problem and it does that in such a way that you don’t even observe that it exists on your laptop or other devices. In short, Ditto is a clipboard manager that is managing all your copies and pastes, the number of occurrences it keeps in the SQLite database is configurable. I always have there a 1000. It is relatively good handled by the DB when you do searches, and it is a big enough number for keeping your most important recent copies and pastes.

ditto_1

I also like that it contains files and even tables from Excel or Word, that is pretty cool.

2012-11-12_0005

You call that by pressing Ctrl + ~

This way when you want to copy and paste multiple snippets of code, you don’t need to switch between the editors, just copy, copy, copy and than paste, paste, paste, and when you are not sure what you should paste use the search feature.

P.S. There are some problems in Windows 8 interactions with Ditto, in short there were made fixes in beta branch and there is a download for windows 8, here you can find the corresponding thread: http://sourceforge.net/p/ditto-cp/discussion/287511/thread/2d4c8635

Thank you, and I hope you all will have this great tool in your belt, and it will save you a lot of time.

Friday, October 5, 2012

What is cron and how to configure it with Drupal (secure) on a shared hosting

I can’t name myself a heavy Linux user developer, I don’t know by heart hundreds of commands, but recently I had to setup a hosting for NetBeans PHP Community Council. You can read my post about it at NetBeans PHP team blog. And I needed to setup cron to make my notifications in Drupal works.

So what is cron? Shortly cron is a time based job scheduler that allows you to run certain bash scripts in a certain frequency. What could we do with it? Well, a lot, think of email sending or verifying a certain flag in a web service, cleansing the database, you name it.

explaining cron configuration: CRONTAB

So cron has a configuration file: crontab, it describes the frequency at which the job runs and also the script that describes what will actually be done.

If you are in command line you can access crontab by typing

crontab -e

this will open the configuration file in your default Unix editor, usually vi.

FREQUENCY DESCRIPTION

Ok so how we describe frequency, there are 5 stars, which by default are placeholders. A star means ‘every’

* * * * *

Ok so what all these start mean

*  - minutes (from 0 to 59)

* hours (from 0 to 23)

* – days of month (from 1 to 31)

* – month (from 1 to 12)

* – day of week (0 to 6)

So the previous example means

* * * * - every minute

* * * * 0 – every Sunday

*/5 * * * * – every 5 minutes

45 * * * * – every hour on 45th minute

15,45 * * * * – every hour on 15th and 45th minute

* * */15 * * – twice a month

I hope you got the idea. Also cron has some predefined values like @yearly, @monthly, @weekly, @daily and others.

CONFIGURE DRUPAL TO WORK WITH CRON

In Drupal we have different moving parts. One of these are notifications, which are very important and even more important in OpenAtrium, Drupal’s flavor. Notifications work with cron. To send all the notifications that are in the queue you can go to your Drupal site’s cron.php script, for example, at http://somedrupal.org/cron.php. At this point you’ll have in your administration panel, Administer –> Reports –> Recent logs, some entries related to cron script.

2012-10-09_2354

Now to make this script run at a certain frequency we’ll need to create a job for it. Drupal’s guide propose to make such an entry in your crontab:

45 * * * * /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php

When you set it up in your crontab –e everything should work fine.

CONFIGURE SHARED HOSTING TO WORK WITH CRON AnD WGET

On my shared hosting solution I hadn’t rights to execute wget command from /usr/bin/wget and my cron failed, so I made a ticket and the guys from the hosting made me a simple copy of wget binary into my /home with all the rights I needed. After that I modified the script from crontab so it could work with my local copy of wget, and everything cron related was working without a single issue from that day.

SECURE ACCESS TO CRON.PHP WITH .HTACCESS

Now that everything works ok, the question is how to configure your site that your cron.php script couldn’t be accessed from the browser. Otherwise anyone could just refresh /cron.php 5 millions time and put a big load on server.

We can avoid it by limiting access to cron.php file via .htaccess file.

  1. Find out your server’s name: use the command  uname –n.
  2. Put the following in .htaccess file
  3. <Files "cron.php">
      Order deny,allow
      Allow from WEBSERVERNAME
      Allow from 127.0.0.1
      Deny from all
    </Files>

  4. Change the WEBSERVERNAME with your own server’s name.
  5. Test that you can’t access the cron.php from browser
  6. Test that the cron job on linux is running and is executed OK.

 

That’s all I wanted to share with you today about cron, if you have any questions or suggestions please write a comment.

Monday, September 24, 2012

TEDx Chisinau NXT LVL #nxtlvl

Hello friends,

TEDxToday I was attending an extraordinary event TEDx in my own town, I must say I’ve never been to a TED event before and hardly imagined what it will be like, but it was an unusual event because pretty much a lot of topics where open-ended points to discuss. We were around 400 attendees with 12 speakers, speaking in 3 languages (English, Romanian, Russian) and pretty much everyone was willing to listen, to learn and to evolve as a personality.

UPDATE: Here are some videos: http://www.youtube.com/playlist?list=PLADJSjJ03wMkNQI_B0ARgzqgO5NZnOtpL

 

 

schedule

Before we get started I’d like to thank everyone involved into organizing this event, and I hope we’ll get many other events related or not to IT, I think communication is the key to get to that next level we’ve kept talking about all day long. Don’t think you’re smarter than someone, but if you got an idea that’s burning you inside out, just make it happen, start by small steps and then it will lead you to some kind of lesson learning.

The bio of all the speakers is on TEDx Chisinau official site: http://www.tedxchisinau.com/speakers/ 

The photos are taken from https://www.facebook.com/TEDxChisinau photos and from Victor Buzu’s FB album.

Elena Pahomova – There will be no  future

An interesting topic for opening of the event – actually the main idea what Elena Pahomova was presenting is that today is the base for our future, we don’t need to wait until it happens with us. Future is happening now, we model it day by day, so we should live as today dreamers, changing something today, living better today, etc. Another good piece of advice for young journalists was “don’t try to chase big money, work for experience, this is why you got here in first place.”

 

 

 

Octavian Ticu – Bankrupt state with elite sport

Octavian Ticu presented a very good info about the idea of meritocracy and that it is mostly applicable to sports, because we know for sure who is the best one there, there are seconds, kilograms, kilometers, etc. He also talked about one little village in Moldova: Grimancauti, this village with a population of 4200 people, gave us (moldovan) 3 Olympic medalists and a lot of champions in box. Also he compared the years when the most progress is done, and these are the years before and after the USSR period in Moldavian history. He also expresses the idea that as a community, as a state we are not yet ready, we don’t have conditions to raise champions in team sports as football, basketball, and others, because the team is a micro community with all its strengths and flaws. This is why we fail in these types of sports. In several words a very good presentation I’d advise you to watch it on YouTube when available.

Onorica Banciu – Get out from the game

Onorica’s insights on our Moldavian budget are very interesting, she indicated several numbers, which seemed very outraged when measuring the price and the value. Getting as an example a simple Moldovan family from a village she presented some of the day-to-day problems and expressed an interesting idea: “Don’t wait until government will give you something, remember when it does, it means that government first took from someone something and than gave that to you”, so basically when you’re doing great, government is putting pressure on your business, when you’re doing bad it will give you some money so you could still be at least on the edge. So don’t get into the game of protesting without changing anything yourself - stop, innovate, create something new and the changes will come. 

Dave Erasmus – Is giving good for you ?

is_giving_good_4_uDave mentioned once again that love isn’t just as simple as a resource, each time you give away love, you’re getting it back. Don’t be afraid of giving something without demanding anything in return, which is the essence of true altruism. As an example on the picture he’s talking about a mother giving everything to her 6 months daughter without getting anything material in return from her. Another idea was that if you have a cause or an idea that you support than getting the funds for that cause is not that complicated, isn’t that complex, just let the people know that you’re passionate about it. Nice talk and a profound one.

Alex Cosmescu – Do you exist ? Really ?

Alex gave the most confusing talk, at least for me. The idea is interesting but not the one that I like, so basically the idea is that life is a union of emotions, feelings, stresses, and many many other things, that we can’t control. Basically life is just happening. And this is why it is not fair to say that you have to suffer more or less than someone else, because life’s just happening want it or not, you can’t change it. Anyway I think this talk enlarged a little bit the common pattern for a TEDx speaker.

 

Eugen Boico – Remix your way into  the future

Once again I loved the presentation. For a beginning artist, designer there is this idea of being unique, that is like a trigger in their mind. But what is the easiest path to express yourself as a creative artist, the answer is simple, that is remix. With loads of data generated every minute on our planet, there is extremely low possibility that you’ve created something unique that was never created before you. But get a piece of art, a track, something that you like a lot, and improve it with your ideas and thoughts, and this way you shouldn’t invest a lot to progress in this area. Remix of course isn’t the only way, but it is the simplest and the most effective one for a beginner. Watch the presentation on YouTube when available.

Ruslan Cojocaru – Happiness 2.0

Unfortunately I just arrived after the lunch at the end of the presentation, but I got the idea of being positive in everything you do and to succeed you need two components: the passion about the project, the passion about what you do, and the other one is the team. Get the perfect team and when you got it experiment with it to do it better. I hope I’ll get more ideas from YouTube watch.

 

 

Maria Gaidar – Changing system from the inside

Maria is talking about being an opposition activist in Russia, and than suddenly things changed when she became vice-governor in the social sector of Kirov region. She talks about her problems and how she tried changing the system from the inside, not breaking it but step by step changing the attitude of the people towards politicians, by listening and making reforms where needed and possible. When asked if she thinks a single person could make the difference, she is a strong believer that a single person can do a lot of things using different tools and techniques.

 

 

 

Chad Rogers – Tweeting isn’t enough

Chad Rogers is talking about tweeter and Facebook and other social media that is used by lots of people, what he’s saying about it that you need to be active for sure, but not on social networks because sharing some link or clicking the “Like” button isn’t an action, it is just an excuse for doing nothing. He also says “Remember why everyone hates politicians ? They keep talking but they are taking no action. The same might happen to you”. The word introduced by Chad is “slacktivism” Smile.

 

Jennifer Brush – Moldovan Youth: Bricks into  the foundation of  the peace

Jennifer Brush is Head of the OSCE in Moldova. She’s talking about the Tighina bridge that can play the key factor of Moldova’s future if opened. There’s a plan of creating a series of European roads from Kiev to Istanbul – Corridor IX and Moldova is right into the center of this road – this road means prosperity and wealth and growing economics, now the bridge is closed because of our past conflict with Transnistria. Also she notice that there’s another organization that involves multiple countries in Danube zone which is also somehow interested in developing the transport routes, and Moldova can get the benefits that comes with that. She’s asking us at least to show to the governors that we’re aware of this problem. Let’s say it straight - I didn’t know about such plans and such organizations till Jennifer told us about those. Now that we’re aware of it what will change ? She answers that at least if this would be on 5th position in the social polls that would be great, and may be our governors will do something about it.

 

Dorin Dusciac – Nuclear physics danger comes from ignorance

A hilarious guy, he’s a research engineer at the French Atomic Energy Commission near Paris. He’s talking about the formulas and the concepts with such an ease that it is truly pleasant to watch him, plus he’s always making jokes. For example he explained about Roentgen and Sievert and than he said “So now everybody knows the difference between Roentgen and Sievert? Right. The Roentgen has beard, and Sievert hasn’t”. Than he talks about the myth that the wine is protecting us from the radiation and that is not correct because wine protects us only from one element in the radiation specter. Also he talks that if we fly pretty often than that dose of 1 mSv can be achieved pretty fast. For example if you get 7 flight of 7 hours you get the dose of radiation that is already higher than the yearly limit. Thanks Dorin, for a great presentation!   

Dmitry Volosin – Live projects

A serious person with a big experience in internet portals. A lot of ideas here, ok for starters he enumerated some of the components of a successful project: obsession, enjoying the project, accepting failures/deaths of the project. He says first projects are like calf's teeth but when those fall, from these small projects can grow big projects with a base already. On the question “Is it normal to lose obsession from time to time ?”, he says that it’s normal because we aren’t robots and these periods of sadness and desperation happen from time to time, but if you lost for good you obsession than sooner or later your project will die. “You should be on fire with this idea, like Jeanne d’Arc… but that isn’t the best example” Open-mouthed smile A good presentation worth watching on YouTube.

 

 

 

truly_yoursWhat I would like to say in the end… Please come to these type of events, support this type of movements. Today in parallel with TEDx Chisinau, in our city was organized “VeloHora”, a great bike event, aside with it, near Opera and Ballet Theatre was running a minifootball European championship, today I felt that our city was really alive and I hope such events will occur more and more often,

Best of wishes.

Tuesday, September 18, 2012

X-Share – cool tutorial for learning Symfony2 Framework

Hello,

At the moment of writing this blog post I’m working in Pentalog, which is a computer and technology services company, focusing on low cost offshore/nearshore IT engineering and software development.

Few days ago I found out, that as a result of our summer internship program some of the developers from our company created a great tutorial called X-Share. Following this tutorial you’ll create a website, that permits sharing of some objects between the members of a group. As an example it could be sharing books, sharing of the discount cards, sports equipment, etc. This tutorial is open sourced and is on SourceForge.

I hope you guys will find it useful, because one of you right now could be searching for a practical example of a  Symfony2 working application. And a little disclaimer: although I’m very proud of what my colleagues have done and achieved, I wasn’t involved in any way in creation and developing of this tutorial, so all the credits goes to them.

P.S. It is great to see how open source community evolves, and I hope X-Share become your first place to show to your new junior PHP developer for learning Symfony2 basics.

Friday, August 3, 2012

Unified Udevi Symfony2 Plugin for NetBeans 7.2

Hello,

I’ve recently created the unified Udevi Symfony2 Plugin that contains both File Templates plugin as well as Code Templates plugin. This plugin is made for new version of NetBeans - 7.2. It passed the validation today so you can install it directly from NetBeans. Go to Tools –> Plugins –> Available plugins. You might need to update plugins info, so it will contain the latest list of validated plugins.

plugin_udevi_symfony2

The content of the plugin remained the same, just uniting 2 templates content. The current statistic is

chart_1 (1)

In the previous table I counted number of days that this extension is published in the NetBeans Plugins Center until today. So 2.5 downloads per day isn’t so bad I would say. Probably Symfony2 and NetBeans are a good combination and a lot of people know it. But 5.5 per day is definitely better. I guess now when it is validated in Plugins Center it will sustain current number of downloads per day

chart_1

I would like to give a shout to first and I hope not the last person making 5 pull requests in total for those 2 plugins:

   Smeagol07     -       Thank you very much I hope that with the input of the community I will improve the quality of the product into something much bigger, than it is today.

 

I would also like to thank NetBeans team, because their 7.2 version has a higher performance than the previous version and made my plugin run much faster without lots of time for processing.

I’d also like to hear from you what else would you like to improve in your day to day job with Symfony2 and NetBeans and who knows may be I will be able to fulfill your expectations.

the bad part

While File templates are working fine, the code templates are not completely working, the only code templates that are working are for php editor, example action template, and others. First the code templates for Twig editor don’t work, I’ll see what I can do with it. Second the code completions for with doctrine annotations are not working, probably because for now I set them as a php documentor templates, may be I’ll need to set them as a php code templates.

The code source is here: https://github.com/Monomachus/UdeviSymfonyPlugin

If you have any questions or suggestions please share them in comments, it will be great to know what you’re thinking about it.

Tuesday, July 24, 2012

Support my feature request for WebMatrix: Possibility to add new file templates

Hello guys,

I used several time WebMatrix for the development using ASP.NET Web Pages, a lot lighter web technology than ASP.NET MVC. Recently I wanted to use WebMatrix 2 to learn Node.js development. Now there is a view engine in Node.js that is called JsHtml. JsHtml is a Razor-like view-engine that can be used with node.js or Express (node.js based Sinatra-like framework). Now back to the point: I saw that files with *.jshtml extension get no highlighting, though it should be similar with *.cshtml or *.vbhtml. I thought that may be I can create an extension for WebMatrix which will somehow call the highlighting engine. Another point would be creating specific JsHTML file template.
But it isn't restricted only to that. It creates and extension point in a free Microsoft product which is used by beginner devs or someone who wants to start playing with NodeJS a little bit.

Actually why I am telling you all these, I created a feature request at WebMatrix UserVoice: Possibility to add new file templates and I voted for it. You can maximum give 3 votes to a feature. Please vote for this feature too, it is important. I would really like these features to get in the top of requested features and than implemented in the final version of WebMatrix 2.

Plus I think these feature can be useful also for .NET devs and I hope you will support this feature request. Thank you.

Wednesday, April 11, 2012

Hibernate : Repeated column in mapping for entity error

Well I guess I need to explain this error so when I’ll get it one more time I’ll at least have a place to see where the problem was.

So I was having this problem because I’ve got an entity and also I’ve got a composed primary key entity that was embedded in the first one.

So let’s imagine I’ve had some GridPreferences entity, that had the GridPreferencesPK composed entity as a primary key which contained userId, and gridId.

GridPreferences.java

@Entity
@Table(name = "GRID_PREFERENCES")
public class GridPreferences extends BaseEntity{
    
    private static final long serialVersionUID = 6521799809955099787L;

    @EmbeddedId
    private GridPreferencesPK id;
    
    @Column(name = "GRPR_GRID_ROWS_PER_PAGE", nullable = false)
    private int rowsPerPage;

}

GridPreferencesPK.java

@Embeddable
public class GridPreferencesPK extends BaseEntity {
    
    private static final long serialVersionUID = 2499336910059865064L;

    @Column(name = "GRPR_USER_ID", nullable = false, precision = 8)
    private String userId;
    
    @Column(name = "GRPR_GRID_ID", nullable = false, precision = 250)
    private String gridId;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GRPR_USER_ID", insertable = false, updatable = false)
    private User user;
}

Now I got this error  org.hibernate.MappingException: Repeated column in mapping for entity. Which isn’t exactly self-explanatory. But this time Hibernate got it right.

Basically it is an embedded primary key, so it would be logical that all the fields that are in the PK are the fields of the table itself, not the relation tables.

And the solution is to move the connections to other entities into base entity, in our example GridPreference. Doing that will solve the problem.

Hope this will help someone else too.

Thursday, March 8, 2012

New Udevi Symfony2 Template NetBeans plugins that will ease your life (hopefully)

Hello guys,

I got great news for you: I’ve created 2 new NetBeans plugins for increasing the speed of development with Symfony2.

First let’s talk about

Udevi Symfony2 Code Templates

1331132011_2012-03-07_1636

Plugin details page: http://plugins.netbeans.org/plugin/42128/udevi-symfony2-code-templates

Plugin code: https://github.com/Monomachus/Symfony2CodeTemplates

So this is something I was thinking about when I started developing a real world applications - code templates, snippets of code that will help me create Symfony2 applications in NetBeans faster and more effective, I searched in Google, and I found this one (http://www.symfony-zone.com/wordpress/netbeans/).

Timo Haberkern – is the guy who created a set of code templates and exported them, he also has the CheatSheet that will help you figure out what each template does. Thank you very much Timo ! Great job !

I took those templates, modified them a little bit, removed some, added some new templates and created a new plugin. I was very happy but when I started testing it I found out that the PHP code templates in NetBeans 7.1 were not working. It was a bug in NetBeans Sad smile. Here’s the original issue: http://netbeans.org/bugzilla/show_bug.cgi?id=206413

So the issue was fixed in 7.1.1 and you can finally use my plugin Smile, but the Twig completion is still broken, I will create a new issue for the guys in NetBeans to fix it. So it doesn’t work for Twig, but still works for everything else.

I uploaded the plugin to NetBeans Plugin Portal, the verification is pending but I hope it will soon pass. I suggest you use the plugin and say what do you think about it. If there are any bugs please report them on github. Please use NetBeans 7.1.1 .  Soon I’ll make a new post with the complete list of code templates.

Udevi Symfony2 File Templates

1331130368_2012-03-07_1622

Plugin details page: http://plugins.netbeans.org/plugin/42127/udevi-symfony2-file-templates

Plugin code: https://github.com/Monomachus/Symfony2FileTemplates

UPDATE: you can also use the Symfony2 interactive generators. More info here (http://qpleple.com/code-faster-symfony2s-interactive-generators/)

This one was a little bit harder to do, but the main goal was to avoid writing over and over pluming code that actually could be written or rewritten using file templates and/or code generation… I like this feature in the IDEs because it saves you a lot of time and the task of writing over and over even 20 keystrokes is not fun.

So I created 3 file templates by default

  • Symfony2 Entity Template: This template includes generating an entity with guessed namespace: this namespace is guessed by the absolute name of the new file. The name of the table in DB is guessed upon the name of the entity with underscores between words if there are multiple words, the wizard also has the optional table name and the checkbox to create the annotation for repository or not.
  • Symfony2 Controller Template: This is just a template of a new controller with guessed namespace and some useful default uses (Symfony2 Controller and Response) and a new default indexAction.
  • Php Class with Namespace: This one is the most wanted for me but still not that good because it is based on supposition that all the Php classes you would need to create with namespace are inside of the ‘src’ folder.

Some templates I would also like to create but don’t know how yet

  • Symfony2 Form Type: It would receive as a parameter the entity and than created in buildForm method each method with description. If field is an id automatically suppose it is hidden. I don’t know how to do it now because of the fact that I don’t know how to get metadata of a PHP entity in Java, hope Oracle guys will help me in that.
  • A ViewModel for an Entity: Now when I don’t need to show everything I have in the entity to the screen I use view models. I would also need a generator that take an entity and creates a ViewModel with all the fields of the entity.

Thought about creating the template for Repository but the command line function lower helps you generate your Repository class.

app/console doctrine:generate:entities BundleNamespace

The first time you run the New file-> template from my plugin it runs slow (up to 6-8 seconds) because NetBeans need to index all the files in the plugin, next times it is faster, like 3 seconds. Still a bad performance, perhaps someone from Oracle could help me with that.

Please share what other file templates you would like to seen in this plugin, how well did the plugin go, do you have any problems, questions, concerns, ideas related to it? If any bugs found please declare them in github. Thanks a lot.

P.S. Later on will create a post about how to create a new file wizard module plugin, hope it will help someone. Are you interested in something like this ?

P.S.S. Dear guys from PHP NetBeans team, if you are reading this please make PHP Project a Public API that I could use in my plugin. There is a Java Project API in NetBeans, but nothing regards PHP, may be it is the time to change it Winking smile.

Ok guys, next and hopefully the last question do you think I should unify these 2 plugins in 1 ?

Thanks a lot and happy coding !

Wednesday, January 25, 2012

Git and NetBeans 7.1 Problem: Everything in the project appears modified, but is not

Hi,

Recently I started developing a new Symfony2 project on Windows following the tutorial on http://tutorial.symblog.co.uk

I like to use Git in combination with BitBucket.org. I used Git integrated in NetBeans in combination with msysGit and recently found a very strange bug. Everything in NetBeans appeared as modified but actually wasn’t. Very strange I thought, and created an issue on NetBeans bugzilla, than I found out that it is a duplicate of the other issue http://netbeans.org/bugzilla/show_bug.cgi?id=198451.

It appeared to be a problem related to line endings in different operating systems. Though msysGit is capable of ignoring this differences, it seems to be that JGit, the tool on which integration with Git is made in NetBeans, doesn’t. So now what should we do to make it work is to add the line

[core] autocrlf = false

to project’s .git/config file. But that’s not enough, also we would need to follow the instructions in http://help.github.com/line-endings/.

So for Windows I needed to run this script in msysGit :

# Remove everything from the index
$ git rm --cached -r .

# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add -f

# Commit
$ git commit -m "Fix CRLF"

Hope this one will save you time and please vote it in NetBeans bugzilla to notify developers that we need it solved. 

2012-01-24_1436For any ideas, concerns, requests please leave a comment. Thank you.

Thursday, January 19, 2012

Git and first Symfony2 project in NetBeans

apple-touch-iconThis post is a part of series of posts dedicated to developping in Symfony2. If you missed the first part I highly recommend you to go and read that one before you continue with this post.

  1. Setting up Windows environment for Symfony2 developing with NetBeans, XAMPP and Git

Hello, today I’ll show you how to create your first Symfony2 project in NetBeans and how to push and pull it to/from Github.

Creating the fiRst SYMFONY2 project IN NETBEANS

Ok go File –> New Project –> PHP –> PHP Application. Click Next.

2012-01-19_1432

Create the project directly into your XAMPP server, htdocs folder. Click Next.

2012-01-19_1434

We should modify the starting URL because in Symfony2 the application starting point is /web/app_dev.php like that we can assure that when we are running the application it is correctly started. Also give it a descriptive name like “FirstApp”.

2012-01-19_1445 

On PHP Frameworks step select Symfony2 checkbox and click Finish. Now your application should be generated.

RUNNING APPLICATION

Now start your Apache and MySQL from XAMPP Control Panel. Go to NetBeans and click F6 (Run the application).

Hooray!!! Our first application is up and running. Now we need to configure our application, and doing this will change the app/config/parameters.ini

AccessSymfony2FirstApp

configure_1_stepconfigure_2_stepwell_done_config

Now here are our new parameters.ini file

changed_params_ini

working with git. putting the site to github.

Now we need to put the site to github I will show you here the NetBeans integration with Git, but I really prefer the command line way from Git Bash (MsysGit). First I will create a repository at Github. I’ll name FirstSymfony2App.

Next we’ll add a .gitignore file to our project. But what is to ignore actually ? Well I didn’t knew it either so I found a typical ignore file for Symfony2 project. So I found it in http://github.com/github/gitignore/blob/master/Symfony2.gitignore.

# Bootstrap
app/bootstrap*

# Symfony directories
vendor/*
*/logs/*
*/cache/*
web/uploads/*
web/bundles/*

# Configuration files
app/config/parameters.ini

Copy it and create this file in our project.

Now we can initialize the Git repository directly from NetBeans. Select the project. Right click go to Versioning –> Initialize Git Repository.

init_git

  • Now we can add the files to Git by “Git –> Add” command.
  • Also we can commit now by right click Project –> “Git –> Commit”.
  • Also we can see already made commits by “Git –> Show History” command

Now lets push the contents of our site to Github. First we’ll need to use a remote site to which to push. Ok let’s execute Git –> Remote –> Push command.

2012-01-19_15422012-01-19_1543

2012-01-19_1544

That’s all folks, our project is on Github. You can see it here https://github.com/Monomachus/FirstSymfony2App

PULLING Project From GiTHUB AND RUNNING IT

Now let’s see the perspective of another developer who wants to use/participate in the project. For the sake of the experiment I will delete all the sources and will use MsysGit to do all Git-related stuff, though I think I could somehow use NetBeans for it.

I will clone the repository directly into XAMPP server, htdocs folder. Also I will name the folder FirstApp to avoid specific problems. Using Git Bash tool run this command

$ git clone https://Monomachus@github.com/Monomachus/FirstSymfony2App.git FirstApp

Import the project into NetBeans using File –> Open Project command. Now start Apache and MySql and run the project. We will also need to specify the project URL : http://localhost/FirstApp/web/app_dev.php .

Now we get an error:

Warning: require_once(D:\xampp_server\htdocs\FirstApp\web/../app/bootstrap.php.cache) [function.require-once]: failed to open stream: No such file or directory in D:\xampp_server\htdocs\FirstApp\web\app_dev.php on line 17  
Fatal error: require_once() [function.require]: Failed opening required 'D:\xampp_server\htdocs\FirstApp\web/../app/bootstrap.php.cache' (include_path='.;D:\xampp_server\php\PEAR') in D:\xampp_server\htdocs\FirstApp\web\app_dev.php on line 17

2012-01-19_1604

This error is caused by the fact that in our .gitignore file there is this line app/bootstrap*  and this means that our bootstrap.php.cache file was ignored and not committed to the Github. So the question is how can we regenerate this file ? Well, thanks to Beeton from IRC channel #symfony from Freenode, I found out that we can generate it using the

php bin/vendors install

command and that vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php is the file that actually creates it.

But before you run that command please note that we also do not have the app/config/parameters.ini file because it is also in our .gitignore file. Is it really a good idea ? Yes it is if you work with other people, it means that your MySql database configuration can actually differ from your mate’s configuration.

So where do you get the sample file, well almost always in open source world the answer is Github. Smile The link to the sample file https://github.com/symfony/symfony-standard/blob/v2.0.9/app/config/parameters.ini

Copy that file and add it to the app/config folder. Modify it and than run the command php bin/vendors install

$ php bin/vendors install
> Installing/Updating symfony
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/symfony'...
remote: Counting objects: 109718, done.
remote: Compressing objects: 100% (35141/35141), done.
remote: Total 109718 (delta 68210), reused 102521 (delta 62139)
Receiving objects: 100% (109718/109718), 16.38 MiB | 3.49 MiB/s, done.
Resolving deltas: 100% (68210/68210), done.
f842739d58b649ffbe6543b2eff520327373029d
HEAD is now at 3e9d937 updated VERSION for 2.0.9
> Installing/Updating twig
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/twig'...
remote: Counting objects: 9859, done.
remote: Compressing objects: 100% (2606/2606), done.
remote: Total 9859 (delta 6399), reused 9540 (delta 6122)
Receiving objects: 100% (9859/9859), 1.28 MiB | 444 KiB/s, done.
Resolving deltas: 100% (6399/6399), done.
96596d5c7f6920dc59985c1cba531ae20715baf4
HEAD is now at 5bba149 prepared the 1.5.1 release
> Installing/Updating monolog
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/monolog'...
remote: Counting objects: 1384, done.
remote: Compressing objects: 100% (548/548), done.
remote: Total 1384 (delta 748), reused 1322 (delta 695)Receiving objects:  94% (
Receiving objects:  96% (1329/1384), 52.00 KiB | 90 KiB/s
Receiving objects: 100% (1384/1384), 174.72 KiB | 90 KiB/s, done.
Resolving deltas: 100% (748/748), done.
8e11234066280685e903ea6dcc0d304cd1aec9b9
HEAD is now at b704c49 Only send FirePHP headers to browser advertising support
for it in their user agent
> Installing/Updating doctrine-common
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine-common'...
remote: Counting objects: 57783, done.
remote: Compressing objects: 100% (14404/14404), done.
remote: Total 57783 (delta 40513), reused 57588 (delta 40349)
Receiving objects: 100% (57783/57783), 15.34 MiB | 834 KiB/s, done.
Resolving deltas: 100% (40513/40513), done.
38c854c37d20b1f67c979772089b2cd30908bcb6
HEAD is now at b886898 Release 2.1.4
> Installing/Updating doctrine-dbal
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine-dbal'...
remote: Counting objects: 59701, done.
remote: Compressing objects: 100% (15249/15249), done.
remote: Total 59701 (delta 41906), reused 59291 (delta 41520)Receiving objects:


Resolving deltas: 100% (41906/41906), done.
2a9e9943f33610bfde4637abeafe00edd201803c
HEAD is now at ae358bd Merge remote branch 'origin/2.1.x' into 2.1.x
> Installing/Updating doctrine
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/doctrine'...
remote: Counting objects: 69262, done.
remote: Compressing objects: 100% (17611/17611), done.
remote: Total 69262 (delta 48424), reused 68330 (delta 47567)
Receiving objects: 100% (69262/69262), 17.08 MiB | 2.61 MiB/s, done.
Resolving deltas: 100% (48424/48424), done.
febfe35c2315a20534630aa9e5b9c72a0047f569
HEAD is now at da0e343 Release 2.1.5
> Installing/Updating swiftmailer
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/swiftmailer'...
remote: Counting objects: 9620, done.
remote: Compressing objects: 100% (3288/3288), done.
remote: Total 9620 (delta 5536), reused 9458 (delta 5388)
 (9524/9620), 4.93 MiB | 876 KiB/s
Receiving objects: 100% (9620/9620), 5.04 MiB | 889 KiB/s, done.
Resolving deltas: 100% (5536/5536), done.
0243dc3b18c784adda72e71f6bd34f11fef69b4b
HEAD is now at 982b4c9 prepared the 4.1.5 release
> Installing/Updating assetic
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/assetic'...
remote: Counting objects: 4714, done.
remote: Compressing objects: 100% (1665/1665), done.
remote: Total 4714 (delta 2787), reused 4492 (delta 2600)Receiving objects:  99%

Receiving objects: 100% (4714/4714), 540.18 KiB | 251 KiB/s, done.
Resolving deltas: 100% (2787/2787), done.
e15a13fe4782caa6566c7f0c34ae10badaf85361
HEAD is now at f829ad2 updated changelog
> Installing/Updating twig-extensions
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/twig-extensions'...
remote: Counting objects: 297, done.
remote: Compressing objects: 100% (148/148), done.
remote: Total 297 (delta 108), reused 270 (delta 84)Receiving objects:   7% (21/
Receiving objects:   8% (24/297)
Receiving objects: 100% (297/297), 40.25 KiB, done.
Resolving deltas: 100% (108/108), done.
a05ab5ed18a51ae45f3dcc2d0c4ec9b3a6386987
> Installing/Updating metadata
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor/metadata'...
remote: Counting objects: 249, done.
remote: Compressing objects: 100% (178/178), done.
remote: Total 249 (delta 118), reused 128 (delta 32)Receiving objects:  91% (227
Receiving objects:  93% (232/249)
Receiving objects: 100% (249/249), 33.70 KiB, done.
Resolving deltas: 100% (118/118), done.
7d97f1725063f04ef1894a86740b261daf229b89
HEAD is now at 8717ad2 release 1.0.0
> Installing/Updating SensioFrameworkExtraBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Fram
eworkExtraBundle'...
remote: Counting objects: 1064, done.
remote: Compressing objects: 100% (518/518), done.
remote: Total 1064 (delta 582), reused 969 (delta 500)Receiving objects:  94% (1
Receiving objects:  96% (1022/1064), 132.00 KiB | 74 KiB/s
Receiving objects: 100% (1064/1064), 132.52 KiB | 74 KiB/s, done.
Resolving deltas: 100% (582/582), done.
55de01d34c5b95ee07bd511d06e0b171af5fe9ba
HEAD is now at 1c7e92f fixed tests config
> Installing/Updating JMSSecurityExtraBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/JMS/SecurityExtraB
undle'...
remote: Counting objects: 1665, done.
remote: Compressing objects: 100% (718/718), done.
remote: Total 1665 (delta 880), reused 1595 (delta 810)
Receiving objects: 100% (1665/1665), 273.00 KiB | 228 KiB/s, done.
Resolving deltas: 100% (880/880), done.
4dc8223afa9a38cc467e0a858ef5741e6cc3987d
HEAD is now at 541a4c2 Merge pull request #36 from everzet/patch-1
> Installing/Updating SensioDistributionBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Dist
ributionBundle'...
remote: Counting objects: 423, done.
remote: Compressing objects: 100% (201/201), done.
remote: Total 423 (delta 211), reused 414 (delta 206)Receiving objects:  70% (29

Receiving objects: 100% (423/423), 60.86 KiB | 87 KiB/s, done.
Resolving deltas: 100% (211/211), done.
f00c99854ff161b006a200d8dffa0013981d5373
HEAD is now at 20b66a4 fixed version in composer.json
> Installing/Updating SensioGeneratorBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Sensio/Bundle/Gene
ratorBundle'...
remote: Counting objects: 651, done.
remote: Compressing objects: 100% (302/302), done.
remote: Total 651 (delta 343), reused 609 (delta 317)Receiving objects:  77% (50
2/651), 76.00 KiB | 130 KiB/s
Receiving objects: 100% (651/651), 115.97 KiB | 130 KiB/s, done.
Resolving deltas: 100% (343/343), done.
67bf607b41f930f93f2032d069be535ecaa21730
HEAD is now at dd37fc4 merged branch gnomii/use_filesystem_component (PR #88)
> Installing/Updating AsseticBundle
Cloning into 'D:\xampp_server\htdocs\FirstApp/vendor//bundles/Symfony/Bundle/Ass
eticBundle'...
remote: Counting objects: 1741, done.
remote: Compressing objects: 100% (544/544), done.
remote: Total 1741 (delta 1056), reused 1671 (delta 992)Receiving objects:  94%

Receiving objects: 100% (1741/1741), 229.34 KiB | 86 KiB/s, done.
Resolving deltas: 100% (1056/1056), done.
ae7f6f4dc252d37c686584576cc92f07b092d06a
HEAD is now at 41b5913 Merge pull request #27 from stof/disable_profiler
Installing assets for Symfony\Bundle\FrameworkBundle into D:\xampp_server\htdocs
\FirstApp/web/bundles/framework
Installing assets for Acme\DemoBundle into D:\xampp_server\htdocs\FirstApp/web/b
undles/acmedemo
Installing assets for Symfony\Bundle\WebProfilerBundle into D:\xampp_server\htdo
cs\FirstApp/web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into D:\xampp_server\htdo
cs\FirstApp/web/bundles/sensiodistribution
Clearing the cache for the dev environment with debug true

After these manipulations we can finally run the sample application.

2012-01-19_1644

Today we learned how to create and run your first Symfony2 project and push and pull it to/from Github.

Hope you liked it, if you have any concerns, ideas for posts, suggestions please post it here. Good coding guys!

Setting up Windows environment for Symfony2 developing with NetBeans, XAMPP and Git

[UPDATE] This is a series of post in the next one I’ll show you first Symfony2 app and how to make it work with Git. Second post link: Git and first Symfony2 project in NetBeans

Hi,

For a long time there was no sign of me here, but I hope this will change… So what do I do these days, well I want to go in Symfony2 to see how it feels like… Lots of guys were telling me PHP is way faster in development than in Java or .NET Web development so I want to try it out too.

So what do we actually need ?

XAMPP

No problem with that one. Get the latest version, install it but please don’t install MySql and Apache as services.  Than add a system environment variable like XAMPP_HOME for example and than add

;%XAMPP_HOME%\php;%XAMPP_HOME%\mysql\bin\

to Path environment variable. Now you should be able to check your PHP version from command line.

Try it now

XDEBUG based on your own phpinfo

A friend of mine showed me a wonderful site for getting your own DLL that is needed for your exactly configuration.

But first start your Apache server from your XAMPP control panel. Go to http://localhost/xampp/phpinfo.php and go get view source and copy all the HTML. Now go to http://www.xdebug.org/find-binary.php and insert the HTML into the textarea. Click on “Analyze my phpinfo output” button. And there you go you have your own DLL to download. Download it and put it into your php/ext folder

find_xdebug_binaryfind_xdebug_dll

Now go to your php.ini location and add these lines + the line starting with zend_extension

xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
zend_extension = D:\xampp_server\php\ext\php_xdebug-2.1.2-5.3-vc9.dll

Now your machine should be ready for debug.


INSTALL mSYSGIT – GIT FOR Windows

Go and get the latest msysgit from and install it http://code.google.com/p/msysgit/downloads/list

2012-01-19_1144

SYMFONY2 Package

Go to http://symfony.com/download

Download the latest version in a .ZIP package. At the time of writing this it was Symfony Standart 2.0.9.zip

Make a separate folder and put this zip into it (in my case symfony2_php_sources). Also unzip it into another folder. (in my case symfony2_php_sources/Symfony).

IDE

Well we have some options like Eclipse and NetBeans also some support in PHPStorm, but I choose NetBeans 7.1.

There are a number of reasons why I chose it:

  • Out of box support for YAML
  • Support for Symfony2 (plugin)
  • Support for Twig (templating engine in Symfony2) also plugin
  • More user friendly than Eclipse (I guess someone could argue that, but I worked in Eclipse for 1 year).

So let’s starts go to  http://netbeans.org/downloads/

2012-01-19_1035

Add plugin for Symfony2. Go to Tools –> Plugins –> Tab Available Plugins –> click “Reload Catalog” –: in Search box input “symfony2” and press Enter. Now there should be a plugin there, called PHP Symfony2 Framework. Install it and restart NetBeans.

Add plugin for Twig. For now it is available for download from https://github.com/blogsh/Twig-netbeans/downloads as a NBM file. Download the latest file.

And install it in NetBeans. 

Now let’s tweak it a little bit. Go to Tools –> Options –> PHP.

Here we’ll have a little fun go to General tab –> Indicate your php.exe location in XAMPP. Also add in Global include path unpacked Symfony2 sources.

Go to Unit Testing tab and indicate the location of your phpunit.bat

Go to Symfony2 tab and indicate the location of the downloaded Symfony2 zip file.

Here is the cumulative actions screenshot

THAT’S ALL. Now your machine is configured.

Next time I’ll show you how to work with your first Symfony2 project and Git.

If you have any concerns, suggestions, ideas for blog posts please comment here.