You are a PHP developer or you may have purchased a PHP script but don’t know how to host a PHP Script online, Right?
Meanwhile, finding a good web server for your PHP script files can be also tough and even more difficult to get set up correctly.
But, not to worry, I am here to help.
In this step by step guide, I will show you how to install any PHP scripts online in less than 10 minutes easily and simply by giving the right command line.
As well as, this guide can help those who have purchased PHP script files from Codecanyon and want to know how to host PHP script files from Codecanyon.
I will define and review the most important concepts like:
- Creating a VPS Server
- Configuring the Server Using Putty SSH Client
- Uploading File to the Web Server using FileZilla or WinSCP
- Installing PHP Modules
- Managing MySQL Databases Setup
- Setting up Cronjobs, and
- Mapping Domain Name
I will not host any PHP Script files here but don’t worry, I will use the “Example” as a “Name” for my PHP file Script.
Furthermore, I will also add the SSH command line, install PHP Modules, run databases setup on the web server, and Cronjobs in this tutorial.
So, it will be an excellent example to follow up and grasp almost all of the terms you could confront while hosting and setting up PHP files on any web Application.
Getting Started – How To Host a PHP Script Online
You will first need a VPS server (Virtual Private Server) to host your PHP web application. So, I will use DigitalOcean to obtain a VPS Server, and why DigitalOcean?
It is because of two reasons:
- DigitalOcean is already configured with (LAMP) Servers to host websites, which makes the process simple. Therefore, there is no need for the installation of PHP, MySQL Database, Apache server, or anything else.
- They’ll give you a $100 credit coupon for free so that you can try everything at zero cost for 60 days.
So sign up, make a VPS Droplet Machine, and ensure that you choose LAMP Server for the Server System, as shown in the picture.
Now, let’s start the installation.
Reset Droplet Password
Now you need to download Putty, an SSH Client, and reset your password to connect to your Server.
When you create the Droplet, You will get an email sent from DigitalOcean, containing your server credentials like server IP, Username and Password, or the default password for the root.
| Why do you need to reset your password?
Because sometimes, when you create your Droplet in DigitalOcean, It generates a default username and password for your Server.
When you connect to your Server using the Putty SSH client, It asks you to enter your password and then reset your default generated password with a new one to connect to the server.
Upload PHP Files
By default, you will see a file such as “index.html” in that directory.
- Just delete it, Drag, and Drop your Script.
In this case, If you are dealing with a Zipped File.
Therefore, You should extract it by writing the following commands to unzip the file using the Putty SSH Client.
sudo apt-get install unzip
Clean the putty screen to make it clear with the following command:
Use the following command below to change the directory to /var/www/html
Type the following command to list the files that exist in the directory:
Then unzip the “.zip” file by the following command:
Note: Your Script file’s name might differ, and to make it clear, I used “example” as my PHP file name.
So you should change the “example” and type your PHP file name.
If you have successfully unzipped the PHP file using WinSCP.
Then you have to Drag and Drop your PHP Script files to the most recent content folder into the upper directory “/var/www/” below the “Html” folder.
Delete the previous “Html” folder and instead rename your PHP file “example” as the “Html” folder.
Follow the steps shown in the picture.
In this manner, Your PHP files are in the Html folder, which means that they can be directly accessed using Your Domain’s name.
Now you can open your browser and type your droplet Server IP. After that, you will be able to see the PHP application startup page you installed.
Install PHP modules
PHP modules will be different for every PHP file but the main command is “Sudo apt install”
However, to make it clear, I will add some PHP module commands as an example to show you how to run the commands to install any PHP Scripts modules.
Open the Putty application again, and execute these instructions for installing PHP modules:
sudo apt install PHP-curl or sudo apt install PHP-mbstring
Here “PHP-curl“ and “PHP-mbstring” are an example and instead of that suffixes you should put your module names, But many Scripts also have these modules to be installed, and if your scripts have these modules too, you can copy and paste them to install them one by one.
Then, Restart your Apache Server with this command:
sudo service apache2 restart
Create the Database
1. Open the Putty SSH Client and execute the following command:
mysql -u root -p
Log in to “MySQL” by using your password.
2. Build a database by using the following command:
CREATE DATABASE example;
Note: You have to change the “example” and instead give any name you want.
3. Create a brand new user if the root isn’t accessed by local:
CREATE USER ‘example’@’localhost’ IDENTIFIED BY ‘example_db_pass123’;
Note: Remember to give the name of your choice in all “example” sections and run all the following command one by one after each other.
Grant all Privileges:
GRANT ALL PRIVILEGES ON * . * TO ‘example’@’localhost’;
Open the WinSCP application, go to the “/etc” directory folder, and Open the “crontab” or (it may differ due to various types of scripts file) using the editor.
Copy all the cronjobs from the Script you use, and paste them on the “crontab” as shown in the picture.
Final Step – How To Host A PHP Script Online
The last step is to connect your domain to your IP address within the DNS management zone.
If your domain name provider is Namecheap go to your DNS management zone and follow these steps:
1. Log in to your account.
2. Go to your “Domain list” on your Dashboard.
3. Find your Domain name and click on “Manage”.
4. Go to the “Advanced DNS” and click on “Add New Record”.
5. Select ” A Record”
- Host: @
- IP Address: Your Server IP
- TTL: Automatic
It is Done; wait a few minutes for configuration.
If your domain name provider is GoDaddy go to your DNS management zone and follow these steps:
1. Log in to your account.
2. Go to your “Manage Domain”.
3. Find and Select your Domain.
4. Click on “…” in front of your Domain and select “Manage DNS”.
5. Select “A Record“.
- Host: @
- Points to: Your Server IP
- TTL: 1 Hour
It is Done; wait a few minutes for configuration.
What is PHP?
PHP is one of the server side scripting languages that’s used for web development. However, a PHP developer may also use it as a (GPP) general-purpose programming language.
A PHP code may be included in HTML code or utilized in conjunction with various web template systems, content management systems, and web platforms.
So, PHP files are generally interpreted by a PHP interpreter, which is either part of the web server or a (CGI) Common Gateway Interface executable.
The web server displays the results of the executed and interpreted PHP codes, which might be any sort of data, such as binary image data or generated HTML code.
PHP has gone through several changes since its inception in 1997. It now supports the command line interface (CLI) and can be used in standalone graphical programs.
What is a PHP Script File?
Similarly, PHP files are saved with a “.php” extension.
The code in a PHP file is executed on a web server and is requested by a browser, typically through a URL or form submission.
After that, the output of the executed PHP file code is then returned to the browser to be displayed.
How Does PHP Work?
When a user requests a page that contains PHP files, the web server calls the PHP interpreter program to process the script.
Otherwise, the PHP interpreter will ignore any code in PHP scripts that are not contained within a tag.
The PHP interpreter will execute any code within the tags, and the resulting output is returned to the webserver to be displayed in the user’s browser.
Moreover, PHP scripts can also be executed from the command line or used to create standalone graphical applications.
So, I hope you have figured out how to host a PHP script online from Codecanyon and found this article helpful.
However, comment down If you have any questions or read here if you want to know how to create a WordPress website.