multidomainhosting

Multi Domain Hosting Linux US Product

PHP Script to Test MySQL Database Connectivity

Provided below is a simple PHP script to test MySQL database connectivity. The result of this script displays the names of the tables present within the specified database.

Sample Script



$connect=mysql_connect("dbserver","dbuser","dbpassword") or die("Unable to Connect");
mysql_select_db("dbname") or die("Could not open the db");
$showtablequery="SHOW TABLES FROM dbname";
$query_result=mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($query_result))
{
echo $showtablerow[0]." ";
}
?>

Explanation about the variables used in the script:

  • dbserver: Mention the value as localhost for Linux Hosting (cPanel). For Windows Hosting (Plesk), MySQL Server IP needs to be mentioned.

  • dbname: Specify complete database name including the prefix. For example, reseloaq_mysql.

  • dbuser: Mention the database user associated with the database.

  • dbpassword: Mention the password for the above database user.

SSH Access

What is Secure Shell (SSH)?

Secure Shell (SSH) is a cryptographic network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that connects, via a secure channel over an insecure network, a server and a client (running SSH server and SSH client programs, respectively). SSH is typically used to log into a remote machine and execute commands. It can transfer files using the associated SSH file transfer (SFTP) or secure copy (SCP) protocols. The standard port used to connect through SSH is 22.

Enabling SSH Access

supports SSH access on all its Linux (Single Domain, Multi Domain and Reseller) Hosting Servers. SSH connection to 's Linux Hosting Servers can be through key or password based authentication.

Connecting to a Server through SSH using Password authentication

For Linux:

  1. Run the below command:

    ssh -l user remote-server
  2. Enter the cPanel password.

For Windows:

  1. Open Putty and enter the Remote Host Name or IP Address.

  2. Click Open and enter the cPanel username and password.

Connecting to a Server through SSH using Key based authentication

Generating a SSH Key Pair

You can generate the key pair (public key and private key) from the cPanel or your local computer.

cPanel

  1. Login to the cPanel of the domain for which you wish to generate the key pair.

  2. Click on SSH Shell Access under the Security section.

  3. Click on Manage SSH Keys.

  4. Click on Generate a New Key.

  5. Enter the key name and password and click on Generate Key.

Note

The private key needs to be stored on your local computer.

  • For Linux, copy the key file to your ~/.ssh folder.
  • For Windows, save the key file to a safe location.

Local Computer

For Linux:

Run the below command:

ssh-keygen -t dsa

OR

ssh-keygen -t rsa

The output would be similar to:

Generating public/private dsa key pair. 
Enter file in which to save the key (~/.ssh/id_dsa): Press [Enter] key 
Enter passphrase (empty for no passphrase): Press [Enter] key 
Enter same passphrase again: Press [Enter] key 
Your identification has been saved in ~/.ssh/id_dsa 
Your public key has been saved in ~/.ssh/id_dsa.pub 
The key fingerprint is: 
<some string>
		

OR

Generating public/private dsa key pair. 
Enter file in which to save the key (~/.ssh/id_dsa): Press [Enter] key 
Enter passphrase (empty for no passphrase): Press [Enter] key 
Enter same passphrase again: Press [Enter] key 
Your identification has been saved in ~/.ssh/id_dsa 
Your public key has been saved in ~/.ssh/id_dsa.pub 
The key fingerprint is: 
<some string>
		

id_dsa or id_rsa is the private key and id_dsa.pub or id_rsa.pub is the public key.

For Windows:

  1. Download PuTTY.

  2. Download PuTTYgen.

  3. Open PuTTYgen.

  4. Select the SSH-2 RSA (or SSH-2 DSA) option and click the Generate button.

  5. Move mouse randomly over the empty space below the progress bar to create some randomness in the generated key.

  6. Click the Save private Key button, without providing any passphrase.

  7. Click Yes on the window asking for confirmation for saving the key without a password.

  8. Save the key file with an appropriate name, say ssh_private_key.ppk.

  9. Upload the public key to the hosting server from the cPanel, using the Import Key option

Authorize the SSH Server to use the Public Key

  1. Click on Manage Authorization for the key you wish to authorize.

  2. Click on Authorize to authorize the key.

  3. Or Deauthorize to deauthorize it.

Accessing the Remote Server

For Linux:

Run the below command:

ssh -l user remote-server

For Windows:

  1. Open Putty and enter the Remote Host Name or IP Address.

  2. In the left menu, click Data under Connection and enter the cPanel username in the Auto-login username field.

  3. In the left menu, click Auth under Connection -> SSH and enter the path of the saved private key file.

  4. Click the Open button to connect to the server.

Ports open for outgoing connections

has opened the following ports for outgoing connections on its Hosting Servers.

Plesk Single Domain Windows Hosting

  • 53

  • 1433

  • 443

  • 80

  • 3306

Plesk Multi Domain Windows Hosting

  • 53

  • 1433

  • 443

  • 80

  • 3306

cPanel Single Domain Linux Hosting

  • 53

  • 43

  • 1433

  • 5432

  • 3306

  • 80

  • 110

  • 143

  • 443

  • 8080

  • 7070

cPanel Multi Domain Linux Hosting

  • 53

  • 43

  • 1433

  • 5432

  • 3306

  • 80

  • 110

  • 143

  • 443

  • 8080

  • 7070

