Screen Shot 2016-04-10 at 7.49.57 PM

composer install-update killed on vagrant machine

These are also other stuffs going on:
composer update or composer install takes forever and the command line responds as killed

Specially this might happen on ordinary symfony application.Screen Shot 2016-04-10 at 8.16.40 PM

This is mostly, very very likely, related to memory issue.

Solution 1: perform your composer update or install on the host machine if possible.

This might not be possible in some scenarios if there are dependencies that rely on installed packages.

But, if that is not the problem, have on the host and the files would be sync’d anyway.Screen Shot 2016-04-10 at 8.07.07 PM

Solution 2: increase the memory on the provision file you have. I am using puphpet so, for that all you would have to do would be

cd /path/to/puphpet/
vim comfig.yml

then search for memory which by default be 512 and increase it at least to 1024 or better 2048 and that should solve the problem

Tip

To see the how much memory you have on your vagrant machine, ssh into your machine and

vagrant ssh
free -h

the free command would tell you how much memory you have and how is used.

Screen Shot 2016-04-10 at 7.49.57 PM

install composer and make it globally accessible

Unless you have been living under rocks, you have heard about composer already. It is a dependency manager and more than that actually. If your PHP app is using a lot of dependencies, then it is time to consult composer.

Here I will put some notes on how to install it and make it available globally so that you can use it from any directory.

First thing first, go and grab the phar file from composer download page

It would be a single phar file and u can use that as it is:

composer.phar install

Of course you would need the composer.json file for the above to work where you would list the dependencies.

But, this would require you to call the phar from where you downloaded and that might not be handy

cd /to/composer/phar/file
sudo mv composer.phar /usr/local/bin/composer

Now, you can call composer from any directory and rock from there
get more @ get composer
That is how you install composer on linux/mac computer and make it globally accessible with in

a door having a knock knob

Who is calling php script browser or cron

Identifying who calls php script

Php script can called from different places or clients. Do you Want to know which client, browser or command line, is calling your php script?
Wanted to handle differently when the script is called from command line
Then use php_sapi_name

Yeah, this sapi thing – Server API is a bit bad boy. You might want to check a manual value comparison before deploying it your server as the sapi return type might be different for different settings say b/n command line script and webserver.

Also having additional check with $_SERVER and $_ENV variables is also a good one for better guarantee. Like some parameters of the $_SERVER would only be set when called from web server like ‘REQUEST_METHOD’

if (!empty($_SERVER['REQUEST_METHOD'])) {
    echo "hey baby web server, calling you from browser X - wssup";
} else {
    echo "umm.. are you cron? manual? who the heck???";
}

Also using the sapi name

$sapi_id = php_sapi_name();
if (stristr($sapi_id, 'cli')) {
    echo "hello command line interface";
}

Since the above would be a bit more conditional it would be advised if used along with existence of like $_SERVER[‘REQEST_METHOD’]

Using the above snippet, you can tell from which the php script is called from and you can say hello to browser or cron.

a truck loading another truck

Check if curl is loaded as module in php

Here are a couple of things to check if cURL is loaded as module or not

1. You can check by using phpinfo();
Just create a single php file and name it as phpinfo.php file and in it add

phpinfo();

Then call the page on your browser and when it loads do the control plus F and search for curl module there. If you can find it, then it means it is loaded.

2. Create a page and name it as test_curl.php and inside that file, add the following code.

if ( in_array('curl', get_loaded_extensions()) ){
echo "Curl is loaded";
} else {
echo "No, I can't find curl";
}

Either of the above two methods would tell you if you have curl to be used as extension or not

composer shadow image

Composer could not be installed b/c of php.ini setting

trying to install composer on your server and got something like
Some settings on your machine make Composer unable to work properly.

Make sure that you fix the issues listed below and run this script again:
And specifically for suhosin.executor.include.whitelist = phar?

Then the fix is to modify php.ini on the fly while you are passing the installer

sudo curl -sS https://getcomposer.org/installer | php -d suhosin.executor.include.whitelist=phar

That should take care of modifying the php.ini on the fly without you updating the config and re-bouncing the server.

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.