Lesson 9: Deploying the Application on a Remote Web Server
This tutorial needs a review. You can edit it in GitHub following these contribution guidelines. |
Normally, a real-life PHP application is run on a remote server and is accessed through a File Transfer Protocol (FTP). To deploy your CRUD application on a remote server, you will need to register an account on a hosting provider, register an FTP account, and create a remote database.
You can use any hosting you like. The current document describes the deployment procedure on the X10HOSTING free hosting. This hosting includes a MySQL but not an Oracle database server.
All the user names, passwords, and email addresses are fake and used as examples only. The administration of the hosting blocks an account if the user does not show up on the forum fore more than a week. So you may fail to apply exactly the same user names, passwords, email addresses, and other credentials from the tutorial.
In this lesson you learn how to do the following:
-
Set up your project to use the registered remote web hosting
-
Change your database connection settings to use the remote database
The current document is a part of the Creating a CRUD Application in the NetBeans IDE for PHP tutorial.
Application Source Code from the Previous Lesson
MySQL users: Click + here+ to download the source code that reflects the project state after the previous lesson is completed.
Registering an Email Account
Create an email account, if you have not created it before. In this example the email address is phpuser65@googlemail.com.
Registering a Hosting Account
To create a hosting account on the X10HOSTING free hosting, follow the steps in their wizard, entering the following settings. You will enter similar information on any other hosting site.
Account Setting | Value |
---|---|
Email Address |
|
Domain name |
|
Subdomain |
phpuser |
Hosting Account Username (also for login to cPanel) |
phpuser |
Hosting Account Password (also for login to cPanel) |
qwerty1234 |
Forum Username |
phpuser |
Forum Password |
qwerty |
FTP Account name |
uploader |
FTP User Name |
|
FTP Server |
ftp.phpuser.x10hosting.com |
Remote Database Host Name |
phpuser |
Remote Database |
wishlist |
Remote Database Username |
phpuser |
Remote Database User Password |
phpuserpw |
Registering an FTP Account
Now that you have a hosting account, you need an FTP account where you will transfer your PHP source and other related files for executing them on the server. For x10Hosting, you opent the cPanel and select New FTP Account, then follow their wizard.
Creating a Remote Database
Because the CRUD application uses a database you will also need to deploy the wishlist
MySQL database on the remote server where you have a hosting account.
Setting Up a PHP Project with Existing Sources and Remote Web Site Run Configuration
-
Download the source files that correspond to the state of the application after the previous lesson is completed. Extract the files.
-
Save the source files in the
htdocs
folder. -
Create a PHP project with existing sources:
-
Specify the location of the downloaded sources in the Source folder
-
Choose the Remote Web Site run configuration and configure the FTP connection
-
-
Complete the project creation.
Updating the Class WishDB
So far you have developed and run the Wish List application on the local web server and used a local MySQL or Oracle database server. To make your application work with the remote MySQL database, you need to update the connection settings specified through the variables of the class WishDB
.
-
Open the file
db.php
. -
Change the variables of the class
WishDB
:
private $user = "<the name of the remote database user>";
private $pass = "<the password of the remote database user>";
private $dbName = "<the name of the remote database>";
private $dbHost = "<the account username specified during the hosting account creation>";
In this example the variables will be updated as follows:
private $user = "phpuser";
private $pass = "phpuserpw";
private $dbName = "wishlist";
private $dbHost = "localhost";