Cakephp Invalid key for decrypt(), key must be at least 256 bits (32 bytes) long: Solved

In cakephp 3 I tried to set cookie in my controller using write cookie method. Error got invalid key for decrypt(), key must be at least 256 bits (32 bytes) long – used following line of code.

$this->Cookie->write(‘username’, ‘test’, true, ‘1 year’);

I got following error after execting page.
Invalid key for decrypt(), key must be at least 256 bits (32 bytes) long

Before using cookie write method, I loaded cookie component in appcontroller using following line.
$this->loadComponent(‘Cookie’);

I loaded conponnet in initialize method (appcontroller.php)

After searching I found following solution. I changed app.php file and added following line of code

'Security' => [
        'salt' => '123456789purab@eparinay!@#*$($(',
    ]

Above solution worked for me and it solved issue.

If you are getting this error means your Security.salt in app.php does not have the correct length.

cakephp 3 getOriginalSubject undefined index issue fixed

I am using cakephp 3.1 for development one of my portal. While configuring email Igot undefined index getOriginalSubject in DebugkitTransport.php. I searched for some time on net for solution but I did not find any solution. This function tries to get subject from email obejct. I think this is bug in cakephp 3.1.

My solution is as follows. I opened DebugkitTransport.php file and in send function I changed following line


/fixing issue of $email->getOriginalSubject undefined index
$headers['Subject'] = $email->subject();

Above line fixed my issue and I am able to send email now. I using smtp setting for sending email. I am using following code for one of my site called http://eparinay.com


$email = new Email();
$email->transport('eparinay');
try {
$email->template('eparinay')
->emailFormat('html')
->to($email)
->bcc('purabdk@yahoo.co.in')
->from(['noreply@eparinay.com' => 'eParinay.com'])
->viewVars(array('username' => $username, 'email' => $email))
->subject('eParinay.com: New registration.')
->send();
} catch (Exception $e) {

echo 'Exception : ', $e->getMessage(), "\n";
}

 

Get base url or development URL in cakephp 3 and use in view ctp file

Getting baseurl in any framework is easy. But development URL in cakephp 3 in view file…took time…For adding css or js or other purpose we need base path cakephp.

While doing development my path was http://localhost/cakephp3/. I wanted to fetch that in my site.
Their are many ways we can get the path.

You can use any one method of following :

<?php 
    echo $this->Html->url('/', true)
    echo $this->Html->url('/');
    ?>

Define constant in Config/core.php as given bellow:

define(“BASE_URL”, “localhost/cakephp3/”);

Then you can use BASE_URL in view file.

For view file you can use following code.

<?php echo $this->Url->build('/', true); ?>

I used above code reference to following URL:
http://book.cakephp.org/3.0/en/views/helpers/url.html#generating-urls

 

Solved : Channel pear is already initialized

I faced channel pear installation issue many times on many linux OS. I installed the pear package first then I removed pear package from linux box. Then when I again tried to install the pear package on box I got the following error. I solved the channel pear issue using following commands.

Solved : Channel pear is already initialized

[root@localhost purab]# pear channel-discover pear.cakephp.org
Channel “pear.cakephp.org” is already initialized
[root@localhost purab]# pear install cakephp/CakePHP
No releases available for package “pear.cakephp.org/CakePHP”
install failed

[root@localhost purab]# pear remote-list -c cakephp
File http://pear.cakephp.org:80/rest/c/categories.xml not valid (redirected but no location)

[root@localhost purab]# pear install cakephp/CakePHP
No releases available for package “pear.cakephp.org/CakePHP”
install failed

[root@localhost purab]# pear channel-discover pear.cakephp.org
Channel “pear.cakephp.org” is already initialized
[root@localhost purab]# pear upgrade pear
Nothing to upgrade

Following command is solved my issue and I am able to install pear package successfully.
[root@localhost purab]# pear clear-cache
reading directory /var/cache/php-pear
302 cache entries cleared

[root@localhost purab]# pear install cakephp/CakePHP
Unknown remote channel: pear.phpunit.de
Did not download optional dependencies: channel://pear.phpunit.de/PHPUnit, use –alldeps to download automatically
cakephp/CakePHP can optionally use package “channel://pear.phpunit.de/PHPUnit” (version >= 3.5.0)
downloading CakePHP-2.4.2.tgz …
Starting to download CakePHP-2.4.2.tgz (1,377,541 bytes)
……………done: 1,377,541 bytes
install ok: channel://pear.cakephp.org/CakePHP-2.4.2
[root@localhost purab]#

Use following command command for solve the issue.
#pear clear-cache

Cakephp installation and blog tutorial step by step

