Wednesday 17 July 2019

Resolving PHP Auto emails from Linux Server Hostings

When you create new websites , a frequent requirement will be sending automatic mail notifications from Enquiry Forms, sending mail activations, forget password links, product enquiries.etc. When you host website in linux hosting , there are restrictions on mail sending. This is mainly due to the increase in number of spam mails all over the world. it is being noted that spammers are sending phishing mails through many domains even without having any login details. So the server people accept only SMTP secure mail transmission for this. I will be using PHP mailer for sending mails.

1) Download PHPMailer script from Github:- 

2) Now  you have to create an email account if you already didn't have and note the password of the same.Make sure to Enable DKIM,SPF and PKR for servers not marking it as spam.

3) Now in the project copy the phpmailer folder into the root folder of project.now in the script you want to send mail,include this code:-

date_default_timezone_set('Etc/UTC');

require 'PHPMailerAutoload.php';

//Create a new PHPMailer instance 
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP                                                                                     $mail->isSMTP();                                                                                                    //Enable SMTP debugging.This you can use to check the working. for testing put to 2 and check mails going or no.In production environment,put it as 0.
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.domain.com";
//Set the SMTP port number should be ssl settings smtp port 465
$mail->Port = 465;
//Whether to use SMTP authentication,dont forget to put this line.
$mail->SMTPAuth = true;
$mail->SMTPSecure = true;

//Username to use for SMTP authentication
$mail->Username = "info@domain.com";
//Password to use for SMTP authentication
$mail->Password = "mYP@$$w0rd";
//Set who the message is to be sent from
$mail->setFrom('user@domain.com', 'Name');
//Set an alternative reply-to address
$mail->addReplyTo('user@domain.com', 'Name');
//Set who the message is to be sent to
//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($msg);
//Replace the plain text body with one created manually
$mail->addAddress($email_to, 'User');
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

Tuesday 16 July 2019

Exporting Large Database From Linux Server Hosting

For exporting database more than certain size, PHPMYADMIN will give you timeout errors. For effective tackling the same, we need to do it via SSH. Here am going to show you, how to do it in linux server.

1) Enable Shell access in server

In your cpanel, dashboard you can see "manage Shell" option. Just click on that.
After that, we have to enable SSH access. Then we will get ssh port and details through this. If you want to use external terminal access softwares like putty, you can use those connection details. But here am explaining about how we can do in the server itself without using any external softwares.

2) Access Terminal of server
Click on Terminal menu in Advanced tab of cpanel. You will get a terminal to enter commands.

3) Executing commands in Terminal

Now from step 3, open the terminal. we have to put one command here..

mysqldump -u dbuser_user -p dbname > /home/folderuser/public_html/dbbackup/db.sql

(dbuser: Put the database username, dbname:Put the db name, db.sql: Give the database file name, path should be given relatively in repect to where you want the exported sql file)

Then it will ask for db user password just provide that. Now the command will execute and database will be exported successfully.

Importing Large Mysql Database in Linux Hosting Servers

When we are migrating very large websites, problem often comes when we are migrating the database. Through phpmyadmin, we can import database upto 50 mb. But the sql of size more than 50mb we have to import via SSH. Here I will explain how to do it in a linux server hosting.

1) Enable Shell access in server
In your cpanel, dashboard you can see "manage Shell" option. Just click on that.
After that, we have to enable SSH access. Then we will get ssh port and details through this. If you want to use external terminal access softwares like putty, you can use those connection details. But here am explaining about how we can do in the server itself without using any external softwares.


2) Access Terminal of server
Click on Terminal menu in Advanced tab of cpanel. You will get a terminal to enter commands.

3)Create Database and User

Now we have to make some basic things ready. So we need to create a database and user. Make sure to give all privileges to that particular user. Note down the db username, password,db name.etc.

3) Upload the Sql file to server

Now we have to upload the sql file to the server for importing.This you can use FTP and through server. Make sure in the sql script, db name should match the database name created in server. if its different open the sql file and edit it with the same.

5) Executing commands in Terminal

Now from step 3, open the terminal. we have to put one command here..

mysql -u dbuser -p dbname < /home/folderuser/db.sql
(dbuser: Put the database username, dbname:Put the db name, db.sql: Give the database file name, path should be given relatively in repect to where you uploaded the sql file)

Then it will ask for db user password just provide that. Now the command will execute and database will be imported successfully.



Monday 15 July 2019

Resolving Permission/ Undefined Variable Problem in SugarCRM/SuiteCRM in Linux Server

When we install or migrate Sugarcrm/Suitecrm,normally we have to face some issues like pages going blank or the messages and popup showing as undefined. This error occurs mostly when we migrate CRM to some Linux servers. This is mainly caused due to permission errors and missing extensions. I will give you step to step instruction on how to resolve this problem. we can divide the steps into three parts.

1) Checking all required extensions are installed or not?
2) Checking all files or folders  having required permissions?
3) Checking the correct path set in .htaccess file

so here am going to explain step by step..

1) Checking all required extensions are installed or not?

We have to check whether following extensions are installed or not.


  • PHP - (check the version.. if you are using older version of sugar or suitecrm ebnable lower php versions. If you are using latest suitecrm version, dont forget to upgrade php verision.)
  • JSON -( Check JSON support is enabled.)
  • XML Parsing- (XML parsing supports should be enabled)
  • MB Strings Module -(This is a php extension needed for sugarcrm to function.make sure to install this extension corresponding to php version in the server)
  • ZLIB Compression Module - (This module is needed for package installation function in crm.make sure to enable it)
  • ZIP Handling Module-  (This module is needed for package installation function in crm.make sure to enable it)
  • PCRE Library-(This is a Perl module needed for advanced regex functions)
  • IMAP Module- (This is for Mail functioning inside CRM for reminders.etc)
  • cURL Module
  • Sprite Support
After install of new modukles, just restart the apache services



2) Checking all files or folders  having required permissions?

We have to check permissions for some directories inside root folder.
Main directories to give 775 permission are:-cache, custom ,modules ,themes ,data, upload.
Also we have to change permission to config_override.php file also to 775
While giving permission to directory, make sure to give permission recursively for child objects under that folder also.

Login to terminal via root user then perform following commands:-

cd  /home/siteuser/public_html/    (siteuser will be username in the hosting)

sudo chmod -R 775 cache custom modules themes data upload config_override.php

Now check the permission has been granted or not

3) Checking the correct path set in .htaccess file

Just open .htaccess file in the root folder. check this line:-

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

Verify RewriteBase /  is correctly set or not. If you have installed in public_html folder itself you have to use like this RewriteBase /. In case, if you installed inside a folder for eg: crm, this line have to change like:- RewriteBase /crm/

After editing , save the file and close it

Now login to CRM and check. Its betetr to do a Repair and rebuild from the admin to make sure everything reloaded correctly..