Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not create new 'wp-config.php' file. #31

Closed
kporembinski opened this issue Oct 9, 2017 · 6 comments
Closed

Error: Could not create new 'wp-config.php' file. #31

kporembinski opened this issue Oct 9, 2017 · 6 comments

Comments

@kporembinski
Copy link

kporembinski commented Oct 9, 2017

Hello!

I have strange problem. I can't create new wp-config.php file. I'm getting error which is probably related to code:

$bytes_written = file_put_contents( ABSPATH . 'wp-config.php', $out );
		if ( ! $bytes_written ) {
			WP_CLI::error( "Could not create new 'wp-config.php' file." );
		} else {
			WP_CLI::success( "Generated 'wp-config.php' file." );
		}

Error:

[06:09:35] [root@a1 tcwp]# ./wp-cli --allow-root config create --dbname=test --dbuser=test--force --skip-check --debug
Debug (bootstrap): No readable global config found (0.097s)
Debug (bootstrap): No project config found (0.098s)
Debug (bootstrap): argv: ./wp-cli --allow-root config create --dbname=test --dbuser=test --force --skip-check --debug (0.098s)
Debug (bootstrap): ABSPATH defined: /var/www/tcwp/ (0.099s)
Debug (bootstrap): Running command: config create (0.1s)
Error: Could not create new 'wp-config.php' file.

In error_log I have found:

PHP Warning:  file_get_contents(phar://wp-cli.phar/templates/phar://wp-cli/vendor/wp-cli/config-command/templates/wp-config.mustache): failed to open stream: phar error: "templates/phar:/wp-cli/vendor/wp-cli/config-command/templates/wp-config.mustache" is not a file in phar "wp-cli.phar" in phar:///home/mateuszdemo/public_html/wp-cli/php/utils.php on line 457

wp-cli is generating empty file. I don't know why it is not working. I have tested this on:

System: CentOS release 6.9 (Final)

PHP (without suhosin):

PHP 7.1.9 (cli) (built: Sep 11 2017 16:59:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.9, Copyright (c) 1999-2017, by Zend Technologies

WordPress: 4.8.2

@kporembinski
Copy link
Author

It is working when I'm using wp-cli.phar not wp-cli or wp name for command.

@danielbachhuber
Copy link
Member

Hi @kporembinski,

GitHub issues are meant for enhancement requests and specific, reproducible bugs, not for general support questions. For support options, please review http://wp-cli.org/#support

@minusf
Copy link

minusf commented Apr 23, 2018

@danielbachhuber Could you please elaborate why this is a "general support question" and not a reproducable bug?

the install instructions clearly state that renaming wp-cli.phar to wp
is a supported mode of operation: https://make.wordpress.org/cli/handbook/installing/

on CentOS 6.8 i also have the same issue:

$ ./wp --info
OS:     Linux 2.6.32-642.11.1.el6.x86_64 #1 SMP Fri Nov 18 19:25:05 UTC 2016 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php
PHP version:    7.0.16
php.ini used:
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/webmaster
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.5.1

$ ./wp config create --debug --path=wordpress --dbname=wordpress \
--dbuser=wordpress --dbpass=eeThaa8leeg5
Debug (bootstrap): No readable global config found (0.049s)
Debug (bootstrap): No project config found (0.05s)
Debug (bootstrap): argv: ./wp config create --debug --path=wordpress --dbname=wordpress --dbuser=wordpress --dbpass=eeThaa8leeg5 (0.05s)
Debug (bootstrap): ABSPATH defined: /home/webmaster/wordpress/ (0.05s)
Debug (bootstrap): Running command: config create (0.05s)

Warning: file_get_contents(phar://wp-cli.phar/templates/phar://wp-cli/vendor/wp-cli/
config-command/templates/wp-config.mustache): failed to open stream: phar error:
"templates/phar:/wp-cli/vendor/wp-cli/config-command/templates/wp-config.mustache"
is not a file in phar "wp-cli.phar" in phar:///home/webmaster/wp-cli/php/utils.php
on line 476
Error: Could not create new 'wp-config.php' file.

$ ls -la wordpress/wp-config.php
-rw-r--r-- 1 webmaster role 0 Apr 23 23:06 wordpress/wp-config.php

$ rm wordpress/wp-config.php

$ ./wp-cli.phar config create --debug --path=wordpress --dbname=wordpress \
--dbuser=wordpress --dbpass=eeThaa8leeg5
Debug (bootstrap): No readable global config found (0.052s)
Debug (bootstrap): No project config found (0.053s)
Debug (bootstrap): argv: ./wp-cli.phar config create --debug --path=wordpress --dbname=wordpress --dbuser=wordpress --dbpass=eeThaa8leeg5 (0.053s)
Debug (bootstrap): ABSPATH defined: /home/webmaster/wordpress/ (0.053s)
Debug (bootstrap): Running command: config create (0.053s)
Success: Generated 'wp-config.php' file.

$ ls -la wordpress/wp-config.php
-rw-r--r-- 1 webmaster role 2593 Apr 23 23:07 wordpress/wp-config.php

@danielbachhuber
Copy link
Member

I think this is a duplicate of wp-cli/wp-cli#4689 (comment)

@kwhat
Copy link

kwhat commented Jun 20, 2019

I am not sure how related this is to #4689 but it is definitely a bug and should have been addressed not dismissed.

@andrewjmead
Copy link

I just ran into this one today.

It looks like it doesn't care what the file's name is, but it must have the phar extension. I was able to rename it without issue, but removing the extension caused the same error that was reported 7 years ago:

Error: Could not create new 'wp-config.php' file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants