Same Rightscript used multiple times on a ServerTemplate with different inputs - bash

I have just created my first Rightscale ServerTemplate and Deployment using a bunch of Rightscripts. One of the scripts I created was to add a virtual host to apache.
#!/bin/bash -e
if [ $RS_DISTRO = ubuntu ]; then
export apache=apache2
export apache_extra_conf_dir=/etc/apache2/conf.d
elif [ $RS_DISTRO = centos ]; then
export apache=httpd
export apache_extra_conf_dir=/etc/httpd/conf.d
fi
server_name=$SERVER_NAME
echo "Adding virtual hosts to ${apache_extra_conf_dir}/vh-${server_name}.conf"
cat > $apache_extra_conf_dir/vh-${server_name}.conf <<EOF
NameVirtualHost $SITE_IP:$SITE_PORT
<VirtualHost $SITE_IP:$SITE_PORT>
ServerName $SERVER_NAME
ServerAlias $SITE_DOMAIN *.$SITE_DOMAIN
UseCanonicalName Off
ServerAdmin $ADMIN_EMAIL
DocumentRoot $APACHE_WWW_DIR
<Directory "$APACHE_WWW_DIR">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EOF
service $apache restart
exit 0
My question is can I use the same Rightscript twice on the ServerTemplate but set different inputs for each (IP, Port, www dir and Servername)? eg.
ServerTemplate:
Execute Rightscript vhost: *:80 /www-x/ x.com
Execute Rightscript vhost: *:80 /www-y/ y.com
OR do I have to create a special Rightscript just for this server deployment that has both virtual hosts defined in the same script?
Execute Rightscript vhost: *:80 /www-x/ x.com | *:80 /www-y/ y.com

You can use the same RightScript with different inputs only if you put that script in the "Operational Scripts" section of your ServerTemplate. Then if you leave the inputs blank, you can execute that operational script with different inputs many times.
If you want that behavior in the "Boot Scripts" section, you'll have to either create a single script which handles two sets of inputs (for two vhosts) or create a clone of the RightScript with a different name and different input names.
You might consider taking a look at the Chef based tools. You can create a Chef recipe which takes an array of vhost names as input, then executes the "apache_site" resource that sets up a vhost. You can see an example in the RightScale Chef code linked below.
https://github.com/rightscale/cookbooks_public/blob/master/cookbooks/web_apache/recipes/setup_frontend_http_vhost.rb

Related

Up laravel project and get (The requested URL /icons/create was not found on this server.) but route exist and any route works perfectly

Running a project in dev server run perfectly but I try to move on a live server, I got "The requested URL /icons/create was not found on this server."
i got that just in 1 route in : .../icon/create
but any route works fine.
this is my htaccess :
I try to composer dump-autoload in local but don't get any error"
or something problem in my htaccess file?
mod_rewrite already enable in the apache web server.
Very thank you, if someone wants to help me :)
as u r saying u have "mod_rewrite already enable"
try this editing /etc/apache2/sites-enabled/000-default or /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Change the AllowOverride None to AllowOverride All
Comment Alias in /etc/apache2/mods-available/alias.conf.
<IfModule alias_module>
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If
# you do not use FancyIndexing, you may comment this out.
# Alias /icons/ "/usr/share/apache2/icons/"
# <Directory "/usr/share/apache2/icons">
# Options FollowSymlinks
# AllowOverride None
# Require all granted
# </Directory>
</IfModule>
After Comment these lines check apache conf using this command:
sudo apache2ctl -t
Then reload apache2:
sudo systemctl reload apache2

Bash: Variable Isn't Used / Defined Properly

