How to Publish PHP Website (Install CodeCanyon Scripts)


 

In case you bought a PHP script from Codecanyon and you want to install it, or maybe you are a PHP developer, and you want to learn how to publish PHP website online, Then You are in the right place.

✔

In this guide, I will cover the following:

  • Requirements .
  • Get a Domain Name.
  • Get a VPS Server.
  • Map Server IP to Domain.
  • Create a MySQL Database For Your Application.
  • Uploading File to the Server using WinSCP.
  • Installing PHP Modules.
  • Managing MySQL Databases.
  • Setup cronjobs.

Requirements to Publish PHP Website.

What you need is simply is:

  • A VPS Server to install your PHP Script on.
  • Domain Name to use with our setup.

1. Get a Domain Name To Publish PHP Website.

Getting a Domain is as simple as eating a piece of chocolate cake. you need to go to any Domain registrar company like Godaddy, HostingerEnom, Freenom, Namecheap…. and Buy a Domain Name, you can even get one for 1$ per year.

I do recommend to get domain name that reflects your business. and if you already have one, as I think so, you can just skip this, and continue to get a VPS Server.

Watch this 3 Minutes Video and see how to get and buy a domain name from Godaddy:

2. Get a VPS Server.

Now, Let’s get our VPS server to set up our PHP Script on.

What is a VPS Server?

When you want to publish PHP website or script or any web application, we do what we call “web hosting” which simply means uploading the files and database into a public server so it can be accessibly Online over the internet.

How To Publish PHP Websites

Hosting Options.

Now when you want to host a web application (WordPress in our scenario), you have mainly 2 options:

Shared Hosting:

Which means publishing your website on hosting services like Godaddy, BluehostHostinger… where your website will be hosted with hundreds of other websites on the same server.

VPS Hosting

In this setup, you will host your website on your own server, so you will have a server only for you! which is called a VPS or a Virtual Private Server.

Which one is better?

I don’t want to go in depth now and explain technical stuff, but in few works, VPS is Definitely better where you will have your own server with full manageability and better performance.

And if you think that shred hosting is a lot cheaper, then you are wrong, as with Contabo VPS services you can start with a 3.99 € per month Only which is the same pricing for almost 90% of shared hosting services.

Maybe the only drawback here, is that it requires some more technical skills to set up and configure, but fortunately, you are here in the step-by-step guide, where you will see how things will go really easy!

What company should I use?

You can use whatever company you want to buy a VPS Server, in this guide I will share with you two companies that I think has everything you need, and with the cheapest prices. and I use to run more than 10 Servers for my business.

These companies are: Contabo Digital Ocean.

But as I told you, it's up to you, you can use whatever company you feel comfortable with. you can also go with Hostinger, which also provides a very good pricing compares with other companies.

Note: In this tutorial: I will be using Contabo

So Let's see how we can get a VPS server from Contabo.

Get a VPS Server From Contabo.

1: Open Contabo Website.

Open your web browser and navigate to Contabo VPS Page.

You will see multiple VPS configuration to start with. You can simply start with the cheapest option to Install WordPress, it will be more than enough.

Later on, when you grow your business, you can scale up and get a more powerful VPS with Higher resources.

2: Set VPS Options

On the Next Page, you will need to select some options

In the Operating System Option, Select Ubuntu 18.04

Select Ubuntu 18.04

Then in the Administration Panel, Select LAMP

SELECT LAMP

And last option, In the Addons, check “Individual reverse DNS”

Add PTR

If you were promoted to enter the PTR record, enter your domain name, and That’s it.

Now, Just Continue to the billing page, and confirm your order. I think other steps are simple and self explanatory.

In like 24 hours, Contabo Team will setup the Server and send the details to your email like this:

Login Info

For Digital Ocean.

If you want to go with Digital Ocean, simply Sign up through the coupon link below to get free 100$ to test everything free.

And after you signup on Digital Ocean, just create a Droplet with the following specifications:

  • Ubuntu 16/18/20 x64 as your operating system.
  • You can start with 1 CPU/ 1 GB RAM (You can resize later).

Great! You Got Your Server. 

Check Also:

How To Install WordPress on Contabo VPS (WITHOUT cPanel)

3. Map Domain Name to your VPS Server.

Ok Friend, Now we have a Domain and a VPS Server. But they are not connected!

Your VPS Server can be accessed now through the IP address that Contabo Team sent you by email. but of course, we don’t want to access our WordPress website though an IP! we want to use our domain name.

So simply, we are going to map the domain name to our VPS IP, so then we access the VPS and the WordPress website through both the domain and the IP.

Configure your DNS Records:

Simply open DNS management zone in your Domain Provider (Godaddy in my case) and edit the main  A record like this:

host: @ points: YOUR SERVER IP.

map domain to vps

Done? Great! ✔

4. Create a MySQL Database For Your Application.

To Publish PHP Website, the Majority of PHP scripts and applications, will require a MySQL Database. So Let's Create one.

Connect to your VPS server using any SSH client like putty. and Let’s start!

putty

Just open Putty and enter the Server IP or Name, and Press Open.

It will ask you to login, just enter “root” as the user, then enter your password which is sent to you by email.

Note: while typing the password, putty will now show it for security reasons, but It’s there, just type it!

install wordpress on contabo
Login with putty

And you are In! 

What's nice, is that we have MySQL installed already as part of the LAMP Stack, but we need to create a database and a user for out application.

