3

Is it possible to version control a PHP + MySQL + Apache project? And could it keep track of the changes in the database, like for example if I added a new table, can I possibly commit that?

Thank you.

5 Answers 5

4

It is not normal to keep databases in version control. Some developers use a sqlite database for development so that it can be checked into version control, but this can lead to issues as sqlite syntax can be different from MySQL.

However, you can keep your database schema and migrations source control. Look at a projects such as mysql-php-migrations to get started.

There's a good tutorial on using PHP with Git at http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/ - this should get you started.

6
  • +1, liking the tutorial to net tuts & advice re: databases in Source control.
    – Haroon
    Commented Jun 10, 2012 at 15:31
  • -1 Database schemas should always be under version control. It is normal and necessary.
    – awm
    Commented Dec 17, 2012 at 14:43
  • @awm - That's exactly what I said. Why have you downvoted me for it?!
    – iHiD
    Commented Dec 18, 2012 at 15:18
  • @IHID: "It is not normal to keep databases in version control."
    – awm
    Commented Dec 19, 2012 at 17:58
  • @awm: It is NOT normal to keep the database in version control. It IS normal to keep the database SCHEMA in version control. That's what I say above... You think it's normal to keep an actual database (e.g. SQLite file that I refer to) in version control?
    – iHiD
    Commented Dec 20, 2012 at 4:49
3

Using Git for your PHP scripts is no problem, however tracking changes to the database is a little trickier. If you have SQL scripts that create the database structure then these can be version controlled with no problems. Otherwise you could use mysqldump to output the structure to an SQL script after any changes you make:

mysqldump -d -h localhost -u root -pmypassword mydatabase > dumpfile.sql 
0

You could use git to track PHP scripts and SQL scripts that create the necessary database structure. Those SQL scripts could of course be version controlled and recreate the database schema at any given state.

1
0

Git is essentially SCM, which means Source Control. Tables in mysql are stored as binary files, so it isn't very good idea.

You can, however, store SQL queries which create these tables, allowing you to re-create them if you needed to.

As for php, it will be all good.

0

I recently released a really simple shell script that will help keep changes to a MySQL database under version control.

https://github.com/stevecomrie/mysql-version-control

Not the answer you're looking for? Browse other questions tagged or ask your own question.