{"id":119622,"date":"2018-04-06T12:03:47","date_gmt":"2018-04-06T12:03:47","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=119622"},"modified":"2018-05-04T07:51:40","modified_gmt":"2018-05-04T07:51:40","slug":"write-your-own-shell-bash-script-to-install-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/","title":{"rendered":"Shell\/Bash Script to Install Magento 2"},"content":{"rendered":"<div>\n<p>It is easy to customize things according to your need. So if you are still installing the Magento by typing commands on your terminal it&#8217;s time to quit this process.<br \/>\nYou can write your own shell script which will allow you to install your Magento just by running a single command on your terminal.<\/p>\n<p>Using this script you can create your Database, install your Magento with sample data. The only thing is required you must have a Magento Store account to download the files from Magento using composer.<\/p>\n<p>Steps are as follows-<br \/>\n1) Write a script<br \/>\n2) The next thing we have to do is give the shell permission to execute your script. This is done with the chmod command as follows: <strong>chmod 755 scriptName.sh<\/strong><br \/>\n3) Now you need to run your script using the command- <strong>.\/scriptName.sh<\/strong><\/p>\n<p>Please find the script below-<\/p>\n<\/div>\n<div>\n<pre class=\"brush:shell\">#!\/bin\/bash\r\n# color coding.\r\nred=`tput setaf 1`\r\ngreen=`tput setaf 2`\r\nyellow=`tput setaf 3`\r\ncyan=`tput setaf 6`\r\nreset=`tput sgr0`\r\nbg=`tput setab 7`\r\n\r\n# All Required Variables\r\ndb_user=root\r\ndb_password=webkul\r\nemail=john@doe.com\r\n\r\n#Creating Database\r\necho \"Creating Database...........\"\r\necho \"${cyan}Enter Your DataBase name I'll create your DB${reset}\"\r\nread db_name\r\n\r\n# DB existance check\r\ndb_exists=$(mysql -u $db_user -p$db_password -e \"SHOW DATABASES LIKE '\"$db_name\"';\" | grep \"$db_name\" &gt; \/dev\/null; echo \"$?\")\r\nif [ $db_exists -eq 0 ];then\r\n    echo \"${red}${bg}A database with the name $db_name already exists${reset}\"\r\n    exit\r\nelse\r\n     echo \"${yellow}Creating database $db_name.${reset}\"\r\nfi\r\n\r\nmysql -u $db_user -p$db_password -e \"create database $db_name;\"\r\necho \"${green} Database $db_name created${reset}\"\r\nsleep 1\r\n\r\n#Install Magento\r\necho \"${yellow}Installing Magento...........${reset}\"\r\ncomposer create-project --repository-url=https:\/\/repo.magento.com\/ magento\/project-community-edition\r\nsleep 1\r\n\r\n#Rename donloaded folder name (change required)\r\necho \"${cyan}Enter your magento name${reset}\"\r\nread magento_directory\r\necho \"${yellow}Magento name is $magento_directory ${reset}\"\r\nmv project-community-edition $magento_directory\r\n\r\n#Go inside your folder (change required)\r\ncd $magento_directory\r\n\r\n#Give permissions\r\necho \"${yellow}Giving permissions........${reset}\"\r\nfind . -type f -exec chmod 644 {} \\;\r\nfind . -type d -exec chmod 755 {} \\;\r\n\r\n#Install Magento\r\necho \"${yellow}Installing Magento........${reset}\"\r\nphp bin\/magento setup:install --base-url=http:\/\/localhost\/$magento_directory\/ --db-host=localhost --db-name=$db_name --db-user=$db_user --db-password=$db_password --admin-firstname=admin --admin-lastname=admin --admin-email=$email --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America\/Chicago --use-rewrites=1\r\n\r\n#Installing sample data\r\necho \"${yellow}Installing sample data and updating magento.......${reset}\"\r\nphp bin\/magento sampledata:deploy; php bin\/magento setup:upgrade; php bin\/magento setup:di:compile; php bin\/magento setup:static-content:deploy; php bin\/magento cache:clean; php bin\/magento indexer:reindex; php bin\/magento cache:flush\r\n\r\n# User input to edit backend URL\r\necho \"${cyan}Do you want to edit your backend url? yes\/no${reset}\"\r\nread backend_url\r\nif [ \"$backend_url\" = yes -o y -o Yes -o Y ]; then\r\n    admin_url=$(grep -E \"admin_+\" app\/etc\/env.php)\r\n    sed -i \"s\/$admin_url\/'frontName' =&gt; 'admin',\/g\" app\/etc\/env.php\r\n    echo \"${green}Backend url has been set. Your Magento is ready to use now...) ${reset}\"\r\nelse\r\n    echo \"${green}Your Magento is ready to use now...) ${reset}\"\r\nfi<\/pre>\n<\/div>\n<p>Please update some values in the script before running it. Like- I have set dummy DB username (db_user) and DB password (db_password). Some Magento related data are already set like &#8211; base URL, Db host, admin first name, last name,\u00a0 email id, password etc which are required for the Magento\u00a0installation.<\/p>\n<p>You can add validations to your script and do required changes according to your need. Hope it will help you.<\/p>\n<p>Thank You! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is easy to customize things according to your need. So if you are still installing the Magento by typing commands on your terminal it&#8217;s time to quit this process. You can write your own shell script which will allow you to install your Magento just by running a single command on your terminal. Using <a href=\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":66,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[6484,6462,2997,2717,2460,2070,6483],"class_list":["post-119622","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-automate","tag-bash","tag-install","tag-installation","tag-magento-2","tag-magento2","tag-shell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Shell\/Bash Script to Install Magento 2 - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Shell\/Bash Script to Install Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"It is easy to customize things according to your need. So if you are still installing the Magento by typing commands on your terminal it&#8217;s time to quit this process. You can write your own shell script which will allow you to install your Magento just by running a single command on your terminal. Using [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-06T12:03:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-04T07:51:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shruti Baranwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shruti Baranwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\"},\"author\":{\"name\":\"Shruti Baranwal\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e\"},\"headline\":\"Shell\/Bash Script to Install Magento 2\",\"datePublished\":\"2018-04-06T12:03:47+00:00\",\"dateModified\":\"2018-05-04T07:51:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\"},\"wordCount\":221,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"automate\",\"bash\",\"install\",\"installation\",\"Magento 2\",\"Magento2\",\"shell\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\",\"name\":\"Shell\/Bash Script to Install Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2018-04-06T12:03:47+00:00\",\"dateModified\":\"2018-05-04T07:51:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell\/Bash Script to Install Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e\",\"name\":\"Shruti Baranwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Shruti Baranwal\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/shruti-baranwal890\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Shell\/Bash Script to Install Magento 2 - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Shell\/Bash Script to Install Magento 2 - Webkul Blog","og_description":"It is easy to customize things according to your need. So if you are still installing the Magento by typing commands on your terminal it&#8217;s time to quit this process. You can write your own shell script which will allow you to install your Magento just by running a single command on your terminal. Using [...]","og_url":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-04-06T12:03:47+00:00","article_modified_time":"2018-05-04T07:51:40+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Shruti Baranwal","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Shruti Baranwal","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/"},"author":{"name":"Shruti Baranwal","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e"},"headline":"Shell\/Bash Script to Install Magento 2","datePublished":"2018-04-06T12:03:47+00:00","dateModified":"2018-05-04T07:51:40+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/"},"wordCount":221,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["automate","bash","install","installation","Magento 2","Magento2","shell"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/","url":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/","name":"Shell\/Bash Script to Install Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2018-04-06T12:03:47+00:00","dateModified":"2018-05-04T07:51:40+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/write-your-own-shell-bash-script-to-install-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Shell\/Bash Script to Install Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e","name":"Shruti Baranwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Shruti Baranwal"},"url":"https:\/\/webkul.com\/blog\/author\/shruti-baranwal890\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/119622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=119622"}],"version-history":[{"count":29,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/119622\/revisions"}],"predecessor-version":[{"id":124011,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/119622\/revisions\/124011"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=119622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=119622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=119622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}