working on my auto-install script. It isn't using my variable properly, debug log looks like this.
I've tried several variants, using "" instead of '', not using '' or "" but just $variable. The script looks like this:
echo "Creating Apache2 VHost and Wordpress blog $domain"
VAR1=$sitealias
VAR2=$domain
MOREF=$`pwgen 14 1`
echo $MOREF is SQL password.
mkdir /var/www/"$domain"
chown -R www-data:www-data /var/www/"$domain"
echo "<VirtualHost *:80>
ServerName myblog.example.com
ServerAdmin webmaster#example.com
DocumentRoot /usr/share/wordpress
Alias /wp-content /var/lib/wordpress/wp-content
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/lib/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" > /etc/apache2/sites-available/$domain.conf
mysqladmin -u root password supersecretpassword create wp_$sitealias
mysqladmin -u root password supersecretpassword CREATE USER $sitealias#'localhost' IDENTIFIED BY '$MOREF';
mysqladmin -u root password supersecretpassword GRANT ALL PRIVILEGES ON wp_'$sitealias.'* TO '$sitealias'#localhost;
FLUSH PRIVILEGES;
quit
The script should insert the variable in the commands, folder directories. Instead the variable is just ignored, as is shown in the debug log.
UPDATE:
variable capturing works fine now. However, SQL doesn't like your double quote (copy and pasted them)
root#hosting:/bin# hello.sh letstest.tld testtesttdjsuqwu
Creating Apache2 VHost and Wordpress blog
qui2AenaihoQu9 is SQL password.
mysqladmin: Unknown command: 'create wp_testtesttdjsuqwu'
mysqladmin: Unknown command: 'CREATE USER 'testtesttdjsuqwu'#'localhost' IDENTIFIED BY 'q'
mysqladmin: Unknown command: 'GRANT ALL PRIVILEGES ON wp_testtesttdjsuqwu.* TO 'testtesttd'
/bin/hello.sh: line 37: FLUSH: command not found
/bin/hello.sh: line 38: quit: command not found
If you want to use parameters inside your script (based on the comments above, 'domain' and 'sitealias') use the '$1' '$2' to capture them
domain=$1
sitealias=$2
# Fixed quoting of pwgen)
MOREF=$(pwgen 14 1)
# Rest of the script here, using $domain, $sitealias
echo $MOREF is SQL password.
mkdir /var/www/"$domain"
It's not completely clear what value do you want to 'APACHE_LOG_DIR'. Assuming that this variable need to be resolved at run-time, based on the Apache default value, you want to use single quote instead of double quote for the 'echo' statement. This will defer the resolution of this variable.
echo '<VirtualHost *:80>
ServerName myblog.example.com
ServerAdmin webmaster#example.com
DocumentRoot /usr/share/wordpress
# Lines removed for
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
' > /etc/apache2/sites-available/$domain.conf
Also, consider double-quoting for the mysqladmin setup command. Use double quote to enable variable substitution, Use single quote when needed by mysql.
mysqladmin -u root password supersecretpassword "create wp_$sitealias"
mysqladmin -u root password supersecretpassword "CREATE USER '$sitealias'#'localhost' IDENTIFIED BY '$MOREF'";
mysqladmin -u root password supersecretpassword "GRANT ALL PRIVILEGES ON wp_$sitealias.* TO '$sitealias'#'localhost';"
FLUSH PRIVILEGES;
quit

Bash echo multi line to end of file but dont echo in terminal

I'm writing a custom alias function to create my vhosts for me whenever i'm creating a new web project. In my function, I want to paste an entire new virtual host into my httpd-vhosts.conf file. I'm first asking for an input for the domain name and folder name to create like this
read -p 'Please enter the domain for your new site: ' domain;
read -p 'Please enter the folder name for your new site: ' folder;
and then in my function, i'm writing to my httpd-vhosts.conf file like this
echo "
<VirtualHost *:80>
ServerAdmin $domain
DocumentRoot \"/Users/sam/Development/Websites/$folder\"
ServerName $domain
ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\"
CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common
</VirtualHost>" | sudo tee -a /usr/local/etc/httpd/extra/httpd-vhosts.conf;
But i've noticed this echo's in the terminal as well as in the conf file. The function works perfectly, but how do I get it to NOT echo in the terminal?
Do I have to use something other than echo to append to the file to achieve this?
Just redirect to /dev/null:
echo "
<VirtualHost *:80>
ServerAdmin $domain
DocumentRoot \"/Users/sam/Development/Websites/$folder\"
ServerName $domain
ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\"
CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common
</VirtualHost>" | sudo tee -a /usr/local/etc/httpd/extra/httpd-vhosts.conf > /dev/null
This allows you to append with sudo privileges while also not showing the output on screen.
instead of tee you may consider to use >>
sudo sh -c "echo \"
<VirtualHost *:80>
ServerAdmin $domain
DocumentRoot \"/Users/sam/Development/Websites/$folder\"
ServerName $domain
ErrorLog \"/usr/local/var/log/httpd/$folder/error_log\"
CustomLog \"/usr/local/var/log/httpd/$folder/access_log\" common
</VirtualHost>\" >> test2.out"

xampp laravel blank page when using vhost windows

