How to Deploy PHP Application With Database Within a Minute?

How to Deploy a PHP Application with Database in a Minute?

Welcome to our guide on setting up a server with a database and deploying a PHP application. This step-by-step tutorial will help you configure your environment with ease.

Setting Up Your Environment

Setting Up Environment

First, log in to your AccuWeb.Cloud dashboard. If you haven’t already set up a PHP environment with a database, click on the “Create New PHP Environment with Database” button

Create New PHP Environment with Database

If you’ve already set up a PHP server and database and wish to access phpMyAdmin for the database, click on the SQL Database option and then on “Open in Browser.” This will redirect you to the phpMyAdmin page.

Check AccuWeb.Cloud’s Best PHP Hosting Services!

Open in Browser

In the dashboard, you’ll find the Deployment Manager. This tool helps you deploy your application using various methods. You can also find the option to access Web SSH by expanding the PHP server.
MySQL Node Created

Check your email for your database and server credentials. You should have received an email containing this information, which you can use when deploying your application.
Environment Created

That’s it! You have successfully set up a PHP server with a database and accessed it to deploy your application.

Connection to the Database

Once your project is successfully deployed, you need to connect it to your database. This requires your application to be properly configured, for example, using the MySQLi (MySQL Improved) extension.

Check our High Performance MySQL database hosting services!

Here are some basic functions to help you connect to your database:

1. Getting a Connection String

Use the following function to get a connection string for accessing your MySQL/MariaDB node:

mysqli_connect('{host}', '{user}', '{password}', '{db_name}');

Replace the placeholders with your connection data:

  • {host} – link to your DB node without protocol part
  • {user} and {password} – database admin credentials
  • {db_name} – name of required database

2. Switching to a Different Database

To switch to a different database within the same server, use the following function:

mysql_select_db('{connect}','{db_name}');

Replace {connect} with the connection string obtained using the mysqli_connect function.

3. Closing a Connection

To close a connection to your database, execute the following:

mysqli_close( );

Note: You need to specify the necessary functions in every *.php page, which should be connected to the database.

Sign up and avail $100 free credits now!!

Checking the Connection

You can check the connection using the following code:


?php $link = mysqli_connect('{host}', '{user}', '{password}', '{db_name}');
//if connection is not successful you will see text error
if (!$link) { die('Could not connect: ' . mysql_error()); }
//if connection is successfully you will see message below echo 'Connected successfully';
mysqli_close($link); ?

Replace {host}, {user}, {password}, and {db_name} in the connection string with the corresponding values

Executing a Simple Request

Here’s an example of how to execute a simple request to your database and output it onto a table:


?php 
// Connection checking:
$link = mysqli_connect('{host}', '{user}', '{password}', '{db_name}');
if (!$link)
{
	echo "
"; exit; } // Switch to a different database: $db="mysql"; mysqli_select_db($link, $db); // table header output: echo "
"; echo "

"; // SQL-request: $q = mysqli_query ($link, "SELECT * FROM help_topic;"); // table-result output for ($c=0; $c<mysqli_num_rows($q); $c++) { echo "
"; $f = mysqli_fetch_array($q); // Returns an array that corresponds to the fetched row and moves the internal data pointer ahead. echo "

"; echo "
"; } echo "
Value1 Value2 Value3
$f[0] $f[1] $f[5]

As a result, you’ll receive a kind of index for all available MySQL functions with links to the instructions on their using.

Index of MySQL Functions

Register and get Auto Scalable instances with a Pay-As-You-Go Pricing Model!

Conclusion:

Congratulations! You have successfully set up your PHP server and database and deployed your application using AccuWeb.Cloud. We hope this guide has been helpful in simplifying the process for you. For more in-depth tutorials and best practices on PHP development, explore our Knowledgebase section.