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.

Sign up to request clarification or add additional context in comments.

6 Comments

+1, liking the tutorial to net tuts & advice re: databases in Source control.
-1 Database schemas should always be under version control. It is normal and necessary.
@awm - That's exactly what I said. Why have you downvoted me for it?!
@IHID: "It is not normal to keep databases in version control."
@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?
|
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 

Comments

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 Comment

ah, faster by a split-second ;)
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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.