Join the community today
Register Now

Wordpress HOW Install Wordpress with command line parameters?

Discussion in 'Blogs & CMS usage' started by AHTOLLlKA, Jun 6, 2020.

  1. AHTOLLlKA

    AHTOLLlKA Member

    32
    4
    8
    Dec 1, 2017
    Ratings:
    +9
    Local Time:
    6:34 AM
    how i can install new website at wordpress via cmd line ? like: centminmod wordpress domain.com SSL NGINX_CACHE=yes LOGIN_PROTECT=yes plugin1=no plugin2=no plugin3=yes .... adn etc ?? without 22 menu wizzard?

     
  2. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    1:34 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Currently if you want to replicate centmin.sh menu option 22 wordpress installs, then it's not possible. But I am working on a command line version to replicate centmin.sh menu option 22, so plan to eventually be available. I might release an early preview version to Centmin Mod Premium Member first in private Premium members only forum to discussion/feedback gathering.
     
  3. AHTOLLlKA

    AHTOLLlKA Member

    32
    4
    8
    Dec 1, 2017
    Ratings:
    +9
    Local Time:
    6:34 AM
    any news ? ^_^
     
  4. tininho

    tininho Active Member

    182
    44
    28
    May 22, 2019
    eu
    Ratings:
    +135
    Local Time:
    5:34 AM
  5. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    1:34 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah it hasn't had much progress. Though @tininho linked articles mention of using expect tool is one variant I have tested for centmin.sh menu option 22 to automate command line installs. I haven't tested in since though - rough expect wrapper I did back then is located in Github Gist at expect centmin.sh menu option 22. This version of expect code is old so won't match with current centmin.sh menu option 22 prompts so if someone wants to test/play with it or improve it, it would need modifying. More detailed guide on using expect for any script automation Expect Command And How To Automate Shell Scripts Like Magic - Like Geeks. You can see the outlined guide in the link for using autoexpect to build the script somewhat - though from my experience you'd need to modify the script eventually.
    Code (Text):
    cd /usr/local/src/centminmod
    autoexpect ./centmin.sh
    


    edit: Ok quickly modded the old expect wpnv.sh to below for current cache-enabler centmin.sh menu option 22 install

    so you'd run wpnv.sh with command line options for the domain name, admin display name, email address and pure-ftpd username i.e.
    Code (Text):
    ./wpnv.sh wordpress2.domain.com YOURADMIN_NAME YOUR_EMAIL_ADDR FTP_USERNAME
    

    actual wpnv.sh script with is an expect script which you need to chmod +x for
    Code (Text):
    #!/usr/bin/expect -f
    set domain [lindex $argv 0]
    set adminname [lindex $argv 1]
    set email [lindex $argv 2]
    set ftpusername [lindex $argv 3]
    set timeout -1
    spawn centmin
    expect "Enter option"
    send -- "22\r"
    expect "Do you want to continue with Nginx vhost site creation ?"
    send -- "y\r"
    expect "Enter vhost domain name you want to add"
    send -- "$domain\r"
    expect "Create a self-signed SSL certificate Nginx vhost?"
    send -- "y\r"
    expect "Get Letsencrypt SSL certificate Nginx vhost?"
    send -- "y\r"
    expect "Enter option number 1-4:"
    send -- "4\r"
    expect "Install CyberChimps Responsive Theme"
    send -- "\r"
    expect "Install Classic Editor Wordpress Plugin ?"
    send -- "\r"
    expect "Install Autoptimize Gzip Companion Wordpress Plugin ?"
    send -- "\r"
    expect "Install Google Native LazyLoad Plugin ?"
    send -- ""
    send -- "n\r"
    expect "Set custom WP Admin Display Name ?"
    send -- "y\r"
    expect "Enter Custom WP Admin Display Name: "
    send -- "$adminname\r"
    expect "Install Wordpress in subdirectory /blog ?"
    send -- "n\r"
    expect "Disable Auto Generated WP Admin Username / Password ?"
    send -- "n\r"
    expect "Disable wp-login.php password protection ?"
    send -- "y\r"
    expect "Enter email address for Admin User for Wordpress Installation:"
    send -- "$email\r"
    expect "Enter option"
    send -- "1\r"
    expect "Create FTP username for vhost domain (enter username):"
    send -- "$ftpusername\r"
    expect "Do you want to auto generate FTP password"
    send -- "y\r"
    expect "Do you want to exclude mobile/tablet devices from full page caching ?"
    send -- "y\r"
    expect "/usr/local/nginx/conf/wpincludes/$domain/wpinfo.sh"
    # CTRL+C
    send \x03
    

    You can also modify it to have a variable for cache option selection

    Code (Text):
    --------------------------------------------------------
            Wordpress Caching               
    --------------------------------------------------------
    1) KeyCDN Cache Enabler
    2) Redis Nginx Level Caching
    3) Wordpress Super Cache
    --------------------------------------------------------
    Enter option [ 1 - 3 ] 1
    


    so change
    Code (Text):
    expect "Enter option"
    send -- "1\r"
    

    to
    Code (Text):
    expect "Enter option"
    send -- "$cacheoption\r"
    

    and add to top of script
    Code (Text):
    set cacheoption [lindex $argv 4]
    

    so as 5th command line argument - starting at 0 to 4
    Code (Text):
    #!/usr/bin/expect -f
    set domain [lindex $argv 0]
    set adminname [lindex $argv 1]
    set email [lindex $argv 2]
    set ftpusername [lindex $argv 3]
    set cacheoption [lindex $argv 4]
    

    Then you can pass cache option on command line
    Code (Text):
    ./wpnv.sh wordpress2.domain.com YOURADMIN_NAME YOUR_EMAIL_ADDR FTP_USERNAME 1
    

    You can test and modify as needed and to remove the test Wordpress install just use the generated uninstaller i.e. for wordpress2.domain.com would be at /root/tools/wp_uninstall_wordpress2.domain.com.sh

    Beauty of using expect is you can automate almost any script that has interactive prompts so definitely worth reading and playing with as outlined at Expect Command And How To Automate Shell Scripts Like Magic - Like Geeks
     
    Last edited: Apr 20, 2022
  6. AHTOLLlKA

    AHTOLLlKA Member

    32
    4
    8
    Dec 1, 2017
    Ratings:
    +9
    Local Time:
    6:34 AM
    work perfectly! thx
    btw, how i can run wp-cli from bash script, i have file 1.sh with
    sudo -u nginx -- wp plugin install /home/wp/plugin/updraftplus.zip --activate

    but nginx is nologin, and --allow-root its bad idea, how i can execute it as nginx user to install plugin?
    google it 3 hours and nothing cant find (

    UPD, chmod 0755 at /bin/wp - help, but i dont think its a good idea
     
    Last edited: Apr 23, 2022
  7. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    1:34 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    It's because I configured wp command to only run for root user
    Code (Text):
    ls -lah /bin/wp
    -rwx------ 1 root root 6.2M Apr 23 00:14 /bin/wp
    

    the centmin.sh generated cronjob for auto wordpress plugin updates every 8hrs also assumes wp is run by root user i.e. for Wordpress domain, update at /root/tools/wp_updater_wordpress.domain.com.sh so you'd also need to modify that script for your domain for non-root user running
    Code (Text):
    crontab -l | grep wp_updater_wordpress
    0 */8 * * * sleep 106s > /dev/null 2>&1;/root/tools/wp_updater_wordpress.domain.com.sh >/dev/null 2>&1