taketyan-man
@taketyan-man

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

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>'

とあったので

extconf.rb
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も読んではみたのですがよく分からずでした

ご教授お願いします。

ーーーーーーーー追記ーーーーーーーー
一文では分からないと思いましたので周辺も追記しときます。

extconf.rb

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

0

1Answer

「extconf.rb:118:in ``': Permission denied -」とあるのでsudoや管理者で「bundle install 」を実行してみるといいかもしれませんね。

1Like

Comments

  1. @taketyan-man

    Questioner

    一応管理者でbundle installしてるつもりなのですが、どこのディレクトリの権限を変えればいいですか?
    教えていただいた箇所の周辺に書いてあるディレクトリやファイルは権限見てみたのですが、問題はなさそうです。
    初心者なので、あってるかわかりませんが。

  2. 「mkmf.log」の内容も載せてほしいです。

  3. まさかとは思うのだけど、ディスクには空き容量はありますか?ディスクフルになってませんか?

  4. @taketyan-man

    Questioner

    「mkmf.log」の内容です
    エラー文に「checking for rb_enc_interned_str() in ruby.h... no」とありますが他の人は基本的にyesになってるぽいので
    そこの部分だけ抜粋しました。他にもみたいところあれば教えて欲しいです。

    have_func: checking for rb_enc_interned_str() in ruby.h... -------------------- no

    "gcc -o conftest -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0/x86_64-linux -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0/ruby/backward -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0 -I. -g -O2 -fPIC conftest.c -L. -L/home/ec2-user/.rbenv/versions/2.7.6/lib -Wl,-rpath,/home/ec2-user/.rbenv/versions/2.7.6/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/ec2-user/.rbenv/versions/2.7.6/lib -L/home/ec2-user/.rbenv/versions/2.7.6/lib -lruby -lm -lc"
    conftest.c: 関数 ‘t’ 内:
    conftest.c:16:57: エラー: ‘rb_enc_interned_str’ undeclared (first use in this function); did you mean ‘rb_sym_interned_p’?
    int t(void) { void ((volatile p)()); p = (void (()()))rb_enc_interned_str; return !p; }
    ^~~~~~~~~~~~~~~~~~~
    rb_sym_interned_p
    conftest.c:16:57: 備考: 未宣言の識別子は出現した各関数内で一回のみ報告されます
    checked program was:
    /* begin /
    1: #include "ruby.h"
    2:
    3: #include
    4:
    5: /top/
    6: extern int t(void);
    7: int main(int argc, char *argv)
    8: {
    9: if (argc > 1000000) {
    10: int (
    volatile tp)(void)=(int (
    )(void))&t;
    11: printf("%d", (tp)());
    12: }
    13:
    14: return !!argv[argc];
    15: }
    16: int t(void) { void ((volatile p)()); p = (void (()()))rb_enc_interned_str; return !p; }
    /
    end */

    "gcc -o conftest -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0/x86_64-linux -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0/ruby/backward -I/home/ec2-user/.rbenv/versions/2.7.6/include/ruby-2.7.0 -I. -g -O2 -fPIC conftest.c -L. -L/home/ec2-user/.rbenv/versions/2.7.6/lib -Wl,-rpath,/home/ec2-user/.rbenv/versions/2.7.6/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/ec2-user/.rbenv/versions/2.7.6/lib -L/home/ec2-user/.rbenv/versions/2.7.6/lib -lruby -lm -lc"
    /tmp/ccGWQvww.o: 関数 t' 内: /var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2/conftest.c:17: rb_enc_interned_str' に対する定
    義されていない参照です
    collect2: エラー: ld はステータス 1 で終了しました
    checked program was:
    /* begin */
    1: #include "ruby.h"

  5. @taketyan-man

    Questioner

    「まさかとは思うのだけど、ディスクには空き容量はありますか?ディスクフルになってませんか?」
    とのことですが、dfコマンドを使ってみたのですが
    [ec2-user@ip-10-0-0-84 /]$ df
    ファイルシス 1K-ブロック 使用 使用可 使用% マウント位置
    devtmpfs 479000 0 479000 0% /dev
    tmpfs 487796 0 487796 0% /dev/shm
    tmpfs 487796 512 487284 1% /run
    tmpfs 487796 0 487796 0% /sys/fs/cgroup
    /dev/xvda1 8376300 4578228 3798072 55% /
    tmpfs 97560 0 97560 0% /run/user/1000
    と出ました。やり方と見方これであってますかね?

  6. はい。ディスクの容量を調べるコマンドはあってます。ディスクには空き容量があり、問題なさそう。

  7. 「ruby.h」がないようなので、管理者で「yum install ruby-devel」でインストールした後、「bundle install」を実行するとどうなりますか?

  8. @taketyan-man

    Questioner

    install ruby-develした後にmysql_configが追加さえれたのでそこに
    bundle config "--with-mysql-config="にて指定したら
    うまくbundle installできました。ありがとうございました。

  9. 解決したようでしたら、質問をクローズにするといいですよ。

Your answer might help someone💌