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

 

Jquery form validation with modal dialog box with custom messages

I used the model dialog box, In that form I want to use the jquery form validation. code for Jquery form validation with modal dialog box with custom messages.

Jquery form validation with modal dialog box with custom messages

I used the following HTML code:


<form id="form1" name="form1">
Field 1: <input id="field1" type="text" class="required" />
</form>

<div>
<input id="btn" type="button" value="Validate" />
</div>
<div>
<input id="dialogbtn" type="button" value="Open Dialog" />
</div>

<div id="dialog-form" title="Create new user">
<form id="form2">

<label for="name">Name</label>
<input type="text" name="name" id="name" required="true" />
<br/>
<label for="email">Email</label>
<input type="text" name="email" id="email" required="true" email="true"/>
<br/>
<label for="password">Password</label>
<input type="password" name="password" id="password"/>

</form>
</div>

following is the javascript code:

 


$(function() {
//simple example 1
//click event for first button
$('#btn').click(function() {
$("#form1").valid(); //validate form 1
});

//example to validate inside a dialog box

//dialogopen button click event
$('#dialogbtn').click(function() {
$( "#dialog-form" ).dialog( "open" );
});

//code for dialog
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Save": function() { //on click of save button of dialog
if($('#form2').valid()){ //call valid for form2 and show the errors
//alert('submit form'); //only if the form is valid submit the form
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
}

});
});

 

After this i wanted to added the custom error messages.

I used the following code:


jQuery(function ($) {
$("#form2").validate({
errorLabelContainer: '#errors',
messages: {
email: {
required: "Please enter an email address",
email: "Please enter a valid email address"
},
name: {
required: "Please enter your name"
}
},
submitHandler: function () {
return false;
}
});
});

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 wordpress secure file upload using apache rules

WordPress tutorial, How to wordpress secure file upload using apache rules, Here we given apache rule for secure your wordpress file upload functionality.

How to wordpress secure file upload using apache rules

Website security is most important point of any website. In wordpress we need to give 777 permission to wp-content/uploads folder. Some time we don’t want to give the 777 (read, write and execute) permission to folder due to security reason but wordpress do not allow you to upload images or media files to uploads folder.

Tip: Do not give 777 permission to wp-content/uploads folder. In stead change user ownership to apache folder.

Security

What you can do is. You can restrict other file types to upload in uploads folder using simple apache rule. following code you can use in .htaccess file.


	Order Allow,Deny
	Deny from all

<FilesMatch ".(jpg|jpeg|jpe|gif|png|tif|tiff)$">
	Order Deny,Allow
	Allow from all

Using above code you can secure your uploads folder and only selected files can be pushed into uploads folder.

How to wordpress secure file upload using apache rules
How to wordpress secure file upload using apache rules

How to wordpress add javascript to page template

For many purpose and designs we use the page template in wordpress site. WordPress tutorial for, How to wordpress add javascript to page template. Some time we need to load the custom javascript to page template. Here is code for same.

How to wordpress add javascript to page template

For that we can use following code.

add_action('wp_enqueue_scripts','Load_Template_Scripts_wpapi');
function Load_Template_Scripts_wpapi(){
    if ( is_page_template('custom-page.php') ) {
        wp_enqueue_script('my-script', 'path/to/script.js');
    }
}

For loading any script or any custom code you can use above action in wordpress. Above code you need to add in functions.php file. Which you can find in your wordpress theme folder.

How to wordpress add javascript to page template
How to wordpress add javascript to page template

How to get page id by slug wordpress theme

WordPress tutorial for, How to get page id by slug wordpress theme. First find the page id using page title or page page slug.  we given sample code here.

How to get page id by slug wordpress theme

For post title use following code:

<?php
$page = get_page_by_title( 'About' );
wp_list_pages( 'exclude=' . $page->ID );
?>

For post slug use following code:

 $page = get_page_by_path( 'your-page-slug'
echo $page->ID;

Now List the child page by post slug

if ( $page = get_page_by_path( 'your-page-slug' ) ){
  wp_list_pages( 'orderby=name&depth=1&order=DESC&show_count=0&child_of=' .$page->ID . '&title_li=' );
}

show pdf in post on wordpress

There are people who are struggling for showing PDF file in there wordpress post. Please use following steps for show pdf in post wordpress.

show pdf in post wordpress

1) Go to media -> Add New, upload a file. Once file is uploaded, you will get File URL. Copy that file URL. (Let me call it MY_PDF_URL)

This will be a complete URL, with http://yourdomain.com in it..
2) Now, go to add new post and switch to html editor. Place this code where you want to show the pdf file….

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

<embed src="MY_PDF_URL" width="600" height="400">

This will work smoothly. OR you can use following code as well.


<iframe src="http://docs.google.com/gview?url=https://purabtech.in/wp-content/uploads/yourpdf.pdf&embedded=true" style="width:880px; height:1200px;" frameborder="0">

[/viral-lock]

There are also nice wordpress plugins for showing the PDF in wordpress posts.

Embed PDF

Will embed a PDF file using Google Docs Viewer Simply include the URL for a PDF document on it’s own line, or wrapped in the embed tag like

Click to access file.pdf

and the plugin will embed the PDF into the page using the Google Docs Viewer embed code. The url must end with .pdf

Supported attributes in the embed tag are class id title height and width

GroupDocs Word, Excel, Powerpoint, Image and PDF Annotate

GroupDocs Annotation lets you embed several types of files into your WordPress pages using the GroupDocs Viewer – allowing inline viewing and annotation of the following file types, with no Flash or PDF browser plug-ins required:

  • Adobe Acrobat (PDF)
  • Microsoft Word (DOC/DOCX)
  • Microsoft Excel (XLS/XLSX)
  • Microsoft PowerPoint (PPT/PPTX)

GroupDocs Annotation lets you view and comment on documents online. Its document annotation features makes it a powerful tool for collaboration. You and your colleagues can collaborate on a document, at the same time, to improve communication and speed up document reviews. GroupDocs Annotation lets you work with text-based documents as well as images. You can collaborate on layouts, drawings and designs just as effectively as on articles, stories and corporate documents. In short GroupDocs Annotation lets you annotate on many file formats including PDF’s, Word documents, Excel documents, Powerpoint documents and many other available formats.

show pdf in post wordpress
show pdf in post wordpress

 

for showing flash intro in sites and flash with wordpress website, we have written article. You might need for your website.