Monday, February 3, 2020

PHP-FPM, Apache virtual host from different mounts

I was stuck in scenario where I had to inter-operate both Ubuntu and Windows.

Most of my PHP projects were in Ubuntu and some few in Windows. I found it difficult because if you want to switch to the other project, then you have to switch the OS.

To mitigate this, I created a folder which is a common one accessible from both OS. From Windows its a D drive and all I could do was edit some apache config and it loads the projects from this web root.

But in case of Ubuntu, there was the apache already with default /var/www
It did not like moving out of the document root to a different point that too along with php-fpm.
I badly needed this as I was running different projects based on 5.6. 7.1 and 7.2.

After hitting Google a large number of times, finally managed to get this work.

In order to help myself and anyone who needs this future, this is a little note.

  • Setup virtual host in apache as similar to other ones
  • Change the apache default user and group to your system user and group:
  • Change the php-fpm user and group similar to apache:
    • /etc/php/7.1/fpm/pool.d/www.conf
    • /etc/php/7.1/fpm/php-fpm.conf
    • systemctl reload php7.1-fpm.service
  • And finally the virtual host example:
<VirtualHost *:80>
        ServerAdmin webmaster@kauripizzeria.test
        ServerName kauripizzeria.test
        ServerAlias kauripizzeria.test
        #DocumentRoot /var/www/html/raas
        DocumentRoot /media/bubi/SHARED/workspace/raas/kauri-pizzeria/public
        ErrorLog /media/bubi/SHARED/workspace/raas/error.log
        CustomLog /media/bubi/SHARED/workspace/raas/access.log combined

        <FilesMatch \.php$>
            # Apache 2.4.10+ can proxy to unix socket
            SetHandler "proxy:unix:/var/run/php/php7.1-fpm.sock|fcgi://localhost"
        </FilesMatch>

        <Proxy fcgi://kauripizzeria.test>
            ProxySet connectiontimeout=5 timeout=240
        </Proxy>

        <directory "/media/bubi/SHARED/workspace/raas/kauri-pizzeria/public">
        #<directory "/var/www/html/appexert/sekure/crm">
            DirectoryIndex index.php index.html
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride All
            Allow from All
            Require all granted
        </directory>
</VirtualHost>

Sunday, May 3, 2015

Python, Django Initial Setup

There are plenty of resources available on the web for installing and configuring Python and Django.

This one is small set of commands for installation on what i have experienced while installing

1. Install Python as per your need - Either from Python website or PPM distribution of your OS if it provides the one. (I prefer package manager, since it gives you stable release that best works with your OS version)
2. Install Django - As said above for #Python
3. Database - Python by defaut comes with SQLite, but i prefer MySQL for its robust features

After all these, i stuck up all getting together - When you try to run server by issuing something like this python manage.py runserver and get any errors, try these:
4. sudo apt-get install libmysqlclient-dev
5. sudo apt-get install python-dev
6. sudo easy_install mysql-python

Now you can start server and access this to find default page http://127.0.0.1:8000/

Thursday, March 27, 2014

Wednesday, March 19, 2014

Removing an empty div using Jquery

$('.selector:empty').remove();

Another Way

$.expr[':'].blank = function(obj){ return obj.innerHTML.trim().length === 0; }; $('.selector:empty').remove();

Friday, February 7, 2014

Capitalize First character in a Javascript String

var capitalized = capitalizeMe.substr(0, 1).toUpperCase() + capitalizeMe.substr(1);

var capitalized = capitalizeMe[0].toUpperCase() + capitalizeMe.substring(1);

var capitalized = capitalizeMe.charAt(0).toUpperCase() + capitalizeMe.substring(1);

var capitalized = capitalizeMe.slice(0,1).toUpperCase() + capitalizeMe.slice(1, capitalizeMe.length);

var capitalized = capitalizeMe.substring(0, 1).toUpperCase() + capitalizeMe.substring(1);

Custom image for facebook share - Open in popup

<a class="facebook" target="_blank" onclick="return !window.open(this.href, 'Facebook', 'width=640,height=300')" href="http://www.facebook.com/sharer/sharer.php?u=YOUR_URL">Facebook</a>

Thursday, February 6, 2014

JQuery URL parser function

// Parse URL Queries Method
(function($){
    $.getQuery = function( query ) {
        query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return results[1];
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return false;
        }
    };
})(jQuery);

// Document load
$(function(){
    var test_query = $.getQuery('test');
    alert(test_query); // For the URL /?test=yes, the value would be "yes"
});
Reference:

http://www.kevinleary.net/jquery-parse-url/