Skip to content

Instantly share code, notes, and snippets.

@electricg
Last active October 7, 2015 15:38
Show Gist options
  • Save electricg/3187449 to your computer and use it in GitHub Desktop.
Save electricg/3187449 to your computer and use it in GitHub Desktop.
Virtul machine Apache server

Virtul machine Apache server

Since so far all my jobs have required me (read: they assigned me) Windows machines, I find more comfortable working with Ubuntu that makes setting up/installing/using various software far more easily.

I use Oracle VM VirtualBox which is free and fairly easy to use (don't forget to install the Extension Pack) and Ubuntu.

Settings for the Ubuntu VM:

  • System
    • Motherboard
      • Boot order:
        1. CD/DVD-ROM
        2. Hard Disk
        3. Floppy (disabled)
      • Base Memory: something more than 1024MB, depending on your machine (with a Windows7 host with 4GB, I set it to the end of the green bar - 1654MB)
  • Network
    • Adapter 1: NAT; Port Forwarding:
      • name - protocol - host ip - host port - guest ip - guest port
      • name - tcp - 127.0.0.2 - 80 - 10.0.2.15 - 80
      • name - tcp - 127.0.0.2 - 443 - 10.0.2.15 - 443
      • name - tcp - 127.0.0.2 - 1234 - 10.0.2.15 - 80 (for http in case host has already a server)
      • name - tcp - 127.0.0.2 - 1235 - 10.0.2.15 - 443 (for https in case host has already a server)
  • Shared folders
    • Folder Path: C:\giulia\www; Folder Name: giulia_www; Auto-mount; Make Permanent

To mount the shared folder on Ubuntu, create the folder giulia_www in home and run the command

sudo mount -t vboxsf -o uid=1000,gid=1000 giulia_www ~/giulia_www

where the first giulia_www refers to the folder name I gave in the VM settings, while ~/giulia_www is the path of the folder I want to mount to (giulia_ww is the folder for an eventual Ubuntu based server folder). If you want automounting, see the ubuntu_rc.local file.

The host is Windows 7. Domain name assigned: giulia and giulia.dev

The guest is Ubuntu 12.04. Domain name assigned: giulia.nix

From the host, the IP address to access the guest is 127.0.0.2, made it possible through port forwarding on VirtualBox. From the guest, the IP address to access the host is 10.0.2.2.

On both the machines Apache is installed. On Windows through xampp, on Ubuntu following this guide:

sudo apt-get install tasksel
sudo tasksel install lamp-server

If taskel returns with error tasksel aptitude failed (100) run

sudo apt-get update
sudo tasksel

On Ubuntu I've also installed SSL

    sudo apt-get install ssl-cert
    cd /etc/apache2/
    sudo mkdir ssl
    sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
    sudo a2enmod ssl
    sudo /etc/init.d/apache2 force-reload
    sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
    gksudo gedit /etc/apache2/sites-available/ssl
    sudo a2ensite ssl

Here's a quick summary:

  • install xampp on win
  • configure xampp
  • install virtualbox on win
  • install ubuntu as vm
  • configure ubuntu vm
  • install lamp on ubuntu
  • install ssl on ubuntu
  • configure apache and ssl on ubuntu
  • configure hosts file

And the configuration files

### Windows hosts file
127.0.0.1 giulia.dev
127.0.0.1 giulia
127.0.0.2 giulia.nix
### Linux hosts file
10.0.2.2 giulia.dev
10.0.2.2 giulia
127.0.0.1 giulia.nix
### /etc/apache2/sites-available/default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/giulia/giulia_www
ServerName giulia.nix
ServerAlias www.giulia.nix
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/giulia/giulia_www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/giulia/giulia_ww
ServerName localhost
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/giulia/giulia_ww/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
### /etc/rc.local
# this command is for automounting on ubuntu the windows shared folder containing the websites
sudo mount -t vboxsf -o rw,exec,uid=1000,gid=1000 giulia_www /home/giulia/giulia_www
exit 0
### /etc/apache2/sites-available/ssl
NameVirtualHost *:443
<virtualhost *:443>
ServerAdmin webmaster@localhost
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
DocumentRoot /home/giulia/giulia_www/
<directory />
Options FollowSymLinks
AllowOverride All
Allow from All
</directory>
<directory /home/giulia/giulia_www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</directory>
</virtualhost>
### C:\xampp\apache\conf\extra\httpd-vhosts.conf
# at the end of the file add
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\giulia\www"
ServerName giulia.dev
ServerAlias www.giulia.dev
<Directory "C:\giulia\www">
Order allow,deny
Allow from all
Options +Indexes
</Directory>
</VirtualHost>
### C:\xampp\apache\conf\httpd.conf
# modify these lines
Listen 8080
ServerName localhost:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment