I am working on a ecommerce based on MagentoCommerce. I use 3 environments: dev (on my local machine), staging and production (both on my dedicated server).
The problem is that when I want to switch from local to staging, I have to edit my hosts file to point the domain used by Magento to my server's IP. However, this is time consuming and I was wondering what other magento developers out there were using as a strategy to not always have to change the hosts file when switching from an environment to another. Plus, when my ecommerce goes into production, I'll have to deal with 2 environments on the same IP.
The best would be if Magento had the domain hardcoded in only one file. That way I could keep different config files in each environment. Is that the case ? Otherwise, what places are domains "hard coded" ?
I'm running Magento on a Production server and a number of development and test domains.
The domain isn't hardcoded in any file - the domain is all in the database.
You have to change the secure base url and the unsecure base url when you move from server to server. Both of these are stored in the database and can be changed in the web based administration screens. When moving the database from one host to another, I use a script that does little but update these values. Here's the SQL you need to update these values:
update core_config_data
set value='http://whatever.com/'
where path='web/unsecure/base_url';
update core_config_data
set value='https://whatever.com/'
where path='web/secure/base_url';
You may also want to pay attention to the local.xml file where the database connection is configured. I'm sure that you'll want to have the different instances using different databases. In my configuration, I leave this file out of source control, and configure it just once for each instance.
Related
I am using MAMP in my Mac for local website testing.
Now, I've always set up multiple websites in the same root folder: 'htdocs'. Ex: htdocs>project1; htdocs>project2.
However I am reading about virtual hosts and how to use a different root for each website.
Is there any huge advantages of doing so apart from:
having a different url - ex: www.localhost2.example? (if localhost2 name is possible)
having a different database environment for each website? (although I typically use just one database per website and I don't mind having all databases in the same PHPMyAdmin)
What are the practical advantages?
It is a good idea for creating a test environment but it has pros and cons, If you're going to instantiate one vm per website then you will find resources problems when making them work all at once.
I usualy instantiate a virtual machine when a need to have a specific machine config for the web app (i.E. Linux specific software like WHMCS or so..), but for regular testing of websites I do deploy them on the localhost, they consume less resources that way.
In our team, I used to be the only developer, coding directly on our remote dev server but we're hiring more developers so we have a need to move the codebase to our local machines so we don't encounter any file collisions.
However, even though I want to use a local codebase, I don't want to use a local database. Syncing the database seems like a hassle and is to be honest not really needed. So we're sticking to multiple codebases, but one database.
How can I run Wordpress on my local machine, while still using our remote server database? How do I set this up in MAMP?
I'm kind of new in setting up servers/ports/databases etc so it's not my strong suite. The problem which I don't know how to get around is the urls.
For instance, our WP sites have the url format:
site1.portal.dev
site2.portal.dev
When I type these URLs I want the codebase to be local but the database to be our remote dev server.
Update the config to point to the remote database. Job done.
As long as the configuration of that database allows you to connect to it, it's very simple.
An example of updating the wordpress config
I work in a multi-developer team. I've found that the best option is to have a full local environment.
We use wp-migrate-db pro for copying the dev database down locally. Once configured (per site) it takes a minute to grab the latest copy from dev.
Having this separation allows your team to make changes for their local development efforts (such as entering bad data, test pages, posts etc) without affecting other developer efforts.
This approach also works well for working with developers of various skill levels...and helps to reduce bigger issues that you may come across later on.
Using your site1.portal.dev should work, as the site_url and home_url. When you click on a link in your dev portal, it will continue to use site1.portal.dev, as WordPress thinks your site resides there. The database just holds the information, it doesn't matter where it resides.
You can connect to your remote mysql instance by providing the correct host, username, password. Usually it would be localhost, but in your case, you will want whatever the IP/DNS address for the machine that is hosting your mysql server is.
You can test the mysql connection with
mysql <database> -h <host> -u <username> -p
add -P <port> if your mysql server is listening on a different port.
I know this is an old question, I just post the answer I found that works for me in case anyone is looking for the solution of "How can I run Wordpress on my local machine, while still using our remote server database"
Install WordPress on your server (http://yourdomain.com)
Configure it with your database
Make sure whitelisting your local machine IP in "Remote MySQL" within your server's hosting panel
Pull down the entire WordPress directory onto your local machine
into a project folder
Add project folder to MAMP or your local web server app of choice
(make a note of your Server Name)
Open your LOCAL copy of wp-config.php Change 'DB_HOST' to
'yourdomain.com'
And add the following just above 'require_once(ABSPATH .
'wp-settings.php'); in wp-config.php file
define('WP_CACHE', true); $currenthost = $_SERVER['HTTP_HOST']; $mypos = strpos($currenthost, 'localhost'); if ($mypos === false) { define('WP_HOME','http://yourdomain.com'); define('WP_SITEURL','http://yourdomain.com'); } else { define('WP_HOME','http://localhost'); define('WP_SITEURL','http://localhost'); }
Replace each instance of 'localhost' with your 'Server Name' in MAMP. (localhost is default)
Source URL: https://coderwall.com/p/ck8v4a/remote-database-with-local-wordpress-instance
How create beta (testing) website use same webroot and cake folder ?
That beta (testing) website probably is at http://beta.example.com or http://example.com/beta
A method I have been using for a couple of years is to set up staging server instances. These could be either separate physical servers, or on the same server using hostname checks. However, it is good practice to have separate web roots and separate databases under each instance. You'll be asking for trouble if different aspects of your site are shared between staging instances!
My setup is the following:
Development (a computer with the source code on, set up to serve to http://websitename.dev (a local domain).
Preview (a separate server, used to provide a preview of a website or a change to a website, before doing the extra work to putting it live). http://websitename.preview.mycompanyname.com
Next (this is on the same server as the live website, under a different web root, and connected to a different database. The reason for this server is because SO MANY TIMES has a site worked on the development machine, but when it is put live, something on the live server makes the site DIE. http://websitename.next.mycompanyname.com
Live (the usual live server setup) http://websitename.com
This is all achieved by assigning DNS records correctly (to point to the correct servers), and using the config script of my web server application, listening to the hostnames and serving the correct web root.
A testing or "staging" server should be set up completely independently of the production server. You should not reuse any component of the live system, which even includes the database. Just set up a copy of the production system with a separate database, separate files, if possible a separate (but identical) server.
The point of a test system is to test code that is possibly buggy and may delete all your live data, shoot your dog and take your lunch hostage. Also, your test system may not be compatible with the production system, depending on what you're going to change down the road.
As such, create a new virtual host in your Apache config (or whatever you're using) and set it up exactly like the production system. Done.
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.
I usually have a config-file with some global variables for database connectivity settings (such as db host, db name, user, pass).
I also really like to be able to just drag and drop all files from my dev machine to the production server. However, development db host etc may be different from the one on the production server.
Is there an easy way of, in PHP, saying something like "if I'm on the dev-machine, use these values"? (I'd prefer to avoid hacks based on host IP / name.) I'm thinking of something like perhaps setting something in php.ini or httpd.conf so that for instance $DEV_MACHINE, is set to true on the dev machine.
You can set up an Apache variable with SetEnv, and query it with PHP's apache_getenv().
I usually use a file called config-local.php which is not under the source control.
If the file is absent, the app shows a warning page saying "finish the setup", or just runs a master to set up database credentials etc.
You can always use the URL. The dev url and the prod url should be different. And should be pretty stable.
But the ideal way is to keep the creds separated. You don't want the prod creds getting stolen if the dev server is hacked. So it is really best to suck it up and just keep them separate.