Trying to use xampp for my virtual host on Windows 10.
But when I open up my project in browser it's a blank page. Not an error message, just blank.
Can anyone help?
Here's my VHosts
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host2.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
##ServerName dummy-host2.example.com
##ErrorLog "logs/dummy-host2.example.com-error.log"
##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>
<VirtualHost *:3000>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:3000>
DocumentRoot "C:/xampp/htdocs/projectlara2/public/"
ServerName projectlara2.test
</VirtualHost>
HERE'S MY Hosts File
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1:3000 localhost
# ::1 localhost
127.0.0.1 localhost projectlara2.test
::1 localhost projectlara2.test
Not quite sure what else I'm supposed to write here. It says I have a post that's mostly code so I should add more details but there aren't any more details. Hopefully this is enough extra writing because this is a bit annoying.
You have not provided the virtual host properly in your windows host file. You need to just change a little in host file and probably it will solve your error.
change your entry of virtual host in host file from 127.0.0.1 localhost projectlara2.test to 127.0.0.1 projectlara2.test and ::1 localhost projectlara2.test to ::1 projectlara2.test.
The problem is although you are using virtual host for the project you are declaring localhost with it. Just write the ip and domain name of virtual host, nothing else.
On your Windows10 hosts file use this only:
127.0.0.1 localhost wiki.com projectlara2.test
Then in your vhosts file you can do this:
<VirtualHost projectlara2.test:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/projectlara2/public/"
ServerName projectlara2.test
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
ServerAdmin, ErrorLog, CustomLog are optional and you can set them up with a real path if you want to, you aren't specifing the server name on your first line on your VirtualHost, when you specify it like this *: you are saying that all requests should point to the VirtualHost you are about to define, so if you want more than 1 VirtualHost you should be more specific like I showed. Hope it works! :D

Multiple Ruby apps on one port, RackBaseURI help

I'm trying to get two Ruby apps to work from the same port. I don't know server technology at all, so forgive my ignorance. I've tried to follow this doc:
http://www.modrails.com/documentation/Users%20guide%20Apache.html
sections 4.1 - 4.3, but I keep messing something up. I've tried to simplify a little, so here is my situation. I have two simple rackup apps here:
/Users/dan/webapps/test1
/Users/dan/webapps/test2
They each have the "config.ru" file, the public/ folder, and the tmp/ folder with "restart.txt", as directed. They both work on their own.
I have the following in my httpd.conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/dan/webapps
<Directory /Users/dan/webapps>
Allow from all
</Directory>
RackBaseURI /test1
<Directory /Users/dan/webapps/test1>
Options -MultiViews
</Directory>
RackBaseURI /test2
<Directory /Users/dan/webapps/test2>
Options -MultiViews
</Directory>
</VirtualHost>
I start apache, and then put this in my browser: http://localhost/test1. I get:
Forbidden
You don't have permission to access /test1 on this server.
I'm not surprised it doesn't work, because I am supposed to set up a symlink but I don't know how to apply that to my setup. Here is the example from the doc:
ln -s /webapps/rackapp/public /websites/phusion/rack
Can you tell me how to set up the symlinks, and let me know if you see anything else wrong? Please give the "for dummies" answer, this stuff boggles my mind. Thanks!
To create the symlinks, try this:
ln-s /Users/dan/webapps/test1 /Users/dan/webapps/test1/public
ln-s /Users/dan/webapps/test2 /Users/dan/webapps/test2/public
However, as chris polzer mentioned, you should also check that your apache user can read from those directories.
If you don't know how to do that, then post the output of these commands:
ls -l /Users/dan/webapps/test1
ls -l /Users/dan/webapps/test2.
ps -aux | grep http
ps -aux | grep apache
You may also need to check the permissions of all parent directories. I.e. /Users, /Users/dan, and /Users/dan/webapps. See: http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_to_a_virtual_host_8217_s_root_2
phylae, I think you may have the paths reversed in the symbolic link. To get it working, I changed the link names for clarity:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/dan/webapps
<Directory /Users/dan/webapps>
Allow from all
</Directory>
RackBaseURI /test1link
<Directory /Users/dan/webapps/test1>
Options -MultiViews
</Directory>
RackBaseURI /test2link
<Directory /Users/dan/webapps/test2>
Options -MultiViews
</Directory>
</VirtualHost>
and then, the symbolic links:
ln -s /Users/dan/webapps/test1/public /Users/dan/webapps/test1link
ln -s /Users/dan/webapps/test2/public /Users/dan/webapps/test2link
Then these urls work as expected in a browser.
http://localhost/
http://localhost/test1link
http://localhost/test2link

Resources