CakePHP is one of the best PHP MVC framework which is purely inspired by Ruby on Rails. I worked on ROR for many years. So I know CakePHP has very similar ROR standards. Here In this article I will show you about CakePHP installation on linux box in very detailed information. I created the very basic blog application using CakePHP and It is free for download.

Cakephp installation and blog tutorial step by step

I am using the linux box for installation following commands will be useful for any linux installation. You can use the any linux OS like (Ubuntu, Fedora, Redhat, centos, etc… )

#pear channel-discover pear.cakephp.org
#pear remote-list -c cakephp
#pear install cakephp/CakePHP

Go to folder where you want to create the project
#cd /var/www/html/

Create the project using following command
#cake bake project cakeblog


{
"name": "cakeblog",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"pear-cakephp/cakephp": ">=2.4.0"
},
"config": {
"vendor-dir": "Vendor/"
}
}

#cd cakeblog
#chown purab:purab -R cakeblog
#chown apache:apache -R cakeblog/tmp

Download debug_kit
https://github.com/cakephp/debug_kit
Add into the Plugin Dir

Download commposer
http://getcomposer.org/download/

using following command and console:
#curl -sS https://getcomposer.org/installer | php

Create the composer.json file in cakeblog folder and add following lines in that file

After that execute the following command

#php composer.phar install

Open the webroot/index.php file and add the following lines at line no 82.


define(
'CAKE_CORE_INCLUDE_PATH',
ROOT . DS . APP_DIR . '/Vendor/pear-pear.cakephp.org/CakePHP'
);

You can download my Blog code from Following Link.

[sociallocker]https://github.com/purab/cakeblog[/sociallocker]

Reference Used:
http://book.cakephp.org/2.0/en/getting-started.html#blog-tutorial

http://book.cakephp.org/2.0/en/installation/advanced-installation.html

 

update wordpress user password through phpmyadmin

Many PHP new developer asked my how to update wordpress user password through phpmyadmin. It is very easy trick. Many PHP sites are using Md5 encryption logic for saving the password in database.

Similarly wordpress is using MD5 encryption for saving the password in database. We can easily keep any password and change through phpmyadmin for wordpress users very easily.

First we need to open phpmyadmin in your web-browser. open wp_users tables. You are able to see following screenshot when choose user for edit.

wordpress-user-pass-phpmyadmin

First select user for which you want to edit the password and click on change button. you will be able to see above image.

Important thing is, you need to select MD5 in function column for user_pass field. Than choose your password and click on go button.

It is very simple to change password using phpmyadmin for any php application if that application is using MD5 encryption logic for saving the password.

install php mysql apache on centos 7

In this tutorial we are going to tell you how to install php mysql apache on centos 7 with very easy and simple steps and guide.
LAMP is becoming more popular these day. Many people are using LAMP for server solutions.

Add EPEL-7 to your linux os with latest phpMyadmin.

rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Now install mysql-server and client. first became root user and execute following command
yum install mysql-server mysql
mysql_secure_installation

Install Apache2

CentOS 7.0 ships with apache 2.4. Apache2 is directly available as a CentOS 7.0 package, therefore we can install it like this:

yum -y install httpd

By default apache will be installed, but it is not installed then install apache using above command

Start apache and start apache at boot time using following command

systemctl start httpd.service
systemctl enable httpd.service

In CentOS 7.0 uses Firewall-cmd command, so I will customize it to allow external access to port 80 (http) and 443 (https).

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Now direct your browser to http://192.168.0.109.

Install PHP5

yum -y install php php-common phpmyadmin

We must restart Apache afterwards:

systemctl restart httpd.service

Now time to test php and apache version.
The document root of the default website is /var/www/html. We can create info.php file and put in document root folder

vi /var/www/html/info.php

put following code in that file

<?php echo phpinfo(); ?>

Now we call that file in a browser (e.g. http://192.168.0.109/info.php):

Now we can install some useful PHP moduels which can be required for CMS Systems like WordPress, Joomla and Drupal:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

Now restart Apache2:

systemctl restart httpd.service

congrats! now you installed apache, php and mysql on your system. Now you are able to execute any php application on your server.

install apache 2.4, php 5.5 and mysql on centos 6/7

In the article we will tell you to install apache 2.4, php 5.5 and mysql on centos 6/7 with this we will guide you about installing phpmyadmin and related php and mysql modules.

LMAP is becoming more and more popular these days. People are using more vps and dedicated servers for their sites and applications. PHP backend is became more popular so here in this post we will tell you about installation on linux system’s.

Here I am using centos 6 for installation. From sept 2015 php 5.4 is no longer supported by PHP team so people are trying to install PHP 5.5+ version for good security and performance purpose on their linux servers.

install apache 2.4, php 5.5 and mysql on centos 6/7

Install Remi Repository

Remi is a repository where you can find the latest versions of the PHP  in this repository we can find latest programs and dependencies.

# yum update && yum install epel-release
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Enable Remi Repository

Open following remi.repo file and change enabled=0 to 1 for php55 tag. Here we want to install PHP 5.5 version on centos machine.

# vim /etc/yum.repos.d/remi.repo

After opening this file just edit this file and change enabled flag to 1 for php55 section
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-php55]
name=Remi's PHP 5.5 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php55/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php55/mirror
# NOTICE: common dependencies are in "remi-safe"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
 

