Search code examples
phpmysqlxamppfilezillabluehost

Pushing PHP from Development to Production


I've been developing PHP pages for several weeks now and am getting much more confident in my code. I've obtained a hosting account through Bluehost, and am ready to begin making some live pages. Previously I have been using XAMPP on Windows and developing all of my pages on my local computer. I'm trying to determine the best practice for creating my page locally and then easily moving it to my hosting server. I use Filezilla to transfer my files. Here are my main questions:

1.) How can I ensure my local and live MySQL databases stay in sync? I have been manually creating the database locally, and then taking the same code and applying it to my live server. (I have phpmyadmin locally and on the live server, but dont know how to use it to streamline this process)

2.) I have to change the mysql password and connection credentials on all files before moving them from local server to live server. Is there a way around this?


Solution

  • For question 1 you could dump the database and import it at the production end each time you do an upload, or you could use mysql replication.

    For question 2 it is quite common to have the database connection details in a separate php file and then include that file at the top of each page that needs to connect to the database

    Then you can just change that one file, or only upload the one with the production database details.

    db.php

    <?php
    $dbuser="";
    $dbpass="";
    $dbname="";
    $dbserver="";
    ?>
    

    myfile.php

    <?php
    include("db.php");
    $conn = mysql_connect($dbserver, $dbuser, $dbpass);
    mysql_select_db($dbname);
    //....
    ?>