So... I've installed Craft online, and I wanted to start templating my CraftCMS, but I'd like to work with a repository so I can have some kind of versioning. The easiest way to do so seemed to me to install Craft on our hosting server, download those files locally and connect to the online database using MAMP pro. I had some issues with our host (I had to whitelist my IP address), but now I can connect to the database using Sequel Pro, but when I try to access my craft CMS site through my local files I get the Craft message "service unavailable". My Mamp Pro is pointed to my public folder (2 folders in my site: public and craft, and it's pointed to this public folder with the index file in it) and I've used the same db settings as the ones I've used in Sequal Pro. Still: no succes. The only thing I've changed after downloading the site are these db setting for the host - as I had to do in Sequal Pro. Can anyone help a newbie in Craft CMS out here :-)? Thanks!
1 Answer
Here is how I have set things up in the past using a similar workflow.
When you get Craft out of the box (for lack of better words) as you said there is a craft
folder and a public
folder. Generally you want your craft
folder above/out of your web root. That would look something like this:
craft/
|- app
|- config
...
public/
|- index.php
|- robots.txt
When setting up your site, point your doc_root
to the public/
folder.
For example, if you are using a Mac, a default doc_root
might look like this:
<VirtualHost *:80>
ServerName sitename.dev
DocumentRoot "/Applications/MAMP/htdocs/sitename/public"
</VirtualHost>
If successful, you should see a screen saying that your site is unavailable. I can't remember the exact verbiage.
From there I will edit two files:
/craft/config/db.php
/craft/config/general.php
db.php
return array(
'*' => array( // Global configuration
'tablePrefix' => ''
),
'.dev' => array( // local configuration
'server' => '127.0.0.1',
'user' => 'username',
'password' => 'password',
'database' => 'database'
),
'.com' => array( // production configuration
'server' => 'hostname',
'user' => 'username',
'password' => 'password',
'database' => 'database'
)
);
general.php
return array(
'*' => array(
'cpTrigger' => 'your-custom-admin-url',
'omitScriptNameInUrls' => true
),
'.dev' => array( // local configuration
'devMode' => true,
'siteUrl' => 'http://mysite.dev/',
'environmentVariables' => array(
'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
'baseUrl' => 'http://mysite.dev/',
)
),
'.com' => array( // production configuration
'siteUrl' => 'http://www.mysite.com/',
'environmentVariables' => array(
'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
'baseUrl' => 'http://www.mysite.com'
)
)
);
By having the multi-environment settings like the above, you can commit your code and it will run regardless of environment.
Generally, I like to have a local database which is separate from my production db. My luck, I'll do something silly and delete something on accident. Depending on how big of changes you are making post-launch, I am sure there are good/better/best ways to migrate the updates to your production db vs. manually entering it. But, if they are simple things (added a new field) I usually just do that manually on my production server.
It sounds like if you can connect to your production db via a 3rd party tool, but not your application there might be some permission trouble (just a guess). Try working locally with everything first, then move it to your other server.
Hope this helps!
-
Thanks for the help I've been able to set it all up locally (downloaded the database and installed it locally), the virtual host is being handled perfectly by MAMP Pro (I've went and checked the httpd.conf file) so that's all OK :-). But... I'd like to use my files locally and connect with the online database since I set up the craft control panel first and only do some small changes later (e.g. to rename a handle) and add some dummy content to do the theming. To me, it seems a bit to much to always have to upload the local database again. Or am I wrong and should I start working like that?– JanCommented Apr 1, 2016 at 9:28
-
That's totally up to you. I am (personally) always scared of messing something up on production. Just a total guess here, but you may have to use a different IP to connect through your application. I know I have an external IP and an internal IP I use for 3rd party tools like sequel pro. Then usually the internal IP gets used within my application.– DamonCommented Apr 1, 2016 at 11:53