Afer enabling remi repository. Now it is time to install PHP and apche and mysql

# yum --enablerepo=remi install httpd mysql mysql-server php php-common mod_php phpmyadmin

Step 4: Installing PHP Modules

Do not forget to accept installation and type Y when you asked while installation.     After installation run following command which will be useful while rebooting server(linux). After rebooting server following service will automatically started.   —— Enable Apache and MySQL on Boot ——

# chkconfig --levels 235 httpd on
# chkconfig --levels 235 mysqld on

—— Start Apache and MySQL ——

# /etc/init.d/httpd start
# /etc/init.d/mysqld start

Verify PHP 5.5

Go to /var/www/html directoy and create file called phpinfo.php using following command.

#vi phpinfo.php

put following code in that file.

<?php echo phpinfo(); ?>

Execute php.info file on your web browser

You can check your installation on command prompt also. For checking php modules use following command.

#Php -m

above command will list all php modules which are installed on your centos machine

Congratulations! Just now you completed your php 5.5, apache and mysql installation on your linux box.

 

how to integrate wordpress into php website

WordPress is very easy to work on. PHP tutorial, how to integrate wordpress into php website. you can very easily integrate the wordpress with php or html site. Here we given code for same.

There may be only a few features of WordPress you want to use when integrating it with your site, or you may want your entire site run with WordPress. This tutorial will guide you through making your WordPress site look like your current design.

how to integrate wordpress into php website

How to start?
First you need to disable the wordpress theme. using following code.

open your header.php file from your wordpress theme and put following code in that file.

<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

Create any php file and put following code in that file.

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

In the event you want to show ten posts sorted alphabetically in ascending order on your web page, you could do the following to grab the posted date, title and excerpt:

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : start_wp(); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
how to integrate wordpress into php website
how to integrate wordpress into php website

For more information you can write to me.

Solved allowed memory size of 33554432 bytes exhausted wordpress

We solved Allowed memory size of 33554432 bytes exhausted which for wordpress. Given solution for allowed memory. Change given for wordpress/wp-config.php file.

Solved Allowed memory size of 33554432 bytes exhausted

We got always following ERROR PHP Fatal error:

Allowed memory size of 33554432 bytes exhausted (tried to allocate 10485761 bytes)

This issue with old and new wordpress versions both. First you need to increase memory limit for your php package. Use following method for increase the memory for php.

Open php configuration file


# vim /etc/php.ini

Change following sections:

max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (16MB)

After this dont forget to restart apache server.

I know on 2.5.1 i needed to increase the memdory, but i don’t know how in 2.6. in the wp-config.php there no define to increase memory. If you are using old wordpress version less than wordpress 2.6 version or you are using the wordpress MU then use following code. open your wp-settings.php file from root folder and change following line

if ( !defined('WP_MEMORY_LIMIT') )
        define('WP_MEMORY_LIMIT', '32M');
to
if ( !defined('WP_MEMORY_LIMIT') )
        define('WP_MEMORY_LIMIT', '128M');

If you are using the newer wordpress version greater than 2.7 then use following method. Following URL is also helpful http://codex.wordpress.org/Editing_wp-config.php

#Increasing_memory_allocated_to_PHP Edit wp-config.php and enter the following line


define('WP_MEMORY_LIMIT', '64M');

If you are using the shared hosting then use following method.

  •  Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site)
  • In php.ini, enter a line that says memory_limit = 64MB 3. In your site’s .htaccess (being a WordPress blog, I’m assuming there is one), enter the following line SetEnv PHPRC // (keep the slashes)
  • Edit wp-config.php and enter the following line

define('WP_MEMORY_LIMIT', '64M');

  • Upload the new files to the server Oh, and don’t tell your hosting provider you’ve done this… This will solve your issue.
Solved Allowed memory size of 33554432 bytes exhausted
Solved Allowed memory size of 33554432 bytes exhausted