Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save limafm/32f52c2fd546d57895db8c3c647da5c6 to your computer and use it in GitHub Desktop.
Save limafm/32f52c2fd546d57895db8c3c647da5c6 to your computer and use it in GitHub Desktop.
Script to configurate a fake ssl virtual host, using Apache Server, on Linux.
#!/bin/bash
##################################################################################################
## ##
## Credits: ##
## - http://www.phpit.com.br/artigos/configurando-ssl-servidor-de-desenvolvimento-apache.phpit ##
## - http://wime.com.br/2013/06/28/como-criar-certificado-ssl-no-apache-para-ubuntu-12-04/ ##
## ##
##################################################################################################
echo ''
printf 'input the domain (eg.: www.anything.com): '
read DOMAIN
printf 'input the project path (eg.: /var/www/path_to_your_project): '
read PROJECT_PATH
# install openssl
printf "\n>> instalando comando 'openssl'..."
sudo apt-get install openssl -y>/dev/null
printf "\n>> criando chaves privadas...\n"
cd ~/
openssl genrsa -out $DOMAIN.key 1024 >/dev/null
printf "\n>> configurando informações da empresa para o certificado...\n"
openssl req -new -key $DOMAIN.key -x509 -out $DOMAIN.crt
## Country Name (2 letter code) [AU]:BR
## State or Province Name (full name) [Some-State]:Sao Paulo
## Locality Name (eg, city) []:SP
## Organization Name (eg, company) [Internet Widgits Pty Ltd]:Minha Empresa LTDA
## Organizational Unit Name (eg, section) []:Solução em Contabilidade
## Common Name (e.g. server FQDN or YOUR name) []:dominio.com.br
## Email Address []:suporte@dominio.com.br
printf "\n>> movendo chaves para o diretório do apache..."
sudo mkdir -p /etc/apache2/ssl/
sudo mv $DOMAIN.key $DOMAIN.crt /etc/apache2/ssl/
printf "\n>> criando certificado '.pem'..."
cd /etc/apache2/ssl/
sudo cp $DOMAIN.crt $DOMAIN.pem
printf "\n>> configurando virtual host..."
cd ~/
sudo echo '<VirtualHost *:80>
ServerAdmin devel@neemu.com
ServerName '$DOMAIN'
DocumentRoot '$PROJECT_PATH'
<Directory '$PROJECT_PATH'>
IndexOptions Charset=UTF-8
AddDefaultCharset utf-8
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-'$DOMAIN'.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access-'$DOMAIN'.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin devel@neemu.com
ServerName '$DOMAIN'
DocumentRoot '$PROJECT_PATH'
<Directory '$PROJECT_PATH'>
IndexOptions Charset=UTF-8
AddDefaultCharset utf-8
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/'$DOMAIN'.pem
SSLCertificateKeyFile /etc/apache2/ssl/'$DOMAIN'.key
ErrorLog ${APACHE_LOG_DIR}/error-'$DOMAIN'.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access-'$DOMAIN'.log combined
</VirtualHost>
' > $DOMAIN.conf
sudo mv $DOMAIN.conf /etc/apache2/sites-enabled/
# enable ssl module on apache
printf "\n>> habilitando módulo 'ssl' do apache..."
sudo a2enmod ssl>/dev/null
printf "\n>> reiniciando o apache..."
sudo service apache2 restart &>/dev/null
printf "\n\n!!! SSL SERVER CONFIGURATED !!!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment