Archive for June, 2009

SBDavid

Alternative PHP cache (APC)

Alternative PHP cache (APC)

Alternative PHP Cache (APC) is a PHP extension for caching data and compiled code from php accelerator. It helps to improve the performance of the webserver. The steps to install APC in cpanel are as follows:

Get the latest version of APC from http://pecl.php.net/package/APC

# cd /usr/local/src
# wget http://pecl.php.net/get/APC-3.0.14.tgz
# tar -zxvf APC-3.0.14.tgz
# cd APC-3.0.14

You can find the path of phpize and php-config using which command.

#which phpize
#/usr/local/bin/phpize
#which php-config
#/usr/local/bin/php-config

Now use these details to complete installation.

# /usr/local/bin/phpize
# ./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/local/bin/php-config
# make
# make install

Add the following lines within the Dynamic Extensions section of php.ini as given below.

extension=apc.so
apc.shm_size = 32

After make install, you will get the extension path like this,
extension=”/usr/local/lib/php/extensions/no-debug-non-zts-20020429/apc.so”
confirm whether extension directory is defined in php.ini.
extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20020429″
If not you should give the full path in php.ini instead of just ‘extension=apc.so’. Like this,

extension=”/usr/local/lib/php/extensions/no-debug-non-zts-20020429/apc.so”

Restart httpd. Now you can see the apc section enabled in phpinfo() page.

Script to transfer an restore mass cPanel accounts.

cPanel Data transfer.

Setup the servers to ‘SSH without password.

The below given is the script to transfer.

#!/bin/bash

for i in `cat /etc/trueuserdomains | awk -F: ‘{print $2}’`
do
/bin/echo “$i”
/scripts/pkgacct $i
file=$(ls /home/cpmove*$i*)
/bin/echo “$file”
scp -P PORT $file root@IP:/root
wait
ls -lh $file
rm -rf $file
done

cPanel Data restoration.

The script is given below. Move to the location whether the cpmove files are located and then execute the following.

# ls cpmove-*.tar.gz | awk -F- ‘{print $2}’ | awk -F. ‘{print $1}’ > file
# for i in `cat file`; do /scripts/restorepkg $i; done

Creating a Ruby On Rails application in Cpanel

Ruby On Rails icon is there in cpanel theme from cpanel 11 onwards.
You can create a Ruby On Rails application in cpanel by following steps given below.

1. Login to cpanel
2. Click on the Ruby On Rails Icon in cpanel.
3. Fill in the “App Name” box with the application name you want to use.
4. Check the box for “Load on boot’.
5. Application Path will be automatically filled in as public_html/application_name.

You can create the application in this location itself. But, if you are installing this inside public_html, the configuration files will be public and everyone can access it. In order to avoid this, change the permission of the configuration files to 600. The main configuration file in which mysql passwords are stored is database.yml(Path: path_to_application/config/database.yml).

Or, you can install the application outside the public_html directory(in the home directory itself). Then you should set redirect to this application through apache to the mongrel port from the cpanel >> Ruby On rails>>Redirects. Mongrel is the default webserver for RoR applications, which will be installed in the server when we install ruby using using /scripts/installruby.

6. Select the environment. The default environment in which the application will be created is ‘production’.

7. Click “Create”.

Application will be created in the specified path.

All the newly created application will be using a port(>12000).

If the application name is test and installation directory /home/username/public_html/test, then you can access the application using http://domainname/test/public/ (Use ‘/’ at the end which is the good method).

How to enable viewing HTML content in Horde.

By default it is not possible for us to view the emails in HTML format using Horde webmail interface. All the html content will be displayed at the top of the page and will be requested to download.

To fix this issue, you have to enable “Inline HTML message viewing” for Horde in the server.

To enable “Inline html message viewing” you can perform the following steps:

1. Goto the horde imp configuration folder at /usr/local/cpanel/base/horde/imp/config

2. Edit the file mime_drivers.php using your favorite editor.

3. Change the following line
————————————————————
$mime_drivers['imp']['plain']['inline'] = false;
————————————————————

To

————————————————————
$mime_drivers['imp']['plain']['inline'] = true;
————————————————————

4. Restart the cpanel service in the server.

Now you will be able to view the html content using Horde webmail interface.

SBDavid

Testing PHP-MySQL connection

Testing PHP-MySQL connection

dbHost = IP address of the remote database server.
dbname= give the database name
dbuser= database user
dbPass= the password of the user.

Add this script to your public_html (ie: name it dbtest.php) for your site and access it via browser and check whether the user is able to connect.

<?php
$dbHost = ” “;
$dbName = ” “;
$dbUser = ” “;
$dbPass =
$dbType = “mysql”;
mysql_connect($dbHost, $dbUser, $dbPass) or die(”could not connect “.mysql_error());
mysql_select_db($dbName) or die(”could not select db “.mysql_error());
echo “db selected”;
?>

« Prev - Next »