Monthly Archives: May 2017

Ubuntu – Deploying application in Apache with custom port

Few years before I was very confused on how the applications are being deployed and port numbers are configured. It looks like a magic. But for the Sys Ops Engineer it is a simple task.

Then I learned myself the procedure and like to share with you. In this post, let’s assume we have PHP project which needs to be deployed. I am using Ubuntu OS, so the example is based on that.

I am having now the directory


Moving my project directory to the location /var/www/html and it is now like,


Now as the second step, Go to /etc/apache2/

Open the file ports.conf and add the following line under Listen 80. Please note that 80 is the default port for apache webserver. Now without disturbing 80, we are now gonna add our new port 6061

Listen 6061

Save the file ports.conf and go to the directory /etc/apache2/sites-available

Now create our project configuration file. I am having “myproj.conf”

Open myproj.conf file and add the following VirtualHost settings in it.

<virtualhost *:6061>
DocumentRoot /var/www/html/php-project
<Directory /var/www/html/php-project>
            DirectoryIndex index.php index.cgi index.html
            Options Indexes FollowSymLinks
            AllowOverride All
           Require all granted

Points to note here are,

  • You need to give your IP address to the ServerName
  • DirectoryIndex has by default index.php or index.cgi or index.html file as landing page. If you want to display home.php as front page, include that at the beginning of index.php and remove the rest of of files specified there.
  • Require all granted grants full permission to avoid Permission denied error.

Now create symlink inside the directory /etc/apache2/sites-enabled through terminal. Go to the path and give below command

sudo ln -s /etc/apache2/sites-available/myproj.conf myproj.conf

Now do restart the apache

sudo service apache2 restart

Open your browser, type localhost:6061



C3P0 Production Settings

I have given below the configuration having in mind minimum resource. You need to tailor it according to your application need.

Generally in production release, we need to ensure the removal of unwanted configs which may cause some other problem after release in Live. The configuration should be accurate and don’t use counts blindly maximum.

C3P0 has many configurations, upon that here given the essential ones,

hibernate.connection.provider_class – org.hibernate.connection.C3P0ConnectionProvider

  • The above statement is used to specify the C3P0 connection provider. Here we use C3P0ConnnectionProvider class

hibernate.c3p0.max_size – 200

  •  This one tells the connection pool that it can hold 200 connections at the maximum

hibernate.c3p0.min_size  – 10

  •  This one tells the connection pool that it can hold 10 connections at the minimum. Generally this will vary from (3-20) based on the need.

hibernate.c3p0.acquire_increment – 100

  •  This determines how many connections the connection pool can acquire when the pool is exhausted.

hibernate.c3p0.idle_test_period – 120

  •  This will lets the C3P0 to test all the idle and uncheckedout connection in every this specified seconds. If the value is 0, then it won’t test.

hibernate.c3p0.max_statements – 2000

hibernate.c3p0.timeout – 60

  •  Its Default value is 0. Zero means, idle connections never expire. If the value given is greater than 0, then for the specified seconds the Connection can remain idle in pool but unused before discarded.

hibernate.c3p0.validate – true

  •  Default value is false. If we specify true, before every transaction gonna happen, it will validate the connection is valid or not. And we need to specify efficient preferredTestQuery.




When and why JPA entities should implement Serializable interface?

Answers from Stackoverflow:

This usually happens if you mix HQL and native SQL queries. In HQL, Hibernate maps the types you pass in to whatever the DB understands. When you run native SQL, then you must do the mapping yourself. If you don’t, then the default mapping is to serialize the parameter and send it to the database

According to JPA Spec:

If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.