To get started, log into the MySQL root (administrative) account by issuing this command:

mysql -u root -p

You will be prompted for the root password, just write or paste it and press Enter.

First, create a separate database that your PHP application will use. You can call this whatever you want, but we will be using TestDb in this guide to keep it simple. Create the database by running this command:

CREATE DATABASE TestDb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Note: Every MySQL statement must end in a semi-colon (;)

Next, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database. Creating one-function databases and accounts is a good idea from a management and security standpoint. We will use the name DbUser in this guide. Feel free to change this if you’d like.

We are going to create this account, set a password, and grant access to the database we created. We can do this by typing the following command. Remember to choose a strong password here for your database user:

CREATE USER 'DbUser'@'localhost' IDENTIFIED BY 'enter_a_custom_password_here';
GRANT ALL ON TestDb.* TO 'DbUser'@'localhost';

You now have a database and user account, each made specifically for Your PHP application. We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made:

FLUSH PRIVILEGES;

Exit out of MySQL by typing:

EXIT;

Done! ✔

5. Upload The Script Files To The Server.

To upload the files, you need an application called WinSCP.

It is a free tool and you can download it from here.

Connect to Your VPS Server using WinSCP, and Update the PHP Files to the server to this path: “/var/www/html”

In most cases, the files would be zipped, so we need to extract them.

Again to Putty SSH CLient and Let’s install the unzip utility using the following command:

sudo apt-get install unzip

Clear putty screen to make in clean using the following command:

clear

Change directory to /var/www/html using the following command:

cd /var/www/html

Unzip the “.zip” file using the following command:

unzip YOURFILENAME*.zip

*Note: the file name may be different in your case, so replace YOURFILENAME with your file name.

Now, Move the latest folder content to the upper directory so it can be accessed directly -> use WinSCP
Just copy all the files inside “YOURFILENAME” folder and paste them directly in html folder.

Files Uploaded. Done! ✔

6. Installing PHP Modules To Publish PHP Website (optional)

Some PHP applicaiton will require some additional PHP modules on your server( this is will be mentioned in the app documentation)

To Install additional PHP modules:

Open Putty, and run the following commands to install PHP Modules:

sudo apt install php-curl
sudo apt install php-mbstring
sudo apt install php-example
......

*Restart apache service using the following command:

sudo service apache2 restart

Done! 

7. Configure Apache to Publish PHP Website

Well Done, Now your files are uploaded and placed in the html folder, we just need to configure apache so we can our Publish PHP Website and access our script using our domain name. To do so, open WinSCP again and navigate to this directory: /etc/apache2/sites-available/

Now, create a new empty file and name it “yourdomain.conf” . You can replace “Scriptname” with any name you want (Below is an example naming it mautic.conf).

Create Conf

Open yourdomain.conf Then copy and paste the content below into the file and save.

<VirtualHost *:80>
     ServerAdmin admin@YOUDOMAINNAME
     DocumentRoot /var/www/html
     ServerName YOUDOMAINNAME
     ServerAlias YOUDOMAINNAME
     <Directory /var/www/html/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Replace with your own domain, in my case its “YOURDOMAINNAME”

Enable your script configuration in apache and restart the service.

Now simply, run the following commands to finish the setup:

sudo a2ensite yourdomain.conf
sudo a2enmod rewrite
sudo systemctl restart apache2.service 

GREAT! You are almost done

8. Connect to MySQL Database.

Open your web browser now and navigate to your server name.

You must see the setup completion wizard below:

Continue the setup by entering the database info and your admin login information. In our example, the database name is TestDb and the user is DBUser with the password set.

That simple! Check below example from a similar script.

Connect to database. Done! ✔

9. Setup cronjobs.

What are cronjobs?

cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful to automate repetitive tasks.

For example, you can set a cron job to delete temporary files every week to conserve your disk space. Some PHP web applicaitons, may require you to set up a cron job to perform certain functions.

Setup cronjobs.

To setup cronjobs, you need to add all required jobs to the server. This depends on your script, so if you bought a script from code canyon, the script owner should provide the cronjobs.

To do this, open WinSCP and got to /etc
Open crontab file using the editor
And paste all the jobs from your script to this folder. (cronjobs are listed in the app documentation)

Make sure each job is on a line and an empty line in the end.

Cronjobs. Done! ✔

10. Secure with a Free SSL.

SSL certificates are used within web servers to encrypt the traffic between the server and client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.

Connect to your Server using Putty SSH client. and Let’s Start!

Step 1 — Install the Let’s Encrypt Client

Let’s Encrypt certificates are fetched via client software running on your server. The official client is called Certbot.

First, add the repository to install Certbot:

 sudo add-apt-repository ppa:certbot/certbot 

You’ll need to press ENTER to accept.

Then, Update the package list to pick up the new repository’s package information:

 sudo apt-get update 

Install Certbot’s Apache package:

 sudo apt install python-certbot-apache 

Certbot is now ready to be used.

Step 2 — Set Up the SSL Certificate

Generating the SSL certificate for Apache using Certbot is quite straightforward. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

Simply run the following command: (change the domain)

 sudo certbot --apache -d YOUR_DOMAIN_NAME

You will be asked to provide an email address for lost key recovery and notices, and you will be able to choose between enabling both http and https access or forcing all requests to redirect to https. It is usually safest to require https, unless you have a specific need for unencrypted http traffic.

That’s it! 

Test your website now and it should be SSL encrypted.

Done! ✔