简体   繁体   中英

Using git version control for PHP development

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.

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.

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 

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM