Microsoft Azure and Laravel 5.1 from Scratch

While most people use AWS, I like to use Azure and there’s just not a lot of information relating Azure and Laravel, so figured this might be useful for others. This assumes a level of comfort with Linux and Azure.

  • Login: https://portal.azure.com/#
  • Click on Virtual machines (classic) and search for Ubuntu. My preference has always been Ubuntu server 14.04 LTS, select this.
  • Select deployment model: Resource Manager and click Create.
  • Give your VM some basic information: Name, User name, Authentication Type (SSH public key is my preference). Create a new resource group, I always use the same name as the VM and Location. I usually do the A1 Standard size.
  • Click ok to choose the defauls under Settings.
  • Click OK on summary and your VM will start deploying, this will take about 10-15 minutes to complete.
  • Once running, click the VM, Public Ip address/DNS name label, All Settings, Configuration, and give it a DNS name. I do this to not have to deal with IP addresses and use actual names.

At this point, I created a CustomScript Extension using this https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-script-lamp/ and http://tutsnare.com/how-to-install-laravel-on-ubuntu-lamp/ and http://tecadmin.net/install-laravel-framework-on-ubuntu/ This will install everything you need. The script is below. To run the script through the CLI you need to use this command: azure vm extension set -c "./public_config.json" <yourresourcegroup> <yourvm> CustomScriptForLinux Microsoft.OSTCExtensions 1.4
If you want to run the script manually, just SSH into your VM and go through every step below starting at "sudo apt-get -y".

  • SSH into your machine.
  • Instal composer: curl -sS https://getcomposer.org/installer | php
  • Move composer globally: sudo mv composer.phar /usr/local/bin/composer
  • Install Laravel: sudo composer create-project laravel/laravel /var/www/laravel 5.1.*
    • sudo mkdir laravel/app/storage
    • sudo chown -R www-data.www-data /var/www/laravel
    • sudo chmod -R 755 /var/www/laravel
    • sudo chmod -R 777 /var/www/laravel/app/storage
  • Create VirtualHost and use sample below: vim /etc/apache2/sites-available/yourhost.com.conf
  • Enable your site config: sudo a2ensite yourhost.com
  • Reload Apache: sudo service apache2 reload
  • Disable default site: sudo a2dissite 0000-default
  • Reload Apache: sudo service apache2 reload
  • Open VM firewall: sudo iptables -A INPUT -p tcp –dport 80 -j ACCEPT
  • Restart VM: sudo shutdown -r now
  • In Azure Portal Network Security Group find "inbound security rules" and add a rule for port 80.
  • Go to your http://yourhost.com Welcome!

Azure LAMP install script:
#!/bin/bash
# set up a silent install of MySQL
dbpass="YourPasswordHere"

export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.6 mysql-server/root_password password $dbpass | debconf-set-selections
echo mysql-server-5.6 mysql-server/root_password_again password $dbpass | debconf-set-selections

# install the LAMP stack
sudo apt-get -y install apache2 mysql-server php5 php5-mysql php5-curl

#install extensions
#installing json extension
sudo apt-get install php5-json
#installing unzip extension
sudo apt-get install unzip
#installing curl extension
sudo apt-get install curl
#installing openssl extension
sudo apt-get install openssl
#installing mcrypt extension
sudo apt-get install php5-mcrypt
#enable mcrypt extension
sudo php5enmod mcrypt
#installing git
sudo apt-get install -y git-core
#enable mod rewrite extension
sudo a2enmod rewrite

# write some PHP
echo \<center\>\<h1\>My Demo App\</h1\>\<br/\>\</center\> > /var/www/html/phpinfo.php
echo \<\?php phpinfo\(\)\; \?\> >> /var/www/html/phpinfo.php

# restart Apache
sudo apachectl restart

Yourhost.com.conf:
<VirtualHost *:80>
       
        ServerName laravel.example.com
        DocumentRoot /var/www/laravel/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

For posterity.

This is case sensative.
public_config.json:{"fileUris":["/scripts/Laravel.sh"]’>/scripts/Laravel.sh"]’>/scripts/Laravel.sh"]’>https://<yourstorage>/scripts/Laravel.sh"], "commandToExecute":"sh Laravel.sh" }