wp cli - WP-CLI not working from Bash script

I am trying to make installations easier on my Mac using MAMP by using WP-CLI.I made a simple .sh file:wp core download

I am trying to make installations easier on my Mac using MAMP by using WP-CLI.

I made a simple .sh file:

wp core download
wp core config --dbname=dbname --dbuser=root --dbpass=root
wp db create
wp core install --url="http://localhost:8888/folder" --title="name" --admin_user="admin" --admin_password="password" --admin_email="[email protected]"

This works fine when I enter it line by line in the terminal, however as soon as I turn it into a .sh file and run it through sh install.sh, it stops as soon as the database is created, but doesn't actually install Wordpress into the database.

What could cause this? This is the wp --info output:

PHP binary: /Applications/MAMP/bin/php/php7.1.0/bin/php
PHP version:    7.1.0
php.ini used:   /Applications/MAMP/bin/php/php7.1.0/conf/php.ini
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 1.0.0

I am trying to make installations easier on my Mac using MAMP by using WP-CLI.

I made a simple .sh file:

wp core download
wp core config --dbname=dbname --dbuser=root --dbpass=root
wp db create
wp core install --url="http://localhost:8888/folder" --title="name" --admin_user="admin" --admin_password="password" --admin_email="[email protected]"

This works fine when I enter it line by line in the terminal, however as soon as I turn it into a .sh file and run it through sh install.sh, it stops as soon as the database is created, but doesn't actually install Wordpress into the database.

What could cause this? This is the wp --info output:

PHP binary: /Applications/MAMP/bin/php/php7.1.0/bin/php
PHP version:    7.1.0
php.ini used:   /Applications/MAMP/bin/php/php7.1.0/conf/php.ini
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 1.0.0
Share Improve this question edited May 14, 2019 at 19:25 norman.lol 3,2313 gold badges30 silver badges35 bronze badges asked Jan 26, 2017 at 15:01 user48745user48745 131 silver badge5 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 1

The reason is because the cron script's environment has minimal configuration. When you as a user log into your system, additional environment variable are set which allow you to execute programs without explicitly defining the full path.

The best way to fix this is to define the full path to your program(s) in your cron script. This is generally best practice even for system calls. For example if your wp resides in /usr/local/bin, modify your cron script:

/usr/local/bin/wp core download
/usr/local/bin/wp core config --dbname=dbname --dbuser=root --dbpass=root
/usr/local/bin/wp db create
/usr/local/bin/wp core install --url="http://localhost:8888/folder" --title="name" --    admin_user="admin" --admin_password="password" --admin_email="[email protected]"

I had a similar problem using WSL. The problem was that I had created the .sh script under Windows, so it had Windows style line ending (CR LF) instead of just LF.

Changing the line endings to LF fixed it for me.

I have created a bash script to install wordpress.

This script will automate the following:

Downlaod and install Wordpress automatically Create Default Users with passwords Install all default plugins Install the default or custom theme by zip url you mostly used. You can find script on github

https://github/jeoga/wordpress_install_bash_script

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132593a4613044.html

相关推荐

  • wp cli - WP-CLI not working from Bash script

    I am trying to make installations easier on my Mac using MAMP by using WP-CLI.I made a simple .sh file:wp core download

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信