• About Sarwar
  • Portfolio
  • আমার বাংলা

sarwar's weblogs

~ story of web applications…..

sarwar's weblogs

Category Archives: PHP

how to install whm/cpanel and change php settings and make PHP DSO

04 Saturday Dec 2010

Posted by Sarwar in Linux, PHP, WHM/cPanel

≈ 10 Comments

Tags

cPanel, PHP DSO, PHP Suexec, WHM


I used rackspace cloud to create a fresh new server with CentOS,

Login as root and used the following command

Configure the network and host
Open /etc/sysconfig/network and put HOSTNAME= your FQDN host name

[root@localhost ~]# nano /etc/sysconfig/network
HOSTNAME=server.domain.com

Update your host go to /etc/hosts

[root@localhost ~]# nano /etc/hosts

Change file to

127.0.0.1        localhost localhost.localdomain
67.12.145.20    host.domain.com  host

Now set hostname from command line

[root@localhost ~]# hostname host.domain.com

restart the network services

[root@localhost ~]# /etc/init.d/network restart

Update your server

[root@localhost ~]#  yum update

Install Perl

[root@localhost ~]#  yum install perl

Download WHM/cPanel installation files

[root@localhost ~]# wget http://layer1.cpanel.net/latest

Start cPanel installation, installation will take several hours so leave your ssh for several hours and check that your net connection is not down until installed it.
Note: when you install cPanel your ip must be authorized by cPanel, or you can registered for trial version, you can verify your ip address from http://www.cpanel.net/apps/verify/index.cgi

[root@localhost ~]# sh latest

You might me see the following message after finished the intall

cPanel Layer 2 Install Complete

Before going to web, you might get some firewall issue, so sometime you need to disable it, you maybe need to disable iptables use the following command

[root@localhost ~]# /etc/init.d/iptables stop

Web access: now you can access your cpanel from http://YOUR_IP:2026, or https://YOUR_IP:2087 and use user as root and your server root password. [YOUR_IP might me your ip or your domain address]

After login you need to give basic setup information of cPanel like network interfaces, nameserver configuration, FTP/Mail etc.

Now our target is to enable PHP DSO and add more features like GD, TTF, MbSring, IonCube etc.

You can see in software section of left navigation “Easy Apache (Apache Update)” click on it
Step 1 Profile : check previous profile and click on the Next
Step 2 Apache Version: select your required apache version and click on Next
Step 3 PHP Major Version: select your required major php version.
Step 4 PHP Minor Version: select your required minor php version.
Step 5 Short Options List: click on Exhaustive Options List and check all your require php settings

Now save your profile and build.

Build will take 40 min appropriately, wait for it. after finished the build You’ll have a popup confirmation box and you need to select DSO from dropdown. and save the configuration.

Now You have php with DSO.

I worked on it and its working with me very well. 🙂

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

install ioncube loader in ubuntu

02 Tuesday Nov 2010

Posted by Sarwar in Linux, PHP

≈ 1 Comment


Download the current version of ioncube, check your system architecture, my system architecture is x86

  wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz

Now extract the tar file,

  tar -zxvf ioncube_loaders_lin_x86.tar.gz

Now move to extract files to your specific location, here I put the folder to /user/local/lib/

  sudo mv ioncube/ /usr/local/lib/

Now add referance to your php.ini file

  zend_extension = /usr/local/lib/ioncube/ioncube_loader_lin_5.3.so

Restart apache

  sudo /etc/init.d/apache2 restart

Done.

How to verify: Please print phpinfo() and notice the following red rectangular, its should say “”With the ionCube PHP Loader v4.0.1, Copyright(c) 2002-2010, by ionCube Ltd”

Its verified.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

direct to specific page instead of get variable www.domain.com/username using php and .htaccess

31 Sunday Oct 2010

Posted by Sarwar in .htaccess, PHP

≈ 6 Comments

Tags

.htaccess, PHP, url rewrite


Sometime we need to get direct access any specific page. We need a user profile page http://www.domain.com/username, but our actual url is http://www.domain.com/profile/profile.php?username=Abc

I’m trying to describe how to make the url friendly, I used .htaccess and php for rewrite the url.
.htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?uri=$1 [QSA,L]

In this case the uri took parameter after index.php file.
So if url is http://www.domain.com/username
uri will have the value uri=useranme

We need following code to retrieve the parameter.

 $_SERVER['QUERY_STRING']

I followed the following way inside index.php file to get the username

  $flag = false; 
  if(isset($_SERVER['QUERY_STRING']))
  {
      $q = $_SERVER['QUERY_STRING'];
      $data = explode("=",$q);  // Assume uri=username 
      if(isset($data[0]) && isset($data[1]) && $data[0] == 'uri')
      {
          $a = $data[1];
          $q = "SELECT * FROM user_profiles WHERE user_profile_name = '$a'";
          $cnt = mysql_num_rows(mysql_query($q));
          if($cnt > 0)
          {
             include("profile/profile.php");
             $flag = true;
          }
          
      }
      
  }
if($flag == false)
{
   include("home.php") // your index or homepage 
}

So above code I tried to find the uri and check it on database if username/profile name exists or not. If it found I include the profile page. if not then include the homepage. After including profile.php page, all variables (only above include) are available in profile.php file.

its working with me very well.

You may have better solutions. But I need it very urgent that’s why I write the code in this way. If you have better solution please share your thoughts.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

joomla Virtumart Redirect Problem Solved

16 Thursday Sep 2010

Posted by Sarwar in Joomla, PHP, Virtumart

≈ 3 Comments


I faced redirection problem on all the form of virtumart. I used joomla 1.5.15 and virtumart 1.1.4.

The problem is when user register and submit the form it move to index.php(home) page. same problem on checkout section for Next button or when I change/add shipping address, its always redirect to home page. I have found some solution someone suggest to change action url from “PHP_SELF” to “REQUEST_URI”, it worked for some form but not all the form.
I have fount one solution which is really great, here is that

1. Find the file ‘libraries/joomla/application/application.php’
2. Find these 2 lines (they are located somewhere around line #191)

// get the full request URI
$uri = clone(JURI::getInstance());

put the following code after the above line

// VM uri fix
		if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
			if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
				$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
			}
			if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
				$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
			}
			parse_str($uri->_query, $uri->_vars);
		}
		// end VM uri fix

Its worked, each and every form of virtumart working properly.

source: http://forum.virtuemart.net/index.php?topic=34989.msg168558#msg168558

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

check username availability on keypress using jquery

26 Wednesday May 2010

Posted by Sarwar in Ajax, JavaScript, jquery, PHP

≈ 3 Comments

Tags

ajax, availability, jquery, keypress, keyup, validation


Username or email availability or any other types of availability check we can do in this way. When user type on a text box an ajax request has made and check what if its available or not.  we only required jquery.js

HTML CODE:

<input name="username" type="text" id="username" />
<label id="user_msg" style="color:#CC0000;"></label>

Javascirpt:

$(document).ready(function() {

		var timeOut = null;	// this used for hold few seconds to made ajax request

		var loading_html = '<img src="ajax-loader.gif" />'; // just an loading image or we can put any texts here

		//when button is clicked
		$('#username').keyup(function(e){

			// when press the following key we need not to make any ajax request, you can customize it with your own way
			switch(e.keyCode)
			{
				//case 8:   //backspace
				case 9:		//tab
				case 13:	//enter
				case 16:	//shift
				case 17:	//ctrl
				case 18:	//alt
				case 19:	//pause/break
				case 20:	//caps lock
				case 27:	//escape
				case 33:	//page up
				case 34:	//page down
				case 35:	//end
				case 36:	//home
				case 37:	//left arrow
				case 38:	//up arrow
				case 39:	//right arrow
				case 40:	//down arrow
				case 45:	//insert
				//case 46: 	//delete
					return;
			}
			if (timeOut != null)
			    clearTimeout(ajaxCallTimeoutID);
			timeOut = setTimeout(is_available, 1000);  // delay delay ajax request for 1000 milliseconds
			$('#user_msg').html(loading_html); // adding the loading text or image
		});
  });
