{"id":1499,"date":"2021-10-27T20:38:29","date_gmt":"2021-10-27T20:38:29","guid":{"rendered":"https:\/\/ionoslabs.com\/?p=1499"},"modified":"2022-07-11T14:29:28","modified_gmt":"2022-07-11T14:29:28","slug":"wordpress-install-bash-script","status":"publish","type":"post","link":"https:\/\/ionoslabs.com\/index.php\/wordpress-install-bash-script\/","title":{"rendered":"WordPress Install Bash Script"},"content":{"rendered":"<div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1289.6px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_3_4 3_4 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:75%;--awb-margin-top-large:0px;--awb-spacing-right-large:2.56%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:2.56%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\" style=\"--awb-text-transform:none;\"><p>What this bash script does<\/p>\n<ul>\n<li>Installs apache2 webserver, mysql-server and PHP required for wordpress<\/li>\n<li>Enables Apache2 webserver to autostart<\/li>\n<li>Enables mysql-server to autostart<\/li>\n<li>Creates a randomly generated mysql DB name<\/li>\n<li>Creates and randomly generated mysql username and password<\/li>\n<li>Creates a randomly generated mysql root user password<\/li>\n<li>Downloads and installs wordpress<\/li>\n<li>Writes the usernames and passwords to local files \/var\/log\/wpinstall.log<\/li>\n<\/ul>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-1 > .CodeMirror, .fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-1 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_1\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_1\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_1\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">#\/bin\/sh\n\ninstall_dir=\"\/var\/www\/html\"\n#Creating Random WP Database Credenitals\ndb_name=\"wp`date +%s`\"\ndb_user=$db_name\ndb_password=`date |md5sum |cut -c '1-12'`\nsleep 1\nmysqlrootpass=`date |md5sum |cut -c '1-12'`\nsleep 1\n\n#### Install Packages for https and mysql\napt -y install lynx\napt -y install apache2\napt -y install mysql-server\n\n####Install PHP\napt -y install php\napt -y install php-mysql \napt -y install php-gd\napt -y install php-curl\napt -y install php-zip\napt -y install php-xml\n\n\n#### Start http\nrm \/var\/www\/html\/index.html\nsystemctl enable apache2\nsystemctl start apache2\n\n#### Start mysql and set root password\n\nsystemctl enable mysql\nsystemctl start mysql\n\n\/usr\/bin\/mysql -e \"USE mysql;\"\n\/usr\/bin\/mysql -e \"UPDATE user SET Password=PASSWORD($mysqlrootpass) WHERE user='root';\"\n\/usr\/bin\/mysql -e \"FLUSH PRIVILEGES;\"\ntouch \/root\/.my.cnf\nchmod 640 \/root\/.my.cnf\necho \"[client]\">>\/root\/.my.cnf\necho \"user=root\">>\/root\/.my.cnf\necho \"password=\"$mysqlrootpass>>\/root\/.my.cnf\n  \n\nsed -i '0,\/AllowOverride\\ None\/! {0,\/AllowOverride\\ None\/ s\/AllowOverride\\ None\/AllowOverride\\ All\/}' \/etc\/apache2\/apache2.conf #Allow htaccess usage\n\nsystemctl restart apache2\n\n####Download and extract latest WordPress Package\nif test -f \/tmp\/latest.tar.gz\nthen\necho \"WP is already downloaded.\"\nelse\necho \"Downloading WordPress\"\ncd \/tmp\/ && wget \"http:\/\/wordpress.org\/latest.tar.gz\";\nfi\n\n\/bin\/tar -C $install_dir -zxf \/tmp\/latest.tar.gz --strip-components=1\nchown www-data: $install_dir -R\n\n#### Create WP-config and set DB credentials\n\/bin\/mv $install_dir\/wp-config-sample.php $install_dir\/wp-config.php\n\n\/bin\/sed -i \"s\/database_name_here\/$db_name\/g\" $install_dir\/wp-config.php\n\/bin\/sed -i \"s\/username_here\/$db_user\/g\" $install_dir\/wp-config.php\n\/bin\/sed -i \"s\/password_here\/$db_password\/g\" $install_dir\/wp-config.php\n\ncat << EOF >> $install_dir\/wp-config.php\ndefine('FS_METHOD', 'direct');\nEOF\n\ncat << EOF >> $install_dir\/.htaccess\n# BEGIN WordPress\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index.php$ \u2013 [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php [L]\n<\/IfModule>\n# END WordPress\nEOF\n\nchown www-data: $install_dir -R\n\n##### Set WP Salts\ngrep -A50 'table_prefix' $install_dir\/wp-config.php > \/tmp\/wp-tmp-config\n\/bin\/sed -i '\/**#@\/,\/$p\/d' $install_dir\/wp-config.php\n\/usr\/bin\/lynx --dump -width 200 https:\/\/api.wordpress.org\/secret-key\/1.1\/salt\/ >> $install_dir\/wp-config.php\n\/bin\/cat \/tmp\/wp-tmp-config >> $install_dir\/wp-config.php && rm \/tmp\/wp-tmp-config -f\n\/usr\/bin\/mysql -u root -e \"CREATE DATABASE $db_name\"\n\/usr\/bin\/mysql -u root -e \"CREATE USER '$db_name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$db_password';\"\n\/usr\/bin\/mysql -u root -e \"GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';\"\n \n######Display generated passwords to log file.\necho \"Database Name: \" $db_name\necho \"Database User: \" $db_user\necho \"Database Password: \" $db_password\necho \"Mysql root password: \" $mysqlrootpass\n\n<\/textarea><\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_4 1_4 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:25%;--awb-margin-top-large:0px;--awb-spacing-right-large:7.68%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:7.68%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-title title fusion-title-1 fusion-title-text fusion-title-size-one\"><div class=\"title-sep-container title-sep-container-left fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><span class=\"awb-title-spacer fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><\/span><h1 class=\"fusion-title-heading title-heading-left fusion-responsive-typography-calculated\" style=\"margin:0;--fontSize:24;line-height:1.2;\">Github<\/h1><span class=\"awb-title-spacer\"><\/span><div class=\"title-sep-container title-sep-container-right\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><\/div><div class=\"fusion-text fusion-text-2\" style=\"--awb-text-transform:none;\"><p><a href=\"https:\/\/github.com\/ionoslabs\/wp-install\">https:\/\/github.com\/ionoslabs\/wp-install<\/a><\/p>\n<\/div><div class=\"fusion-title title fusion-title-2 fusion-title-text fusion-title-size-one\"><div class=\"title-sep-container title-sep-container-left fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><span class=\"awb-title-spacer fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><\/span><h1 class=\"fusion-title-heading title-heading-left fusion-responsive-typography-calculated\" style=\"margin:0;--fontSize:24;line-height:1.2;\">Download<\/h1><span class=\"awb-title-spacer\"><\/span><div class=\"title-sep-container title-sep-container-right\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-2 > .CodeMirror, .fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-2 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_2\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_2\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_2\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">git clone https:\/\/github.com\/ionos-seth\/wp-install<\/textarea><\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1371,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[391,691],"tags":[],"class_list":["post-1499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resources","category-wordpress"],"_links":{"self":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/1499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/comments?post=1499"}],"version-history":[{"count":3,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/1499\/revisions"}],"predecessor-version":[{"id":2495,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/1499\/revisions\/2495"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/media\/1371"}],"wp:attachment":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/media?parent=1499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/categories?post=1499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/tags?post=1499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}