VPS + Cloudflare + Cpanel email

I have a strong shared hosting plan from a company that provides unlimited email accounts but sadly I had some issues deploying a Laravel app on that plan because of the restrictions it has. now I want to use a VPS for my Laravel app but still want to use the cpanel email functionality on that plan to send and receive emails on the same domain that will host the Laravel app on the VPS but I really have no idea if it is possible and if it is then how should it set the DNS records to achieve that.

Short answer - yes, it is possible. And you can use Cloudflare too :slight_smile:

I can admit I manage few domains just like that. Even, it is recommended to separate them just in case.

Separate server per need with different services, just as a websites are being hosted on a dedicated server, each domain/website is using Cloudflare Origin CA certificate, SSL setup on Full (Strict) SSL, while the e-mail is on shared cPanel (having it’s AutoSSL certificate for a mail hostname) or some other dedicated server (with Let’s Encrypt SSL certificate) or some third-party e-mail service like GSuite, Microsoft Office 365, etc.

All working fine and smoothly as far for now :wink:

  1. Create a Cloudflare account and add your domain
  2. Change your current domain name nameservers at your domain registrar to the Cloudflare one’s which you will be given in the process of adding your domain to your Cloudflare account
  3. Add the DNS records per need, for example A type www and A type yourdomain.com DNS records both pointed to your VPS IP address where your domain (website) content (Laravel?) is hosted (located) and make sure both are proxied :orange:
  4. Next one, create an A type mail.yourdomain.com DNS record and point it to your “unlimited email accounts” cPanel hosting IP address where you use e-mail and make sure it is :grey: (DNS-only)
  5. Nevertheless, add an MX type record pointed to that mail.yourdomain.com hostname
  6. From cPanel you can check for SPF and DKIM records, and it is recommended to add them too (as a TXT type of DNS records) to your DNS tab at Cloudflare dashboard
  7. Furthermore, you would have to setup the HTTPS (both at your VPS as a web server and Cloudflare SSL/TLS tab) and have an SSL certificate for your root (naked) domain and www (even if you have more sub-domains just in case). In case you do not have an SSL certificate, you can use Cloudflare Origin CA certificate (see below for more info)
  8. Just in case, check and allow Cloudflare to connect to your origin host / server (whitelist Cloudflare IP addresses/ranges) in your Firewall / iptables, etc.
  9. Make sure your web server / app is working over one of the supported and compatible Cloudflare ports - when the proxied :orange: mode is active

Helpful articles following as above steps:

More useful tutorials can be found here:

Helpful tutorials following above steps:

In case you do not have an SSL certificate, you can use Cloudflare SSL, if so, kindly make sure you follow the instructions as follows on the below article to setup an SSL certificate using Cloudflare CA Origin Certificate:

Last but not least, kindly have a look here for more information regarding correct SSL settings:

Check if Cloudflare is allowed to connect to your origin host to as follows in the below article:

Ports list compatible and supported when using :orange: cloud (proxy mode) on Cloudflare can be found here:

Due to the e-mail, I would suggest looking at the below articles too:

To manage the DNS records at the DNS tab, usefull for help:

1 Like

thanks for the thorough response. i followed as per your instruction and everything is ok except that i receive emails with a delay of 5-10 min but sent emails get delivered almost instantly. maybe i missed something? i attached the DNS records but i retracted the IPs and domains. would appreciate if you take a look at it and give me feedback if im missing something.

1 Like

All looks good to me as far for now :+1:

E-mail (A mail and MX) is setup correctly.

I am not 100% sure why is the delay.
May I ask is the delay while using Webmail interface (like Roundcube), or in your app like MS Outlook, Mozilla Thunderbird, etc.?
Or if it is shared hosting cPanel for e-mail, maybe due to more than only your e-mail (more users and server load, etc.)?
Or, maybe you would have to check by looking into the Track Delivery and check the mail headers like sent/received and inspect if it could be something in between?

Screenshot 2021-09-28 at 03-19-22 cPanel - Main

Or, if using some digital signature when sending e-mails, or like GPG for signing them?
Or, if there is some anti-virus/spam checking and setup like amavisd, clamav, etc., on that cPanel hosting causing this delay for sending/receiving?

Or, may I ask you to re-check your IMAP/POP3 and SMTP server in your e-mail client app (MS Outlook, etc.) if you are using mail.domain.ir or domain.ir?

Hopefully, using e-mail over an secured connection (SSL) as well?

Furthermore, in case of troubleshooting, may I suggest few online tools (if not already used) to check and test your e-mails:

Hope they will help you too :wink:

Furthermore, if I could suggest one thing:

I see the CNAME ftp, which goes to domain.ir, while the domain.ir is proxied :orange: - meaning, I am not sure if it will connect and pass through as expected, even when transferring the files.

Kindly, if using ftp.domain.ir hostname to access your server using an FTP application like FileZilla, it would be good way to remove that CNAME ftp and rather create A ftp and point it to the IP and make sure it’s :grey: - similar to the A mail.

Otherwise, I actually recommend removing it and access the FTP via directly entering the IP address rather than the hostname itself - only you know the IP :slight_smile:

Of course, this could be different if more users need to access it, so it easy for them to remember (if they didn’t saved it) :wink:

Just an idea :thinking:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.