function is_available(){
	//get the username
	var username = $('#username').val();

	//make the ajax request to check is username available or not
	$.post("availability.php", { username: username },
	function(result)
	{
		if(result != 0)
		{
			$('#user_msg').html('Not Available');
		}
		else
		{
			$('#user_msg').html('<span style="color:#006600;">Available</span>');
		}
	});

}

PHP: Put your way to searching, you can make any array search or you can check it from database or flat file. I check it from database here is the code

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('db_name');
$username = mysql_real_escape_string($_POST['username']);
$result = mysql_query('select username from user_table where username = "'. $username .'"');
$cnt = mysql_num_rows($result);
print($cnt);
?>

Its work with me very well 🙂

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

how to cakephp in a sub-directory, access it from root using .htaccess

16 Tuesday Mar 2010

Posted by Sarwar in CakePHP, PHP

≈ 13 Comments

Tags

.htaccess, CakePHP, sub-directory, url


Sometime we may need to put cakephp in a sub directory insted of document root directory, and we need to get the site from root.
Our document root directory is /httpdocs/ and we put the cakephp inside it /httpdocs /cake_sub/ and we want access the site from http://www.my-domain-name.com not http://www.my-domain-name.com/cake_sub

1. In this case we need to create a .htaccess file and put it to /httpdocs/ and the content is as follow

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule    ^$ cake_sub/app/webroot/    [L]
RewriteRule    (.*) cake_sub/app/webroot/$1 [L]
</IfModule>

So we need to on the RewriteEngine Now we need to edit the .htaccess files from the following locaiton

  • cake_sub/
  • cake_sub/app
  • cake_sub/webroot

2. Need to edit the .htaccess from /httpdocs/cake_sub as following


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
3. Need to edit the .htaccess from /httpdocs/cake_sub/app as following
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/app/
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

4. Need to edit the .htaccess from /httpdocs/cake_sub/app/webroot as following

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cake_sub/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


Done, It worked with me and hope it’ll work with you too. I just put the document root httpdocs and sub directory name as an example.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

passing get variable in cakephp pagination url

12 Tuesday Jan 2010

Posted by Sarwar in CakePHP, Framework, PHP

≈ 17 Comments

Tags

argument, CakePHP, GET, pagination, paginator, parameter passed, PHP


For searching we many need to pass variable like ?keyword=test, and we may need to add pagination withen the search, Here I describe multiple cases where we may need to use pagination and how we manage the url for pagination when we make some searching

Case 1: if the url like the following
http://www.mydomain.com/controller/method/?keyword=test1&opt=test2

In this case we need to add the paginator option like this
First we retrive the passing variable and assign value, we can get it from “$this->params[‘url’]

$urls = $this->params['url']; $getv = "";
foreach($urls as $key=>$value)
{
if($key == 'url') continue; // we need to ignor the url field
$getv .= urlencode($key)."=".urlencode($value)."&"; // making the passing parameters
}
$getv = substr_replace($getv ,"",-1); // remove the last char '&'

Now we have the all get parameter, lest assign this to paginator option

$paginator->options(array('url' => array("?"=>$getv)));

Now all the pagination links always taking this get parameter so now if we gos to the next page the url look like this
http://www.mydomain.com/controller/method/page:2?keyword=test1&opt=test2

Now If we need passing an argument as id like the following
http://www.mydomain.com/controller/method/1/?keyword=test1&opt=test2
where 1 is an id or something we get this 1 from $this->passedArgs[0] So now we have to set the paginator option like this

$paginator->options(array('url' => array($this->passedArgs[0],"?"=>$getv)));

If we have passed more than one argument, we need to take it

$pass_argument = $this->passedArgs[0]."/"$this->passedArgs[1]."/".$this->passedArgs[2]."/";
$paginator->options(array('url' => array($pass_argument,"?"=>$getv)));

It depend on you how much you want to passed the argument, if you faced any problem print the $this->passedArgs and see how it organize the argument. Its really easy and I’ve already used it. Cheers

–new update
I got the idea from comments, here is update, the following code will useful for multiple arguments or params.

//extract the get variables
$url = $this->params['url'];
unset($url['url']);
$get_var = http_build_query($url);

