I'm currently using webrick and lightsql for my Rails 3 development app, but I've finished the app now and need to move it on to MySQL and Apache, because that's what DreamHost uses, and it's probably a more suitable production environment. The only problem is I've never done this in rails before, as this is my first rails app.
Can anyone please point me in the direction of some tutorials for both of these, or advise me how I'm supposed to do it? I'd be eternally grateful! I'll be doing this in development mode first, and testing everything, and if it all works in both of those then I'll begin deployment. I've never done a deployment before either, so that's another thing I have to figure out ><
Thanks!
For change database to MySQL it´s easy.
You need add MySQL gem and remove SQLite gem:
gem mysql2
And change your database.yml (your_app/config/database.yml) to like this:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_development
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
test:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_test
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: yourdb_production
pool: 5
username: root
password: 123456
socket: /tmp/mysql.sock
If you don´t have experiencie with apache, you can deploy easy in webbynode.com, this guys have a rapid deploy.
Regards.
I've done deployments to Dreamhost using Apache/Passenger and there was just literally nothing to it; you specify the path to your project's root directory and then you are done. I did not make any .htaccess files or otherwise try and configure Apache manually. I freeze all my gems and rails in vendor which simplifies it quite a bit.
petersonferreira probably has answered the database question adequately. I have not personally done that (I always develop in MySQL) so I do not know if you may find any platform differences that you need to manage in your code.
There are a ton of tutorials out there for deploying Rails apps on Dreamhost.
Google is your friend.
Related
I'm new to Rails and I'm going through a tutorial on Lynda.com, Rails 4 Essentials. I'm on a Windows 7 x64 machine and I'm trying to connect the MySQL database to the Rails app. I've successfully created the database and created a new user.
I had issues running the mysql2 gem and I could only get version 0.3.11 to work (it's on version 0.3.16 as of this post). I copied the libmysql.dll from the C:\Program Files\MySQL\MySQL Connector.C 6.1\lib to my C:\RailsInstaller\Ruby2.0.0\bin directory as the instructions stated.
Everything seems to be ok at this point.
I configured my database.yml file to match my database credentials (I had to create this from scratch, nothing was generated when I ran mysql2).
#config\database.yml
development:
adapter: mysql2
database: simple_cms_development
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
test:
adapter: mysql2
database: simple_cms_test
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
production:
adapter: mysql2
database: simple_cms_production
username: craig
password: password
host: 127.0.0.1
socket: /tmp/mysql.sock
I got to try to connect my database with MySQL using:
rake db:schema:dump
and I get this crap:
LoadError: cannot load such file -- mysql2/2.0/mysql2
I see a directory called mysql2/1.9 and there is a file called mysql.so in there but there is no 2.0.
Any ideas? Thanks!
The joys of developing on a windows machine :)
I suggest you check this question - it looks like the same problem.
Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". On Windows XP with Ruby 2.0.0
I managed to get passed this issue by starting fresh. I followed these set of videos to set up Ruby, MySQL, and Rails on my Windows 7 x64 machine.
http://youtu.be/C5S7vjN6GLc
Worked like a gem, I'm rockin' and rollin' now.
I have downloaded a database to my desktop (I am using OSX)
I need to create rails app that uses this database, I am sorry if this question is so simple I am new to rails! I think that this socket: is the path to the database, is this correct?
development:
adapter: mysql2
encoding: utf8
database: ttlem_demo_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Your file seems to be correct. If you want to connect on localhost, you'll need to add this line
hostname: 127.0.0.1
to your file.
Note that the database.yml you provide contains only a section for development. You can add other section like 'test' or 'production'. You can see an example here.
I also found a good explanation of a socket here. Hope that will help you.
I have not gone too far with the development of the application.
i just did rails new app -d mysql and i did rails s loaded my browser.
Rails homepage loaded and I went inside my app folder, http://localhost:3000/demo/index and surprised to see this error ActiveRecord::ConnectionNotEstablished.
Please suggest some good way to get out of this and continue with my further development.
OS is Windows 7, I already installed mysql adapter and tried many solutions over the stackoverflow similar questions. None are solving my issue. I request serious help.
My database.yml looks like this with regards to development:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: app_development
pool: 5
username: root
password: pass
host: localhost
After creating application, create database using below command
rake db:create
and then start server using rails s
I switched to Ubuntu after trying number of methods to solve the issue on windows. Solved.
I'm having trouble connecting to a remote mysql db with mysql2 gem.
I get this error:
Host 'my_ip' is not allowed to connect to this MySQL server
My db.yml says:
remote_development:
adapter: mysql2
reconnect: false
host: host_ip
encoding: utf8
database: host_db
pool: 5
username: root
password:
And when I try to connect via my sql or telnet I have no problems at all. I've double and triple checked the data con my yml, but can't get through this. Any idea?
Btw I'm using Rails 3.2.3, Ruby 1.9.3, and tried mysql2 v 0.2.18 and 0.3.11 ... pls HELP!
I solved this, pretty simple...
I just created a new user and password to the db with specific permissions instead of using root :)
Should have tried this from the beginning.
I think this is the correct approach.
This seems to be a MySQL error message. I think the problem may be the user account that you are using. It should be set up with the 'username'#'%' format when setting it up. The percent sign means all ip addresses. You should then flush privileges on the server to make the account available.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mystore_development
pool: 5
username: root
password:password
host: localhost
try this one surely it wil work...
change your host:localhost and try it again it will work
I'm trying to get a rails app up and running on my computer, and I'm having issues with creating the databases. I've properly installed/setup rails, mysql and have installed the mysql 2.8.1 gem (I verified this with gem list).
So now, I'm trying to run 'rake db:create:all' and I'm getting the following error:
Couldn't create database for
{"encoding"=>"utf8",
"username"=>"root",
"adapter"=>"mysql", "database"=>"pyo",
"host"=>"localhost", "password"=>nil,
"socket"=>"/tmp/mysql.sock"}, charset:
utf8, collation: utf8_unicode_ci (if
you set the charset manually, make
sure you have a matching collation)
Couldn't create database for
{"encoding"=>"utf8",
"username"=>"root",
"adapter"=>"mysql",
"database"=>"pyo_test",
"host"=>"localhost", "password"=>nil,
"socket"=>"/tmp/mysql.sock"}, charset:
utf8, collation: utf8_unicode_ci (if
you set the charset manually, make
sure you have a matching collation)
I'm currently running 5.5.10 MySQL Community Server (GPL) on Snow Leopard (10.6.6)
And here is what is in my database.yml file
development:
adapter: mysql
encoding: utf8
database: pyo
username: root
password:
socket: /tmp/mysql.sock
host: localhost
test:
adapter: mysql
encoding: utf8
database: pyo_test
username: root
password:
socket: /tmp/mysql.sock
host: localhost
I notice how the end of the error says "charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)" -- Is that the issue? And if so, how do I fix it?
I've been stuck on this thing for hours and can't find anything that helps on Google. So any help at this point would be much appreciated.
Thanks!!
I know this thread is old but being a IT guy who believes in keeping good solid documentation in one place here goes:
The problem actually stems from your "config/database.yml" file. You are pointing ROR to the wrong location for the MySQL Socket.
I ran into this problem and what it turned out to be is the gem was built on a mac system and the developer did not account for other operating systems by putting his "mysql.sock" file in the "/tmp" directory rather than the "/var/run/mysqld/mysqld.sock" .
So his "database.yml" file looked like:
development:
adapter: mysql2
#encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /tmp/mysql.sock
Because I was on a Ubuntu System I had to change mine to the following:
development:
adapter: mysql2
#encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /var/run/mysqld/mysqld.sock
Yes the error can be misleading however it has nothing to do with your "encoding" or whether you are using localhost or 127.0.0.1 (At least in linux/UNIX systems these translate to the same thing and are synonymous)
Begin Edit
Also it is not good to have encoding commented out like I do above. So I am providing the modification here for reference.
development:
adapter: mysql2
encoding: utf8
database: somedatabase
pool: 5
username: someusername
password: somepassword
socket: /var/run/mysqld/mysqld.sock
End Edit
think I had something like this...fixed by adding this to database.yml:
host: 127.0.0.1
Or in your case, changing it from localhost.
I was getting the same issue with the mysql2 gem. Then I found my MySQL is listening in 'localhost' only and not '127.0.0.1', so I changed it to 'localhost' and now I don't get that issue anymore. Everything works now.
So, after about 3 or 4 days of googling and trying so many different things, I stumbled on this somehow:
http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/
And guess what? IT WORKS! PERFECTLY. Which leads me to believe that the problem lies within MySQL 5.5.10. Something about it will not just play nice with my ruby/rails environment. However, once I followed the instructions on the link above (which include uninstalling mysql and re-installing 5.1), my app now runs perfectly on my local machine.
Hope this helps someone!
I want to share my solution.
I had my database.yml as follow
default: &default
adapter: mysql2
encoding: utf8
username: root
password:
host: 127.0.0.1
port: 3306
development:
<<: *default
database: dev.database
My mistake was in this line
database: dev.database
So, I write without (.)
database: devdatabase