Category Archives: CakePHP

PHP Composer update command and Status: 404 Not Found on Linux server

Today I was trying to update Cakephp on my remote server using composer. I tried to follow the commands given at https://getcomposer.org/download/ under Command-line installation but it failed at the very first go. The command line code is:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

My server is a CentOS Linux release 7.4.1708 (Core) server with cpanel install. So, running the first command over there gives me the following error:

Error in argument 1, char 2: option not found r

Which clearly indicates the there is no r argument. If we check the above code in detail this is it tries to do:

  1. It tries to read the installer from give url https://getcomposer.org/installer and write it to a file named composer-setup.php
  2. If the file hash matches the given hash it tells user that install is verified otherwise it says that the Installer is corrupt and delets the file from server.
  3. Runs composer-setup.php
  4. Deletes composer-setup.php from server.

After doing all these steps it would let you run the following command in your directory you installed the composer in:

php composer update. However my method failed and then I found that the composer was already installed on my server at location /opt/cpanel/composer/bin. Since it was installed globaly and not under php php composer wont work at all.

Now if I ran composer update, because it was installed in teh given path it woudl show me the follwoing message:

Composer could not find a composer.json file in /opt/cpanel/composer/bin
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ “Getting Started” section

So all I need is to specify the correct path of my working directory. Doing this worked like a charmfor me:

composer update --working-dir /home/myproject/public_html/

Can’t send an email on cakephp3 using Gmail? Here is the fix!

Do you see:

error- stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)

error when you set email transport to gmail? Your settings might look like this:

'EmailTransport' => [
..........
'gmail' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'xxx@xxxxx.com',
'password' => 'xxxxx',
]
]

Ok. Here is the explaination for this in this thread :

PHP 5.6 verifies SSL certificates by default, and if your cert doesn’t match, it will fail with this error. The correct solution is to fix your SSL config

Solution:

Thanks to the efforts of jagguy at this forum

All you have to do is, to add ssl configuration to the transport settings (in bold), as follows:

'EmailTransport' => [
..........
'gmail' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'xxx@xxxxx.com',
'password' => 'xxxxx',
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]

]
]

Using Cake Bake Console with both CakePHP 2.x and 3.x

I got started with my new CakePHP 3.x project today. As usual I wanted to create a few scaffold using cake bake command. As I already had a CakePHP 2.x setup in my machine. I still needed it and its cake bake commands to run to create any thing while working on the cakephp 2.x project. So is there a way I could use both cake bake consoles for CakePHP 2.x and 3.x respectively, at the same time?

Answer is YES. All we need to do is make some tweaks in order to run them both. Here are what I did.

  • I actually went back into the CakePHP 2.x installation and renamed the cake and cake.bat to cake2 and cake2.bat respectively. There are located in  C:\wamp\www\mycakephp2app\lib\Cake\Console.
  • This step actually was to set path environmental variable manually for CakePHP 3 as I already had set it up for CakePHP 2.x on my windows machine. I actually need them both. So I would add them like this C:\wamp\www\mycakephp2app\bin;C:\wamp\www\mycakephp2app\lib\Cake\Console;(for cakephp 3 it is set automatically.

    If you installed Cakephp 2 after CakePHP was installed you have to set the environmental variable path accordingly)

  • As you might have noticed that I renamed cake and cake.bat shell scripts to cake2 and cake2.bat  respectively I need to run cake2 bake in order to invoke CakePHP baker.

    cake-bake-cakephp-2

How to set Cakephp paginator url for custom Route

I was making a url route like this:

Router::connect('/ca/assets', array('plugin' => 'file_manager', 'controller' => 'file_manager', 'action' => 'assets', 'ca'));

It worked alright with normal urls as- /ca/assets. However when i used paginator in view as

echo $this->Paginator->numbers();

it generates url as- /assets/ca/page:2

I tried different things and at the end, as a work around to this problem I figured out that the following trick works. So make some heck in the $this->Paginator->options() function as the following:

$this->Paginator->options(array(
'url'=>array('controller' => 'ca', 'controller'=>'action', 'plugin'=>false)
));