How to Deploy to a cPanel Managed Web Host

What is cPanel?

cPanel is server-side software that provides a graphical user interface (GUI) so website owners and other non-SysAdmins can easily manage their web hosting server settings.

Web hosting providers generally need to provide their end users with a control panel like cPanel since full root access will never be granted on basic shared hosting accounts. cPanel is widely used by web hosting providers such as GoDaddy, 1&1, Bluehost, Liquidweb, HostGator, A Small Orange, A2Hosting, and many more.

The The A2Hosting shared hosting accounts that are included in the Deep Dive Bootcamp are managed via cPanel. We'll go over the steps involved in successfully deploying your PWP to A2Hosting, or any other cPanel managed web host.

Preliminary Steps

Before you begin, you will need to:

  1. Log into your web hosting account. (A2 Hosting)
  2. Have PuTTY (Windows) or Terminal (Mac/Linux) open. You'll need it to test SSH access.
  3.  Windows users, have PuTTYGen open to access your SSH key.

Once logged in to your hosting account, take note of your Account Username and keep it handy.

a2 hosting username
Figure 1: Where to find your username

PHP Version Selector

On A2Hosting, PHP version 7 should be set by default. You can set the specific PHP version via cPanel if you need to.

In cPanel, navigate to Software PHP Selector, and select version 7.

Adding SSH Keys

You will need to grab a copy of your Public SSH Key.

  • Mac/Linux: Open your Terminal and run the following command cat ~/.ssh/id_rsa.pub. Copy the entire text output, beginning with "ssh-rsa".
  • Windows: Open PuTTYGen and load your Private SSH Key file. Enter your passphrase, and copy the text output. This is your Public Key.
In cPanel, navigate to Security SSH Access. Select "Manage Keys".
  1. Select "Import Key".
  2. You DO NOT want to use your Private Key, so IGNORE the "Paste Private Key" and "Passphrase" fields.
  3. You may choose a name for your SSH key. This can be helpful if you plan to add more than one SSH key to your account. Do not use spaces or special characters in this name.
  4. Copy and paste your Public Key in the last textbox, and select "Import".
  5. Return to the previous screen, "Manage SSH Keys"
  6. Select your key from the list at the bottom of the page, and select "Authorize".

After all of the above steps are completed, you should be able to SSH in to your host using PuTTY or your Terminal with the following command:

ssh YOUR_USERNAME@YOUR_DOMAIN.COM -p7822

Please note that A2Hosting requires you to SSH in at port 7822.

Creating a New Deployment

After you have successfully verified SSH access you can now create a new deployment in PhpStorm, or the IDE of your choice. You will need to make sure the SFTP host, Port, Root path, User name, and Web server root URL are all updated for your new host.

cpanel host deployment settings
Figure 2: New PhpStorm Deployment Settings

Be sure that the Deployment path on server is set to "/", to ensure correct automatic uploading.

URL Redirect for PWP

The following file will redirect your users into your /public_html directory inside your PWP. It will also remove /public_html from your URLs.

The last three lines will force a secure connection (https://). If you do not have an SSL certificate, or are deploying to a host that does not include a free SSL conncection, remove these last three lines.

In the root of your project, create a new file named .htaccess. Add it to git, and copy/paste in the code below.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^YOURDOMAINNAME.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.YOURDOMAINNAME.com$
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]

# this forces SSL connection
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://YOURDOMAINNAME.com/$1 [L]
.htaccess for URL redirect
You will need to update YOURDOMAINNAME in the .htaccess file above to YOUR domain name.

Email Addresses

In cPanel, navigate to Email Email Accounts.

Fill out the form to create custom email addresses at the primary domain associated with your hosting account. It is preferable that web developers have an email address at their own domain. You can also opt to configure a desktop or mobile mail client, such as Thunderbird, Outlook, K-9 Mail, etc., to use with your email account(s) here.

Email Forwarding

In cPanel, navigate to Email Forwarders.

This option allows you to forward incoming mail to any other email address. You can also forward ALL mail for your domain to any email address you like.

Domains

If you want to change the domain name associated with your hosting account, you will need to contact customer support and request to change the primary domain. The change may take a few days. Have your domain registrar account open and the nameserver info handy when you contact customer support.

Linking a Domain Name to a Web Hosting Account

Nameserver
A nameserver is a computer that is permanently connected to the Internet and translates user-friendly domain names into numeric IP addresses.
- Definition courtesy of Google.com

In order to link a domain name to a web hosting account, you'll need to update the domain name's nameservers. This can be done via your domain name registrar account. If you registered your domain name and your hosting account at the same time, this should be automatically done for you.

If you would like to change the primary domain of your hosting account, it is generally necessary to contact your hosting provider's customer service department, and then you will need to update the nameserver for your domain name if it has been purchased via another registrar.

Your web hosting provider will provide the DNS server/nameserver information for your hosting account. See sample image below.

a2 hosting nameservers
Figure 4: Nameserver Information

Subdomains

In cPanel, navigate to Domains Subdomains.

A subdomain is a subdirectory on your web hosting account that can exist as a separate website. Use subdomains to create memorable URLs for different content areas of your site. For example, you can create a subdomain for your blog that is accessible at blog.johnsmith.com AND www.johnsmith.com/blog

Addon-Domains

In cPanel, navigate to Domains Addon Domains.

Add-on domains allow you to point another domain name to a subdomain on your account. Setting up an add-on domain will automatically create the subdomain for you. You can use add-on domains to host more than one website on your account at a time.

You will need to have access to the domain name's registrar account in order to use it as an add-on domain, whether or not that domain name is controlled by you or by your client.

If the domain name you want to use is registered through a separate registrar (not A2Hosting), you will need to update the nameserver info for each domain to be the nameserver/DNS of the web host (A2, in our case). See Figure 4 above for where to find this information.

Aliases

In cPanel, navigate to Domains Aliases.

Domain aliases make your website available from another domain name, in addition to the primary domain that is set up with your account. For example, you can have janesmith.net and janesmith.org both point to your site that is hosted at jsmithrocks.com.

Again, if you registered the domain names you want to use as Aliases through a separate domain registrar, you will need to update the nameserver for each alias to the nameserver/DNS of your web host.

Redirects

In cPanel, navigate to Domains Redirects.

A redirect allows you to make one domain redirect to another domain, either for the whole website or for a specific page. For example, you can create a redirect so that johnsmith.com automatically redirects users to webninja.net. You can select either a 301 Redirect (permanent), or a 302 Redirect (temporary). The redirect codes will inform search engines as to the nature of the change. The use of Aliases will not do this for you.

Use the 301 Redirect if you want to inform search engines that a website has been moved permanently. Use a 302 Redirect to inform search engines that the redirect is only temporary, or to a temporary web site or page.

MySQL Databases

In cPanel, navigate to Databases MySQL Databases or MySQL Database Wizard.

The A2Hosting accounts included with the Bootcamp include the hosting of unlimited MySQL databases.

phpMyAdmin

In cPanel, navigate to Databases phpMyAdmin.

The phpMyAdmin tool provides you with a Graphical User Interface you can use to directly work upon your MySQL databases. This is an alternative to working on your MySQL databases via the command-line.