Configure Web Server for Magento [Ubuntu, Nginx…] (Part 1)

There are some default good practice when installing/configure a server and I think is good to follow them and improve where is possible.

I tend to use [ apt ] instead of  [ apt-get ] as they are almost the same: apt is designed for end-users (human) and its output may be changed between versions > Means the output is more reach and pleasant.

Read more “Configure Web Server for Magento [Ubuntu, Nginx…] (Part 1)”

Troubleshooting SOAP: requesting multiple elements

I’m integrating the Whistl shipping carrier in our custom framework through SOAP protocol.

The fastest way is to build an array with all the required elements and send it to Whistl API.

Working with SOAP in php is very simple. Especially when you use the array as a container to pass to SOAP.

Example of SOAP initialisation and the method to be called with the array:

// initiate the soap request
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));

// Building the array 
$DespatchParcel = array(
 ...
);

// my method was DespatchParcel
// and the array was build into 
$result = $client->DespatchParcel($DespatchParcel);

But later, going a bit closer through documentation spotted this bit of requirement for the request:

<ifor1:ParcelProducts>
  <ifor1:parcelProduct>
    <ifor1:Code>30205958</ifor1:Code>
    <ifor1:Quantity>1</ifor1:Quantity>
  </ifor1:parcelProduct> 
  <ifor1:parcelProduct>
    <ifor1:Code>30205959</ifor1:Code>
    <ifor1:Quantity>2</ifor1:Quantity>
  </ifor1:parcelProduct> 
</ifor1:ParcelProducts>

And at that moment I realised, there’s no way I could pass multiple elements with the same tag (<parcelProduct> ) using the array.

Overcome the multiple elements restriction

Tried multiple approaches and the best solution (the one and only one)  was to use the empty generic php Object.
It allows you to pass a request with same multiple elements, for example the upper XML request would look like:

// new object 
$DespatchParcel = new stdClass();

$parcelProduct1 = new stdClass();
// assign property 
$parcelProduct1->Code = "30205958";
$parcelProduct1->Quantity = "1";

$parcelProduct2 = new stdClass();
$parcelProduct2->Code = "30205959";
$parcelProduct2->Quantity = "2";

$ParcelProducts = new stdClass();
$ParcelProducts->parcelProduct = $parcelProduct1;
$ParcelProducts->parcelProduct = $parcelProduct2;

$DespatchParcel->ParcelProducts = $ParcelProducts;

After the object is properly build and is passed to the method as in the following example:

// Make the SOAP call 
$result = $client->DespatchParcel($DespatchParcel);

That’s what I’m calling a neat solution 😀 !

P.S. Don’t forget to pass every bit of code through GIT, that’s a life saver.

MAMP Error – Unable to load dynamic library redis.so

I’m at the end of my patients, God knows what was update, MAMP or Brew or something else but I ended with this nasty error for Redis integration:

Warning: PHP Startup: Unable to load dynamic library 
'/Applications/MAMP/bin/php/php5.6.32/lib/php/extensions/no-debug-non-zts-20131226/redis.so' - dlopen(/Applications/MAMP/bin/php/php5.6.32/lib/php/extensions/no-debug-non-zts-20131226/redis.so, 9): image not found in Unknown on line 0

Whaaat was that?

Ok, I know I don’t have the redis library or php is not able to load dynamically the library therefore  I fixed this couple times through different methods, like:

  • install the library through brew
  • install phpredis through macport

But, I have MAMP I don’t want to mess with brew if it’s not necessary, I want to keep it simple and mostly I need a damn quick solution.

I need redis in my project otherwise I would disable the extension from php.ini .

Solution:

Anyway, decided to take the straight approach. The error says it doesn’t have the redis.so in that location. A short search on google revealed a github project with Pecl redis Extension for MAMP 3.x & 4.x I forked the project so it would be available at any point at this location: https://github.com/obsergiu/php-redis-mamp.  And:

  1. From the upper error got the version of php: php5.6.32
  2. Checked if the path from the upper error exists:
    1. Open Finder
    2. Pressed the combination of keys CMD+SHIFT+G or from top menu Go > Go to Folder and past the path from the error:  /Applications/MAMP/bin/php/php5.6.32/lib/php/extensions/no-debug-non-zts-20131226/ if it opens we’re good to go and skip (c).
    3. In terminal just run the following command which will create the entire folder structure (the folder might look different for a different version of PHP):
      mkdir -p /Applications/MAMP/bin/php/php5.6.32/lib/php/extensions/no-debug-non-zts-20131226/
  3. Download from github the redis version closer to what php version you have and save to(created directory): /Applications/MAMP/bin/php/php5.6.32/lib/php/extensions/no-debug-non-zts-20131226/

That’s it, that’s everything. I saved the file in the location it was looked by MAMP and everything works properly.

PHP extension mcrypt, intl, … missing as composer uses default environment

I got a bit tired of this error, it’s a bit of nightmare to setup Magento2 on OSX using the MAMP PRO PHP in CLI.

As composer is not able to pick the MAMP php but instead is loading the native one (if u’re in a hurry go to end of article, to update 2, for the solution).

The entire error looks like this:

Problem 1
- Installation request for magento/framework 100.1.5 -> satisfiable by magento/framework[100.1.5].
- magento/framework 100.1.5 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

Problem 2
- Installation request for magento/magento2-base 2.1.5 -> satisfiable by magento/magento2-base[2.1.5].
- magento/magento2-base 2.1.5 requires ext-intl * -> the requested PHP extension intl is missing from your system.

Problem 3
- Installation request for magento/product-community-edition 2.1.5 -> satisfiable by magento/product-community-edition[2.1.5].
- magento/product-community-edition 2.1.5 requires ext-intl * -> the requested PHP exte
nsion intl is missing from your system.

Read more “PHP extension mcrypt, intl, … missing as composer uses default environment”

M2 Defining a plugin

A plugin is used to extend or modify a public method’s behaviour by applying code before, after, or around that observed method.

The first argument for the before, after, and around methods is an object that provides access to all public methods of the observed method’s class.

Note: The rest of the parameters for these functions are depending on the function type (before, after, around) – they are having a dynamic number of parameters.

Read more “M2 Defining a plugin”