Rails デプロイ時 MYSQL2 install
解決したいこと
今Railsのアプリをデプロイしようとしたのですが、
bundle install
を実行したところ下記のようなエラーが出てしまいました。色々調べて試してみたのですが、自分の力では及ばずでした。どうか、お力を貸してください。
発生している問題・エラー
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
/home/ec2-user/.rbenv/versions/2.7.6/bin/ruby -I
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0 -r
./siteconf20231211-19703-1jgj6jw.rb extconf.rb
--with-mysql-config\=/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... no
-----
Using mysql_config at
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary
libraries and/or headers. Check the mkmf.log file for more details.
You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/ec2-user/.rbenv/versions/2.7.6/bin/$(RUBY_BASE_NAME)
--with-openssl-dir
--without-openssl-dir
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysql-config
extconf.rb:118:in ``': Permission denied -
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
(Errno::EACCES)
from extconf.rb:118:in `<main>'
To see why this extension failed to compile, please check the mkmf.log
which can be found here:
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.5.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5 for
inspection.
Results logged to
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.5.5/gem_make.out
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:99:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/ext_conf_builder.rb:48:in
`block in build'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/tempfile.rb:291:in
`open'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/ext_conf_builder.rb:30:in
`build'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:169:in
`block in build_extension'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:165:in
`synchronize'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:165:in
`build_extension'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:210:in
`block in build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:207:in
`each'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:207:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/installer.rb:844:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/source/rubygems.rb:198:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:54:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:156:in
`do_install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:141:in
`install_serially'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:91:in
`call'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:67:in
`call'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:244:in
`install_in_parallel'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:201:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:89:in
`block in run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:12:in
`block in lock'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:9:in
`open'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:9:in
`lock'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:71:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:23:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli/install.rb:62:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:261:in
`block in install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/settings.rb:131:in
`temporary'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:260:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:34:in
`dispatch'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:28:in
`start'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/exe/bundle:45:in
`block in <top (required)>'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/exe/bundle:33:in
`<top (required)>'
/home/ec2-user/.rbenv/versions/2.7.6/bin/bundle:23:in `load'
/home/ec2-user/.rbenv/versions/2.7.6/bin/bundle:23:in `<main>'
An error occurred while installing mysql2 (0.5.5), and
Bundler cannot continue.
In Gemfile:
mysql2
エラー文の中に
(Errno::EACCES)
from extconf.rb:118:in `<main>'
とあったので
118 ver = `#{mc} --version`.chomp.to_f
To see why this extension failed to compile, please check the mkmf.log
which can be found here:
とも書いてあったので、 mkmf.logも読んではみたのですがよく分からずでした
ご教授お願いします。
ーーーーーーーー追記ーーーーーーーー
一文では分からないと思いましたので周辺も追記しときます。
GLOB = "{#{dirs.join(',')}}/{mysql_config,mysql_config5,mariadb_config}".freeze
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111elsif (mc = (with_config('mysql-config') || Dir[GLOB].first))
112 # If the user has provided a --with-mysql-config argument, we must respect it or fail.
113 # If the user gave --with-mysql-config with no argument means we should try to find it.
114 mc = Dir[GLOB].first if mc == true
115 abort "-----\nCannot find mysql_config at #{mc}\n-----" unless mc && File.exist?(mc)
116 abort "-----\nCannot execute mysql_config at #{mc}\n-----" unless File.executable?(mc)
117 warn "-----\nUsing mysql_config at #{mc}\n-----"
118 ver = `#{mc} --version`.chomp.to_f
119 includes = `#{mc} --include`.chomp
120 abort unless $CHILD_STATUS.success?
121 libs = `#{mc} --libs_r`.chomp
122 # MySQL 5.5 and above already have re-entrant code in libmysqlclient (no _r).
123 libs = `#{mc} --libs`.chomp if ver >= 5.5 || libs.empty?
124 abort unless $CHILD_STATUS.success?
125 $INCFLAGS += ' ' + includes
126 $libs = libs + " " + $libs
127 rpath_dir = libs