cPanel Reseller Linux Hosting

  • 53

  • 43

  • 1433

  • 5432

  • 3306

  • 80

  • 110

  • 143

  • 443

  • 8080

  • 7070

Perl-based Form Mail (Feedback) Script

Using a Perl script, you may accept feedback from your website visitors and get the results emailed to you. You can use the sample script provided by and tweak it a bit to suit your requirements.

Sample Script


#!/usr/bin/perl
print "Content-type: text/html\n\n";
#
$title='Perl Mail demo';
$to='TO_Email';
$from= 'some-name@yourdomain.com';
$subject='perl mail';

open(MAIL, "|/usr/sbin/sendmail -t");

## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL "This is a test message
mail body text here\n";

close(MAIL);

print "

$title\n\n\n";

print "

$title

A message has been sent from $from to $to

";
#

Note
  • The .pl file containing the script needs to be uploaded to your web server in ASCII mode only.

  • The .pl file needs to have execute permissions for the normal web user. For example, the .pl file can have permissions 755 or 765.

Sample HTML Feedback Form

The following code needs to be added in the form which connects to the above script:

Below is the explanation about the variables in the code:

  • recipient: This would be the email address, where the email containing the data submitted through the form needs to be delivered.

  • email: You would need to change the email address in the email field to any email address on the domain name, on which you are incorporating this script. For example, if you are deploying this script on yourdomain.com, then you would define the From email address as some-name@yourdomain.com. This email address need not be existing on the Mail Server of yourdomain.com; however, the domain name in the email field has to be yours. This implies that you may use an email address such as Do_Not_reply@yourdomain.com. This email address will appear as the From email address in the email sent by the script.

  • realname: The value here indicates the name mentioned in the From section of the email, that will be sent upon submission of this form. This can be modified as per your requirement.

  • subject:The value in this field can be changed to indicate an appropriate subject for the mail to be sent. For example, you may set this as YourDomain.com Feedback Form or any other subject that would allow you to uniquely identify from which form on your website this data has been received.

  • redirect: Once the visitor provides feedback, he/she can then be redirected to another page on your website. In order to achieve this, you need to mention the path to the HTML file in the redirect field. Alternately, you can display a message to the visitor thanking him/her for the feedback. Such messages can be displayed in a new page like thanks.htm. Such a page can also contain other information as deemed necessary.

Note

In an attempt to keep a check on abuse from 's Hosting Servers, the following conditions have been set for mail scripts on 's Linux Hosting Servers:

  • The domain name in either the To or the From email address used in the script should be your domain name hosted with .

    Example: yourdomain.com is hosted with and yourotherdomain1.com and yourotherdomain2.com are hosted with some other hosting provider.

  • For mail scripts with the From email address as <user>@<server_hostname>, the To email address compulsorily should be an email address on your domain name hosted with
    .

    Example: yourdomain.com is hosted with with parent user yourdo & server name cp-00.webhostbox.net and yourotherdomain1.com is hosted with some other hosting provider.

    With the From email address as yourdo@cp-00.webhostbox.net:

PHP-based Form Mail (Feedback) Script

Using a PHP script, you may accept feedback from your website visitors and get the results emailed to you. You can use the sample script provided
by and tweak it a bit to suit your requirements.

You would need to change the email address in the field $from to any email address on the domain name on which you are incorporating this script.

Example:

If your domain name is yourdomain.com, then you would define the From email address as some-name@yourdomain.com.

This email address need not be existing on the mail server of yourdomain.com; however, the domain name in the $from field has to be yours.

You may use an email address such as Do_Not_reply@yourdomain.com.

The value in the $mailto field needs to be changed to the email address, where the email containing the data submitted through the form needs to be delivered.

Note

In an attempt to keep a check on abuse from 's Hosting Servers, the following conditions have been set for mail scripts on 's Linux Hosting Servers:

  • The domain name in either the To or the From email address used in the script should be your domain name hosted with .

    Example: yourdomain.com is hosted with and yourotherdomain1.com and yourotherdomain2.com are hosted with some other hosting provider.

  • For mail scripts with the From email address as <user>@<server_hostname>, the To email address compulsorily should be an email address on your domain name hosted with
    .

    Example: yourdomain.com is hosted with with parent user yourdo & server name cp-00.webhostbox.net and yourotherdomain1.com is hosted with some other hosting provider.

    With the From email address as yourdo@cp-00.webhostbox.net:

Once the visitor provides feedback, you can display a message to the visitor thanking them for their feedback.

Sample Script


$mailto="some-name@yourdomain.com";
$pcount=0;
$gcount=0;
$subject = "Mail from Enquiry Form";

$from="some-name@abc.com";
while (list($key,$val)=each($_POST))
{
$pstr = $pstr."$key : $val \n ";
++$pcount;

}
while (list($key,$val)=each($_GET))
{
$gstr = $gstr."$key : $val \n ";
++$gcount;

}
if ($pcount > $gcount)
{
$message_body=$pstr;
mail($mailto,$subject,$message_body,"From:".$from);
echo "Mail has been sent";
}
else
{
$message_body=$gstr;
mail($mailto,$subject,$message_body,"From:".$from);
echo "Mail has been sent";
}
?>