$arg1 = array(); $arg2 = array();
//take the named url
if(!empty($this->params['named']))
$arg1 = $this->params['named'];

//take the pass arguments
if(!empty($this->params['pass']))
$arg2 = $this->params['pass'];

//merge named and pass
$args = array_merge($arg1,$arg2);

//add get variables
$args["?"] = $get_var;

$paginator->options(array('url' => $args));

done.. But I’m trying to make better solution, will update it soon.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

how to get/configure file/image browser for tinymce editor

08 Wednesday Jul 2009

Posted by Sarwar in JavaScript, PHP, tinymce

≈ 34 Comments

Tags

image browser, session, tinymce, upload, WYSIWYG Editor


tinybrowser is great plugins for tinymce and we can easily upload images/files and file browser.  It’s work with tinyMCE v3.2. I’ve describe the detail configuration here.

  • Download tinymce and extract.
  • Download tinybrowser, its distributed under the GNU General Public License.
  • Extract and copy to \tiny_mce\plugins\
  • Open config_tinybrowser.php file and set the upload directory

$tinybrowser['path']['image'] = '/upload/images/'; // Image files location - also creates a '_thumbs' subdirectory within this path to hold the image thumbnails
$tinybrowser['path']['media'] = '</span><span style="color: #800000;">/upload/images/</span><span style="color: #800000;">'; // Media files location
$tinybrowser['path']['file']  = '</span><span style="color: #800000;">/upload/images/</span><span style="color: #800000;">'; // Other files location

You can change the upload path dynamically, we’ll discuss it end of this session.

  • Ensure that the upload directories are writable (0777 permission)
  • You have to call “tb_tinymce.js.php” before calling “tiny_mce.js”

<script language="javascript" type="text/javascript" src="<?php echo url::js_dir()?>tiny_mce/plugins/tinybrowser/tb_tinymce.js.php>"></script>
<script type="text/javascript" src="<?php echo url::js_dir()?>tiny_mce/tiny_mce.js"></script>
  • In you initialization of tiny_mce you have to add file_browser_callback : “tinyBrowser”,
  • The following is the full code, the bold is for tinybrowser plugins

<script language="javascript" type="text/javascript" src="js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php>"></script>
<script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script></span>

<span style="color: #993300;"><textarea id="adesc" name="adesc"></textarea></span>

