Skip to content

Instantly share code, notes, and snippets.

@AJNOURI
Last active August 27, 2018 13:53
Show Gist options
  • Save AJNOURI/466df73120a105a34863 to your computer and use it in GitHub Desktop.
Save AJNOURI/466df73120a105a34863 to your computer and use it in GitHub Desktop.
Install Apache2 and create self-signed ssl certificate on Ubuntu 14.04
#!/bin/bash
commonname=apachehttps.lab
country=FR
state=IDF
locality=Panam
organization=cciethebeginning.wordpress.com
organizationalunit=IT
email=ajn.bin@gmail.com
echo "########### Installing apache, php5 and openssl packages..."
apt-get update && apt-get install -y apache2 apache2-doc apache2-utils openssl php5 libapache2-mod-php5
mkdir /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.cert -subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email"
echo "########### Enable apache ssl module..."
a2enmod ssl
echo "########### Configuring vhost to listen to ssh..."
sed -i 's|/etc/ssl/certs/ssl-cert-snakeoil.pem|/etc/apache2/ssl/apache.cert|' /etc/apache2/sites-available/default-ssl.conf
sed -i 's|/etc/ssl/private/ssl-cert-snakeoil.key|/etc/apache2/ssl/apache.key|' /etc/apache2/sites-available/default-ssl.conf
echo "########### Loading new ssl conf..."
a2ensite default-ssl.conf
echo "########### Restarting Apache..."
service apache2 start
sed -i .bak "'SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem'/'SSLCertificateFile /etc/apache2/ssl/apache.cert'/g" /etc/apache2/sites-available/default-ssl.conf
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
cd /var/www/html
cat > test.php << EOF
<?php
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nClient IP: ".$_SERVER['REMOTE_ADDR'];
echo "\nIP used by client = ".$_SERVER['HTTP_HOST'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];
echo "\nDNS name used by client = ".$_SERVER['SERVER_NAME'];
?>
EOF
cat test.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment