error = MongoId not found in symfony application

I got the MongoId not found error on the the application I recently moved to remote server.
The app is working fine locally and the problem appears to happen on the remote one only.
The problem seems obvious, and I checked the mongo version I have locally vs the version I have on the remote – they are different

I have newer version of mongo installed on the remote server. And the doctrine orm handling my mongo objects was also older.
I updated my doctrie orm on composer as

 "doctrine/orm": "2.4.6",

This took care of the problem – at least for now 😉

Deploying Symfony app on micro instance of aws – Amazon EC2

The major issue you would face is memory. Yeah, the instance comes with small memory allocation and anything memory intensive task might not work there. Your composer install command might not do anything as well.

The major one would be Composer install just hangs and even aborts the process
When you are issuing

composer install

It will eat a bit of memory and doing it on the instance might not work as expected.

Here are the methods I used to overcome it.

1. Incremental install
On you composer.json file, you can try to list only one or two packages at a time and issue composer update vendor/package and if your individual packages are small enough you might get away with it. In my case this didn’t work

2. Ship your vendor from your local machine to the instance
yeah, just have all your composer install where you will be comforted by memory in Gigabytes and just zip and ship it to your instance.
On your local machine

tar -cf vendor.tar.gz /path/to/vendor/folder

Once you have the tar or zip of any of your favorite compressed file

scp -i /path/to/your/pem/file vendor.tar.gz ec2-user@ec2-domain-goes-here:/path/on/instance

This is assuming this will transfer your vendor file to instance.
Then log into your instance and just uncompress the file and put it on the root directory of your application.
This would be just the half of the work.
Then you will need to generate the bootstrap cache file

composer run-script post-update-cmd

yeah.. this will take care of creating the cache file of the bootstrap along with other stuffs that you put on your composer.json post-update-cmd part.
Sometimes you might want to give the write access to the app/cache and app/logs folders as well

ENjOY

Configuring PHP + MySQL + Apache on Amazon EC2 Step by Step

Log in to aws.amazon.com
Click on EC2 virtual servers in the cloud

From the left menu, under Network and Security, select Key Pairs
Create on by hitting “Create Key Pair”. Mind you, aws will give you only one chance to save the pem file you will be using for logging. So make sure you download and save it.

From your select Elastic Beanstalk and follow the wizard to create an instance per your need.
in the wizard, there is a step you will be asked to use the pem file you downloaded.

Now from the left menu, click on the instances.
And click on the instance on the right pane and you will see another pane with description will be opened on the lower part. On that pane, search for security group and click the link
You will be transferred to the security group associated with that instance. Click on the “in bound” tab and check if SSH is listed there, if not, hit the ‘Edit’ button and add a new rule of SSH with the source of anywhere if you would like to ssh into your box from anywhere or you can specify particular ip address.

log to your instance from terminal as

ssh -i /your/downloaded/pem/file ec2-user@public-domain-goes-here

you will get your public domain on the instance you selected.

If you are using Elastic Beanstalk, it will come with installed apache server for as your webserver. Just restart it

sudo service httpd restart

MySQL shell would be there as well but not the mysql server so install that

sudo yum install -y mysql-server

And restart the demon

sudo service mysqld restart

I have checked if git is installed, if you are using any DCVS, which you should and it is installed already to verify do

git --version

Next would be the creation of your public and private keys for secure communication with the other servers.

ssh-agent -t rsa -b 4096 "your_email@domain.tld"

The above command will provide you with the public and private key that you would use. The default path for it would be on ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub

If you are using github or bitbucket, you would need the content of the id_rsa.pub for logging to the server without password.

If you are going to use mongo just use the very information on the following links https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
http://www.liquidweb.com/kb/how-to-install-the-mongodb-php-driver-extension-on-centos-6/

This will get you started with your aws instance

Loaded Configuration File => (none) Apache not reading php.ini

php.ini is a core file to handle the behavior of PHP and sometimes apache might not pick it and php might not be using and it will create problem.

To resolve this, just see the output of phpinfo first.
Just add the following code snippet in the php file and run it through your server

<?php
phpinfo();

Then look of configuration file (php.ini) path, by default it would be /etc
If you don’t have the file php.ini in that mentioned directory, just look for related ones like php.ini.default or something and just copy that as php.ini and restart your apache.

do you postfix?

Recently I was engaged on setting up mail client on the new redhat (rhel6) server for one of my clients. The server was on its default setup of sendmail. Since it is a bit outdated, I decided to use postfix relaying on gmail SMTP.

First thing first, make sure sendmail is not running by running this command

sudo service sendmail stop

Make sure if there are any lingering processes out there by issuing proper process listing commands on your server and kill those if you have to

Then check if you have postfix installed your machine

sudo service postfix start

If you got any complaint like service not found or something along that line, just install the postfix

sudo yum install postfix

Ok now lets go to the juicy part of integrating the postfix with gmail SMTP.
Lets assume your username is gopostfixgo@gmail.com and password is #nomoresendmail

Now lets proceed to the configuration part of the postfix.
go to postfix config folder

cd /etc/postfix

Here you will see a couple of files. Our interest would be on the main.cf file
First, before you start messing with the file, create a copy of it

sudo cp mail.cp main.cp.bak

Just go to the end of file and add the following snippet in there

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/pki/tls/certs/self.pem
relayhost = [smtp.gmail.com]:587    

That last line right there would tell the postfix it has to relay the SMTP to other server.

Now lets create the sasl_passwd file

sudo touch sasl_passwd
echo "[smtp.gmail.com]:587 gopostfixgo@gmail.com:#nomoresendmail" > sasl_passwd

The above command would add the content to the sasl_passwd file.

Then to obscure the password information you placed on in the sasl_passwd file,

sudo postmap /etc/postfix/sasl_passwd

The other point would be creating a self certificate you would be using for your secure communication. If you have a certificate you are using already, then just point it to the right place and you should be fine

cd /etc/pki/tls/certs/
make self.pem

The above command would give you interactive wizard that you will follow and create the certificate.

After this, you need to tell the postfix to pick the changes you have been ramming. For that just restart postfix

sudo service postfix restart

Then open your logger to see if there are anything that are suspicious going or if mail is not working, you can tail it as

tail /var/log/maillog

Common Errors
1. Google might be sending some kind of error saying you have to log into the web browser bla bla bla.. then do the following
Go to https://www.google.com/settings/security/lesssecureapps and login with your google account and turn it on

Mount to NSF Server timed out on Vagrant

I had a bit rough weekend :( after successful update of some packages and successful breakage of my guest machine aka vagrant.
The thing is my symfony app is running on vagrant and all of a sudden I can’t ssh or after halt I can’t vagrant up – it is giving me the mount to NFS server timed out

This has something to do, unfortunately, with the firewall setting. After the guest and the host are two, at least technically, machines and firewall decided to block the packets for some of the host machine applications.

You can comb those needed for it by looking from the list of the firewall..
On Mac => go to System Preferences and click on Security and Privacy and Turn off the firewall to make sure the issue is associated with it and then you can turn it back with applications related to virtual host to accept all the incoming traffic.

t h a t i s IT

Working From Home? Here are some tips for ya

As it sounds nice, unless you follow some guidelines, working from home can be quite boring and unpleasing, been there :).. here are some tips I will share with you to be as effective as possible

You and Your House – Nothing Technical

#1 – Hygiene – Looks trivial ha? Working from, unfortunately, is highly associated with working in pajamas which is mostly correct. Think about it and you can’t find any other thing filthier than that, you are working with what you wore the whole night ugh.. Guess what comes along with that – you might not take shower too.
So the fix, make sure that is your priority, dart into your shower before hitting your desk. Brush your teeth, wear your deodorants.. basically do what you would have done if you were to fly to your office. This has a very refreshing effect on you especially on the morning.

#2 – Dress Nice – yeah mostly if you have done tip #1, this would come natural. Just wear something other than your pajama. Also, use this opportunity to wear what you want, shorts, flipflops, hoodies.. you are not supposed to follow dress code here – just dress nice.
This has a good effect on you especially when you want to go out – you are just ready and you won’t have excuse not to go out and get fresh air :)

#3 – Clean your Surrounding – This would apply if you are single mostly. It would come easy to toss papers and pizza boxes here and there, not to clean your kitchen and bathroom, not to fix your bed and not to let fresh air to your room. This would be a simple reason to hate your room. It is difficult to keep up with it as I have trouble to do that, but if you make it habit, then the flip side would be impossible in return.

#4 – Make sure You Are Well Fed – One thing I noticed working from home is how easy it is to miss lunch and breakfasts most of the time. I think I was OK when I was working in the office as there would be others reminding for lunch or to a short trip to the near by corner store. I don’t have to explain why you should not be hungry – you will easily be angry and angry programmer is the one you don’t want to be.
The fix – make sure you have snacks, fruits, candies, string cheese, yogurt or something that can be consumed immediately in your house, some protein bars are good too. They might not be healthy in most cases, but be selective and store them. Have your stack of water and beverages at hand as well.
But, the biggest thing would be to be able to cook. One thing, it would help you for break, and second you feel great that you are eating what prepared which is healthier and cheaper.

