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

      php-project

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

      /var/www/html/php-project

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>
ServerName YOUR_IP_HERE
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
   </Directory>
</virtualhost>

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

Congratulations.!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s