resellerhostinglinuxuk

Reseller Linux Hosting UK 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.

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= '[email protected]';
$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 [email protected]. 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 [email protected]. 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 [email protected]:

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 [email protected].

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 [email protected].

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 [email protected]:

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

Sample Script


$mailto="[email protected]";
$pcount=0;
$gcount=0;
$subject = "Mail from Enquiry Form";

$from="[email protected]";
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";
}
?>

FileZilla

To Upload Content/Files using FileZilla

  1. Open FileZilla and choose Site Manager under the File menu.

  2. Click the New Site button.

  3. Provide the following details, label the entry as yourdomainname.com and click the Connect button:

    Host: yourdomainname.com

    Port: 21

    Protocol: FTP - File Transfer Protocol

    Encryption: Require explicit FTP over TLS

    Logon Type: Normal

    User: FTP Username for yourdomainname.com

    Password: Password for the above FTP User

  4. Select the Always trust certificate in future sessions. option and then click the OK button.

  5. Once connected, open the relevant folder by double-clicking it:

    • cPanel - public_html

    • Plesk - httpdocs

    Note

    Depending upon the Directory/Folder structure of the Web Hosting package, you would need to upload your files to the relevant
    folder. See details

  6. In the left pane, select the files to upload. Right-click and choose Upload.

    The files will be transferred to the remote server.

To Enable Active/Passive Mode FTP (Anchor: ftpmode)

Different modes of data connection can be used during
FTP. See details

There are 2 ways in which the data connection mode can be modified.

Global Settings

  1. Choose Settings under the Edit menu.

  2. The Passive mode for data connection is set by default. Under the Connection section, click FTP and select
    the Active radio button to enable the
    Active mode.

  3. Click OK to save the changes. This change will affect all the sites for whom the data connection mode was set by default.

For Individual Sites

  1. Choose Site Manager under the File menu.

  2. Select yourdomainname.com and click the Transfer settings tab. Here, you can change the data connection
    mode to Active or
    Passive.

  3. Click OK to save the changes. The change is saved and active for future FTP sessions of this site.

WinSCP

To Upload Content/Files using WinSCP

  1. Open WinSCP.

  2. Provide the Host name, User name and Password information, set Port number to 21 and click the
    Save button.

    Uploading content is allowed only through FTPS on Port 21. Hence, besides File Protocol you need to select FTP in the first dropdown menu and
    TLS Explicit encryption in the next.

    Additional Information

    FTPS

  3. Confirm the entry as shown below.

  4. In the Stored sessions section, select yourdomainname.com and click the Login button.

  5. Once connected, open the Web folder by double-clicking it.

    Note

    Depending upon the Directory/Folder structure of the Web Hosting package, you would need to upload your files to the relevant
    folder. See details

  6. Select the desired files in the left window and from the Files menu, click Copy.

  7. Confirm the file transfer by clicking the Copy button.

    The files will be transferred to the remote server.

To Enable Active/Passive Mode FTP

Different modes of data connection can be used during FTP. See details

The data connection mode can be modified in WinSCP client as follows:

  1. Under Stored sessions, select yourdomainname.com and click the Edit button.

  2. Select the Advanced options check box.

  3. By default, the data connection mode is set to Active mode. Click Connection and select the Passive mode check box.

  4. Click the Save button. The change is saved and active for future FTP sessions of this site.