Setting up Ubuntu VM in Azure cloud for PHP & Java development

This step by step guide will be helpful to understand how to setup LAMP with tomcat on a fresh Ubuntu Azure VM

What are we going to do?

  1. Install Apache
  2. Install PHP
  3. Open Azure firewall for port 80
  4. Configure Apache for PHP
  5. Install mysql
  6. Install phpmyadmin
  7. Install FTP Server
  8. Install JDK 8
  9. Install Tomcat 8
  10. Open Azure firewall for port 8080
  11. Deploy a war file to tomcat

All of the instructions given below assumes you have a SSH connection to your Azure VM.

02

Apache

sudo apt-get install apache2

Let’s start apache service

pandian@grassfield:~$ sudo /etc/init.d/apache2 start
* Starting web server apache2                                                   *

Is it listening to port 80?

pandian@grassfield:~$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.

Let’s open the port 80 with azure firewall.

Goto Network security groups

03

You will find you security group. If you don’t find any, add one.04

This is your essential settings. Click on Inbound security rules

05

You will find the rules created already. Here is the one created for SSH access.

06

Allowed TCP Port 80

08

Try to browse your public IP on your browser.

12

PHP

sudo apt-get install php5

Let’s test php now.

$ cd /var/www/html/

$ sudo mkdir testphp

$ sudo  chmod 777 testphp/

$ cd testphp/

$ vi index.php

09

Try to browse your url.

10

MySQL

ok

Lets install mysql and its connectors now

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Lets’s start it now.

pandian@grassfield:~$ sudo /etc/init.d/mysql start
* Starting MySQL database server mysqld                                 [ OK ]

Check the port is open

$ telnet localhost 3306
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
[
5.5.46-0ubuntu0.14.04.2

Lets install phpmyadmin now. Otherwise, I’ll feel handicapped as many other developers

sudo apt-get install phpmyadmin

Lets test if this is accessible.

11

Java SDK

We can install Open JDK, But I wanted to use the oracle jdk. Hence I downloaded and transferred the .tar.gz file using SCP.

$ wget http://xxxxxxxxxxxxxxxxxx/jdk-8u65-linux-x64.tar.gz

$ gunzip jdk-8u65-linux-x64.tar.gz

$ tar -xvf jdk-8u65-linux-x64.tar

$ jdk1.8.0_65/bin/java -version
java version “1.8.0_65”
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

Tomcat

$ wget http://www.eu.apache.org/dist/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz

$ gunzip apache-tomcat-8.0.30.tar.gz

$ tar -xvf apache-tomcat-8.0.30.tar

$ cd apache-tomcat-8.0.30/bin

$ ./catalina.sh start
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program

$ export JAVA_HOME=/home/pandian/jdk1.8.0_65

$ ./catalina.sh start              Using CATALINA_BASE:   /home/pandian/apache-tomcat-8.0.30
Using CATALINA_HOME:   /home/pandian/apache-tomcat-8.0.30
Using CATALINA_TMPDIR: /home/pandian/apache-tomcat-8.0.30/temp
Using JRE_HOME:        /home/pandian/jdk1.8.0_65
Using CLASSPATH:       /home/pandian/apache-tomcat-8.0.30/bin/bootstrap.jar:/home/pandian/apache-tomcat-8.0.30/bin/tomcat-juli.jar
Tomcat started.

Make sure tomcat is started

tail ../logs/catalina.out

09-Jan-2016 11:34:16.126 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 5799 ms

Okay! Ready!!

 

 

 

 

Fatal error: Call to undefined function session_is_registered()

I upgraded the PHP version of one of my old applications. The application was not working as expected. Here is the first error I’ve received.

Fatal error: Call to undefined function session_is_registered()

28-1406550233-alanganallur

session_is_registered() has been removed in PHP 5.5. We may need to use $_SESSION(‘username’).

I replaced the old code with the following.

if(!(isset($_SESSION(‘myusername’))))

Now it ended up with the following error! (AGAIN!)

Fatal error: Cannot use isset() on the result of a function call (you can use “null !== func()” instead)

Then I replaced it like this.

$myusername=$_SESSION(‘_user’);
if(null == $myusername)

Now,

Fatal error: Function name must be a string

And finally, this one worked.

if (!isset($_SESSION[“_user”]))

Fatal error: Call to undefined function session_register() in

This is related to my previous post about session_is_registered(). This post is about another deprecated function session_register(). Lets replace it by $_SESSION

Old format:

session_register("myusername");

New format:

$_SESSION['myusername']=$myusername;

Another Buddha!

Treasures from Asia’s Oldest Museum: Buddhist Art from the Indian Museum, Kolkata

Treasures from Asia’s Oldest Museum: Buddhist Art from the Indian Museum, Kolkata

Fatal error: Call to undefined function session_is_registered() in …

This is another nasty error when we access session attributes without proper check!

Fatal error: Call to undefined function session_is_registered() in G:\XAMPP\htdocs\market\login.php on line 2

This is a deprecated function. It will be resolved when we change to something like this.

if (!isset($_SESSION['myusername'])){

Treasures from Asia’s Oldest Museum: Buddhist Art from the Indian Museum, Kolkata

Treasures from Asia’s Oldest Museum: Buddhist Art from the Indian Museum, Kolkata

New Project: Infrastructure Management

This is a new project built for Virtual Infrastructure Lease Management.

The users are requesting new VMs to the Network infrastructure team. Network Team creates a new VM or assign an existing VM to the request. This project will automate it.

These are the following modules available in this release.

  1. User Management
  2. Hypervisor Managment
  3. Virtual Machines Management
  4. Applications and VM mapping
  5. Lease Management

Demo website is available at http://manageinfra.grassfield.org

Image

Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?

IMAG0659

When I try to connect to a website with SSL, I got this problem

Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?

This is the method I call in my code.

$httpsfile = file_get_contents("https://customer.ccccc.com/");
I had to add the following line to my php.ini file located in xammp/php/php.ini.

extension=php_openssl.dll

Apache VirtualHosts – HowTo

IMAG0652

I used to do this whenever I make a new PHP project. But I forget the steps often. This post will explain you how to add a new virtual host in apache.

1. Apache server installed (I’ve used XAMPP ) with php plugin enabled

2. Make a new folder in your computer. Ensure you have an index.html or index.php on that folder. I’ve my folder on C:\xampp\htdocs\market

3. Make the following steps on C:\xampp\apache\conf\extra\httpd-vhosts.CONF file. This will be the file to define your virtual hosts

Add the following lines at the end of this file.

#this is to access the standard xampp home page
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>

#this is our virtual host grassfield.dev
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

4. Restart the apache service

5. Access http://localhost and http://grassfield.dev sites are rendered correctly on the browser. Sample file is attached in this post.

#
# Virtual Hosts
#
# 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.2/vhosts/&gt;
# 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.
#
#NameVirtualHost *:80
#
# 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.
#
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias http://www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</Virtual
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

The picture at the top don’t have any relations with this post 😉