Jump to content

Script to create new PW in bitnami stack


Manol
 Share

Recommended Posts

This a script  I use to install new sites (mainly pw) in an amazon EC2 with bitnami stack (ubuntu 14.04). Maybe it can be useful for somebody else.

To access your bitnami terminal you have to install a .pem or .ppk key on your home folder then 

ssh -i ~/.ssh/bitnami-hosting.pem bitnami@yourbitnami.bitnamiapp.com 

now we're connected through ssh. 

cd /home/bitnami

# Create a file called createWeb.sh

sudo nano createWeb.sh  // paste the long script at the bottom
sudo chmod +x createWeb.sh
sudo ./createWeb.sh yourwebsitename   //note down the random BD password
cd ./apps/yourwebsitename/htdocs

# download and unzip pw

wget https://github.com/ryancramerdesign/ProcessWire/archive/master.zip
unzip master.zip
sudo cp -R ./ProcessWire-master/* .

# change permissions to install

chmod 777 -R ./site/assets ./site/modules
chmod 777 ./site/config.php
mv htaccess.txt .htaccess

# change permissions after install

chmod 644  ./site/config.php
sudo find . -type d -exec chmod 775 {} \;
sudo find . -type f -exec chmod 664 {} \;
sudo chown -R bitnami:daemon ./*

# enter your .htaccess and around line 117 make sure the line looks like

RewriteBase /
RewriteBase /yourwebsitename/

Open your url and ready to install a fresh pw.

Note that in the script you have to substitute PASSWORD by your actual mysql pass in the following  line:

mysql -u root -pPASSWORD << EOF

#!/bin/bash

# creaweb miweb miweb.zip


# 1.- Crea estructura de directorios
sudo -u $USER mkdir -p /opt/bitnami/apps/$1/htdocs /opt/bitnami/apps/$1/conf

# 2.- Permisos archivos y directorios para el usuario bitnami
sudo -u $USER chown -R bitnami /opt/bitnami/apps/$1

# 3.- descomprimir zip de la app, sino exite crea un phpinfo como 
if [ -n "$2" ]
then
    unzip ./$2 /opt/bitnami/apps/$1/htdocs/
else
	sudo -u $USER echo '<?php phpinfo(); ?>' > /opt/bitnami/apps/$1/htdocs/index.php	
fi



# 4.- Crea configuración para acceder a la web http://mibitnami.com/miweb
sudo -u $USER cat > /opt/bitnami/apps/$1/conf/$1.conf <<EOL
Alias /$1/ "/opt/bitnami/apps/$1/htdocs/"
Alias /$1 "/opt/bitnami/apps/$1/htdocs"
<Directory "/opt/bitnami/apps/$1/htdocs">
    Options Indexes MultiViews
    AllowOverride All
    <IfVersion < 2.3 >
    Order allow,deny
    Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
    Require all granted
    </IfVersion>
</Directory>
EOL

# 5.- Añadir en la útima linea  de la configuración de apache la nueva entrada
echo Include "/opt/bitnami/apps/$1/conf/$1.conf" >> /opt/bitnami/apache2/conf/httpd.conf

# 6.- Reinicializar servicio apache
/opt/bitnami/ctlscript.sh restart apache

# 7.- lista webs disponibles
ls -ls /opt/bitnami/apps

# 8.- Crear Base de datos
echo "creando BD"
pass=`tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 | xargs`
echo $pass

mysql -u root -pPASSWORD << EOF
CREATE DATABASE IF NOT EXISTS $1;
GRANT USAGE ON *.* TO $1@localhost IDENTIFIED BY '$pass';
GRANT ALL PRIVILEGES ON $1.* TO $1@localhost;
FLUSH PRIVILEGES;
EOF

  • Like 1
Link to comment
Share on other sites

Wow o_O impressed.

This is probably a bad question but, does that mean you run PW sites, their files and MySQL, from Amazon resources (so effectively Amazon is the hosting Co.)?

Link to comment
Share on other sites

Hi Alan, yes I run it in aws EC2 but bitnami allows you to install it on GCE ( google ) amazon, azure and locally, as you know it would work on any linux server, actually I'm using ubuntu 14.04. 

Link to comment
Share on other sites

That's cool Manol.

I need to go do some Googling.

Does this keep hosting costs low compared to a traditional VPS running Centos w/ Mysql etc if you don't mind me asking?

Any compromises, perhaps a lack of SSH access? Or lack of WHM/cPanel to help non-admins like me easily install SSL certificates etc?

Sorry to bombard you with Q's—intrigued by the thought of possibly cloud hosting.

Link to comment
Share on other sites

Thanks Manol. I know lots of bits of sysadmin type stuff that would get me some way to being able to do that, just not enough (yet) to actually dive in and try it. But very interesting to know (that you ssh in and set it all up from there). One day if I pluck up the courage I might try..!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...