#4 – Exercise – Yup, it is like blinking of an eye when 10-12 hours of your day flies by before your eyes. The more you do that, the more your body would get used to it and hence less metabolism and high carbs would be your immediate friends. You definitely don’t want that.
the fix – Have smaller dumbbells at your house it could range from 6-50lb and make sure you play with them every 2 hours or so, you can set your mobile alarm or one of those gadgets which would help you remind that you should get up and do some exercise. Pushups, pullups, situps, stretches, head to knees, joggings, boxings.. there are numerous of those you can do in your house – just make sure you know your limit and you do it drop at a time. If you over do it, since you know where the bed is..

#5 – Have Natural Light – In the morning, open your blinds and let the light fill your room. It is natural and energetic than the lamp hanging on your roof. Also, let the air visit your surrounding as well.

#6 – Get Office Chair and Desk – You might be tempted to work from bed. nahh.. Avoid that for a lot of reasons. The first, you are breaking tip #1, as you might still be in your pajamas if you work from bed :), two it not healthy for your back as you might be curling yourself, third, you are way near for sleeping and productivity might not look good.
The fix – Get office chair and desk. There are a lot of Ergonomic chairs out there that are meant to be helpful for longer hours of working, the desk too..

#7 – Reminder for taking break – If you were in the office, there are quite successive breaks you would take without your conscious. A co-worker might be sharing a story what she and her husband run into when they were dining in the neighborhood, a fellow programmer requesting for review or help, breaking news on the TV, funny links being passed around on the communication tools and the like.. all those are effective ways of staying alert and taking a break. You won’t get those when you are in your own dungeons – so do that reminder on your one-of-many gadgets you sport.
But, make sure you know your limit as well, it is easy to get carried away on youtube or huffingtonpost..

#8 – Limit Your Communication – It would come handy talking to phone and responding to texts when you work from home. But somehow people would respond or call per your rate of communication. Though it is good to communicate, you should also tell yourself that you are at “work” and all the ethics and discipline would 100% apply here too. So, be cautious about it and setback.

#9 – Hangout Online With Coworkers – You work from home and so does others, they are your co-workers. So you can still hangout with them and chitchat a bit on work related or completely non-work related stuff. That would make it more natural – you are sharing thoughts or concerns and what nots with co-worker. This is even more effective way to learn about the work itself and about your virtual friends. Still business as usual, you are working with/for them and communication with them shall not and will not deter the professionalism you have.

#10 – Music – There are quite number of researches out there on how music would affect the ability of concentration while programming. For me, it is working fine, I can put on my headphone and just work fine – probably this is something I picked from my co-workers. I am just mentioning it – this is absolutely personal color choice. The good thing is working from home serves both choices equally.. if you like woking in a silent or in music, the actions to be taken are entirely in your hands.

#11 – Work outside 2 Days a Week – I have worked from Starbucks, public libraries, college libraries[this has some limitation], hotel lobbies, restaurants and literally anywhere I see that wifi logo.. but I have to admit Starbucks is the number one. It is great to work outside of your home for the sake of change. It provides the best of two worlds – you are alone and you are with peoples as well – what a goodie! Just make sure the rules of the places, some places like Panera Bread would allow you to work for 30 mins only during their busy hours, others like college libraries might not allow you to tunnel, and others have cap on bandwidth usage. Worst case, you can tether from your phone and work till you make it to your home. But, going out and working from those areas would make you feel active outgoing

#12 Have Something To Play With Yoyo is the best one in this category. Just have yoyo, some, rubik’s cube, small robots and the like that you would invest maybe 5 minutes when your brain is tied up with solving a problem and/or trying to come up with better algorithm for the problem you are facing.. again..

Next time I will share a thought on You and Tech – on how to stay sharp and upto the technology, tools to help that, news and selected articles sites..

Let me get back …

Apache listing directory – I swear I have index file!

OK, the ultimate wisdom is you will put your index file on the webserver accessible directory and your website would be visible – right? Well, not all the time.
Apache might decide to list your files even though you put your index.php in the directory you are expecting..
The thing lies on the default configuration of your server. If the default http.conf file has the directory setting to list then it will list even in the virtual hosts.
The fix Add your DirectoryIndex

So typical .htaccess or your setting in http.conf file would look like

...you other configs
   DirectoryIndex index.php //or whatever you want it to start from 
....your other configs

vOILa

Vim not syntax highlighting in sudo/root huh..

So I had to deal with the server issue and I ssh into it. Then opened the file looked at it and wanted to change the content, I had to be on root and I noticed the syntax highlighting was off..
Here are the steps I took to check what went wrong.
Basically when I am sudo-ing the user has changed a bit. So the configuration per that user is the area of focus.
Also, there could be multiple installations and vanilla versions for the vim as well, so check which one the sudo is using

sudo which vim

I was able to locate the right vim the sudo was using and I applied that one to fix the issue