<span style="color: #993300;"><script>
tinyMCE.init({
// General options
mode : "textareas",
mode : "exact",
elements : "adesc",
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,advhr,advimage,advlink",
<strong> file_browser_callback : "tinyBrowser",</strong></span>

<span style="color: #993300;">theme_advanced_buttons1 : "forecolor,backcolor,|,bold, italic,underline,strikethrough,| ,justifyleft,justifycenter,justifyright,justifyfull, styleselect,formatselect,fontselect, fontsizeselect",
theme_advanced_buttons2 : "pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent, blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup, help,code,|,insertdate, inserttime, preview",
<strong> theme_advanced_buttons3 : "",</strong></span>

<span style="color: #993300;">theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
<strong>convert_urls : false</strong>,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",</span>

<span style="color: #993300;">// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",</span>

<span style="color: #993300;">// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
  • Click on the image button, a popup window open and you can see an icon appear beside image url click on and a another new window open which is our image browser, we can browse images and upload image from there.
  • Now If you run it can work 🙂

Path Change While Add imge to editor:
When we upload an image and put it to editor its path has been changed. If we save the output to database, and we need to show in different location then we have faced some problem, Just add convert_urls : false  to tinyMCE.init(). So the path will not be changed.

Session Control:
We can use session in tinybrowser. See …/tiny_mce/plugins/tinybrowser/config_tinybrowser.php

//session_start();
//$tinybrowser['sessioncheck'] = 'authenticated_user'; //name of session variable to check

Just comment out the above line and the additional line.

$_SESSION[$tinybrowser['sessioncheck']] = "YES";

New you can uses session here.

Dynamic Upload Directroy:
We may need dynamic upload directory, like each user has their own upload folder. It can possible by using session variable.

Step 1:
Just add a get parametter while we diclearning the tb_tinymce.js.php the say in php, $upload_path = “/user1/dir/upload/”

<script language="javascript" type="text/javascript" src="js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php?upload_path=<?=urlencode($upload_path);?>"></scrip>

Step: 2
Open file “/js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php” and add the following two line at the top to page.

session_start();
$_SESSION['upath'] = $_GET['upload_path'];

Step: 3
Open “js/tiny_mce/plugins/tinybrowser/config_tinybrowser.php” and change the assignment op upload directory like the following [Note you must comment out the session strat on this page as i’ve describe it above]

$tinybrowser['path']['image'] = $_SESSION['upath'].'images/'; // Image files location - also creates a '_thumbs' subdirectory within this path to hold the image thumbnails
$tinybrowser['path']['media'] = $_SESSION['upath'].'media/'; // Media files location
$tinybrowser['path']['file']  =$_SESSION['upath'].'files/'; // Other files location

I’ve successfully run it and use for different directory for different modules. Just assign value to $upload_path, it depend on you how you change the path but make sure all upload directory always writable (permission 0777)

Share this:

  • Tweet
  • Email

Like this:

Like Loading...
Newer posts →

Author

  • Sarwar

Categories

  • .htaccess
  • Apache
  • API
  • CSS
  • Debug
  • Framework
    • CakePHP
  • HTML
  • JavaScript
    • Ajax
    • ckeditor
    • jquery
    • jQuery UI
    • tinymce
  • Joomla
    • Virtumart
  • Linux
  • MySQL
  • PHP
  • SVN
  • Twitter
  • WHM/cPanel
View Sarwar Hossain's profile on LinkedIn
Follow bdsarwar on Twitter

Tweets

  • “Running a small business without a plan is a lot like driving without directions.” — @GoldmanSachs via @appexchange    4 years ago
  • RT @TechCrunch: 5K people turn up to catch Pokémon in Chicago tcrn.ch/2aaLRys https://t.co/VVQSd7nmN4    4 years ago
  • linkedin.com/slink?code=eZ2… @ibneha, @mdthanvirahmed, @shafi_aszad, @ashrafulkauser, @digitalstatusbd, @eternolimited, @mamunha34354847    4 years ago
  • linkedin.com/slink?code=eYt… @html50, @bdwasif, @81faabfaa6f34a8, @saimonsajid, @voipworldcalls, @sarwar31945, @tomamuns    4 years ago
  • linkedin.com/slink?code=ewd… @ataharhh, @shariful51, @akhtar_h, @litetechno, @tahsin_wsit, @noormd25522880, @abmukid11    4 years ago
  • linkedin.com/slink?code=ewA… @solamanraji, @mycomplain, @washimk118_s, @audacity_it_ltd, @jibonbikash, @salimshalimm784, @mukul_politeboy    4 years ago

Flickr Photos

From Helipad ViewAbove the CloudHillNear to SkySunset Moment#sunset #beach #ocean #coxsbazar#jamroll #food #deliciousfood #homemade  #homemadefood#seaside #ocean #oceanview #travelphotography #coxsbazar #bayofbengal #travel #longestbeach#beach #lifeguard #seaside #holiday #tour #longestbeach #travel #travelphotography #coxsbazar #bayofbengal#resort #mountains
More Photos

Archives

  • February 2012 (1)
  • January 2012 (2)
  • August 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (2)
  • April 2011 (1)
  • March 2011 (3)
  • December 2010 (3)
  • November 2010 (1)
  • October 2010 (4)
  • September 2010 (1)
  • June 2010 (1)
  • May 2010 (2)
  • April 2010 (1)
  • March 2010 (1)
  • January 2010 (2)
  • July 2009 (1)
  • January 2009 (1)
  • August 2008 (1)

Recent Comments

  • SolkAgoks on quick setup of Auth Component for CakePHP 2.0
  • Kush on how to cakephp in a sub-directory, access it from root using .htaccess
  • CharlesLaula on Drag and Drop dashboard using jquery and save state of each change
  • ror on set & reset form text value onfocus, onblur, onclick using javascript
  • Mr Griever on Access session data in a model -cakephp
  • RSS - Posts
  • RSS - Comments

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Blog at WordPress.com.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
Cancel
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
%d bloggers like this: