atbkellum01
atbkellum01

Reputation: 25

How do I use my host server info instead of localhost on XAMPP?

I have been building a website with PHP functionality in XAMPP, and everything works perfectly within the localhost. Although, I know that in order to have the same functionality on a live hosted server I will need to change the server info in my config.php file that is used:

<?php
    define('ROOT_URL', 'http://localhost/newkellumws/');
    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASS', 'austink01');
    define('DB_NAME', 'kellumws');

I've tried changing the DB_HOST to my hosting profile's nameserver, but that did not work. Any help is much appreciated and thank you for your time. I apologize if the is a newbie question...

Upvotes: 0

Views: 1640

Answers (2)

CloudTheWolf
CloudTheWolf

Reputation: 375

Assuming you are also moving the site as well the hostname will remain as localhost (as is the case with most shared hosting)

Assuming it's cPanel hosting you will first need to create the database. You can then create an SQL account and grant it access to the DB (recommended) or use your cPanel credentials (Not Recommended)

So your config would look something like this:

define('ROOT_URL', 'http://example.com/newkellumws/');
define('DB_HOST', 'localhost'); // Website and SQL ruinning on the same server
define('DB_USER', 'exampl_kellumws');
define('DB_PASS', 'aBc*63oie8wfq');
define('DB_NAME', 'exampl_kellumws');

See https://documentation.cpanel.net/display/68Docs/MySQL+Databases

if the site is still going to be run via XAMPP (For whatever reason) you would also need to allow Remote MySQL

See https://documentation.cpanel.net/display/68Docs/Remote+MySQL

So your config would instead look something like this:

define('ROOT_URL', 'http://example.com/newkellumws/');
define('DB_HOST', 'c01.example.host'); //Address the SQL Server
define('DB_USER', 'exampl_kellumws');
define('DB_PASS', 'aBc*63oie8wfq');
define('DB_NAME', 'exampl_kellumws');

If you still have issues, contact your hosting provider as they will know the server setup and requirements.

You can also create testConnection.php with the following to help diagnose errors

<?php
require_once('path/to/file/with/config.php');
//Step-1 : Create a database connection
$connection=mysql_connect(DB_HOST,DB_USER,DB_PASS);
if(!$connection) {
    die("Database Connection error: " . mysql_error());
}
//Step-2 : Select a database to use
$db=mysql_select_db(DB_NAME,$connection);
if(!$db) {
    die("Database Selection error" . mysql_error());
}
echo('Connected to Database');

Upvotes: 0

user1805543
user1805543

Reputation:

Your server infos and local XAMP are different localhost works like following. You dont need url part as its localhost/your_folder

<?php
    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASS', ''); //Xamp doesnt have a password for root as default leave it empty if you didnt set one.
    define('DB_NAME', 'kellumws');
    define('PORT', '3306'); 

latest version of XAMP request port for MySql port, add it into your connection. mostly its 3306 as default but sometimes it changes to 3307 or 3308 because of mariaDB comes as default you can see real path on XAMP tool.

Than just call http://localhost/newkellumws/ if you created a folder.

Upvotes: 0

Related Questions