I'm currently working on a PHP site, and am using Git both locally (development) and on the production site (a repo on my web server uses a post-recieve hook to deploy to the web root), the details of which are outlined at toroid.org's 'Using Git to manage a web site' article.
Issue is that I also have a config.php file (of sorts) that I use for connecting to the database that differs between my local development environment (a local install of MySQL with test data) and my remote 'production' web server (which has it's own 'live' database). Whenever I push my changes to the website however the config file goes with it and replaces my 'live' config with settings connecting to the (nonexistent) development one! I then have to manually SSH to my web server and replace the config.php file, kind of defeating the purpose!
Is there any way I can get Git to... kind of 'desynchronize' the config.php file? The 'development' config.php should never get saved to the git repo, and when the production server deploys the PHP scripts etc to the web root directory, it should also leave the existing 'production' config.php file untouched.
Is there any way of doing this with Git? Thanks a million for your suggestions!
TC
First I would remove config.php from the repository, then I would create
a file named ".gitignore" and add the filename "config.php" to it.
Related
As is usual for a PHP/MySQL project, I have a config file with database credentials.
I test on my own local LAMP set up and do a git push to the live site.
The database name, user and password are different on the two.
What is the best practice for managing the two config.php files?
Could I make local edits to change from prod to test, but not commit that one file? That's assuming there are no other changes that need to be made to the file.
Or is there anything equiv to #ifdef in PHP? I know there's no preprocessor!
(Sorry for the unclear title). This is the scenario. I have a local server and I installed Gitstack in it. I was able to to push and pull to this local git server. This same server runs the webapp that I am working on. My plan is to push commits to this local git server and that change must also reflect to the webapp. So instead of using filezilla to copy files from my machine to serer, I will just push the changes via git. How to do it? Or is it possible?
I tried to look inside the Gitstack's installation folder. I expected to see the actual project's files inside but only git files are there.
I'm using Apache, PHP and MySQL. I maintain websites to connect to a real server remotely. But I want to separate real and development Server.
I will use Github and make a local development environment. Then I will maintain websites on local system and send source files to Github and a real server.
I'm curious. Source files will be placed on Github. Then how to manage database info files and Board Uploaded files?
Take advantage of the .gitignore file.
Say uploaded files.. they only mean something to production if they are uploaded in production. They only mean something to dev if they are uploaded in dev. If git is set to ignore this directory then it won't allow you to add/commit/push these uploaded files.
For database and config files, we generally name them like config.php.dist (.dist for distribution) and then rename them on the production side. Then you will always have a base config file with the necessary information which does not override what is in production and being used. Then on dev config you set your settings to reflect dev environment & dev database. In production you reflect proper.
Here is some documentation on using gitignore: https://help.github.com/articles/ignoring-files/
We are a small team developing a Wordpress site. Till now we have been editing the same files online, which inevitably led to mistakes. We thought to use Git / Github to stop stepping on each others tows and manage source code efficiently. However I can not run the site locally on XAMPP as I am getting numerous PHP errors. What would you recommend in this case?
Maybe creating another folder on the server with identical content just for testing? Is it possible then to run Git on the server?
I operate in a team of devs and this is what we do.
Locally each set up our own wordpress install under a seperate vhost and locally modified dns. Get just plain jane wordpress running perfectly.
Create a dev testing site on a live server on the internet (often prefix the real url with dev-www.mysite.com)
Create a GIT repository, and have it auto push-deploy to the dev testing site (we create the folder structure in GIT from wp-content down, and only have custom themes/plugins)
Configure GIT to MANUALLY push changes to the production server (for going live)
On all systems we install the wp-migrate-db-pro plugin. Locally devs only PULL from the shared dev site to their local (which means planning what/when/where you create content).
Copy around the /uploads folder, incase there are a bunch of images/media uploaded.
This works when some of us run Windows/IIS/WordPress, Mac/Apache/WordPress, Linux/Apache/WordPress
As a general idea a deployment process could go like this:
developers push their git changes to the server 'staging' area
either manually or using git's post processing, changes are pushed is needed to a virtual Wordpress web host that acts as test or 'staging' server. This can be password- or geolocation-protected
once it's tested properly, then the code can be moved to production web host files, this can be accomplish with a simple script that goes like: stop web server - backup files - nuke files - move files from staging - start web server
When i've worked on Drupal sites before, if there is internal access to the server, or if remote desktop access is available, i've always developed it on the machine it would be ran from when live, and just not made it public on the server.
However, what is the best thing to do if you don't have access to the server yet, for example if the client hasn't got anything in place?
I need to be able to build and test the solution on my local machine, or on my VPS which I have RDP access to, and be able to move it over with as much ease as possible to the clients server when ready.
Any tips or best practices? As far as i'm aware Drupal doesn't have any specific migration tools? I could be wrong though
I don't work with Drupal, but for Prestashop, Wordpress, Zencart, etc. I always use the same workflow:
I setup a vhost in my virtual sever, usually using a subdomain of my own domain (like customer.mydomain.com). Install the software with its DB etc. on the server. Setup FTP access.
I get a local copy of the files, which I maintain in a local git repository, pushing to github for backup purposes mainly.
I work with ZendStudio and configure a remote server and set it up to upload the files when I save them, so I can check them pretty much as if I were working locally. But the main advantage of this approach is that I can share the project with the customer as it progresses.
When I have to move to final server, at least with Wordpress, I have to search/replace the domain name, which wordpress saves on DB. But I do it locally. I download the entire DB as an SQL file through phpmyadmin, open it, searc-replace and upload it again via phpmyadmin to the permanent server.
With ZenCart and others the problem is the config file, which stores some paths. For long projects or long term customers I modify the config file to use some config details or anothers depending on the server name.
adding to the above comment...
Check the "backup and migrate" module and the "backup files" module. "Backup and migrate" is useful in any setup...
with this I was able to do a barebones drupal install and then migrate/replace the database with the one backed up from my local system... if the databases are named differently you will still need to edit the settings.php
"backup files" is useful for themes and content assets like images etc. but is essentially just a wrapper around gzip
I typically develop on my local machine and then upload to server once complete.
All you need to do is change the folder name in /sites/ and change the settings.php file to reflect the server settings/domain.
Something you should be aware of:
If you are uploading files on your local installation, the file paths will be wrong on the server and you will need to execute a one off mysql replace query.
Make sure you use relative paths in any hard coded links.