Skip to content

Instantly share code, notes, and snippets.

@paridin
Last active September 12, 2015 06:39
Show Gist options
  • Save paridin/39bf89f1df2962cb625d to your computer and use it in GitHub Desktop.
Save paridin/39bf89f1df2962cb625d to your computer and use it in GitHub Desktop.
Allow PHP in a subdomain, after install a project django for domain in a2hosting

Guide

The problem, after install django project in my domain foo.net, i need install a limesurvey in a subdomain, using a2hosting

limesurvey.foo.net

  1. Create a subdomain using a cpanel limesurvey.foo.net
  2. Connect to account using ssh ssh -l user foo.net
  3. Download limesurvey and install it. https://www.limesurvey.com/ for more details
  4. Allow Cross Domain using .htaccess vi limesurvey/.htaccess

# Add in your .htaccess the following lines
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

Creating an javascript app who uses the remotecontrol api of limesurvey

  1. Create an other subdomain app.foo.net
  2. Create an .htaccess into your folder vi app/.htaccess
# Prevent Apache from serving .ht* files:
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine on

    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f

    # otherwise forward it to index.html
    RewriteRule . index.html
</IfModule>

Testing using jQuery

<script>
var url = 'http://limesurvey.foo.net/index.php/admin/remotecontrol';
var request.method = 'get_session_key';
request.params.username = 'UserName';
request.params.password = 'YourPassword';
$.post(url, JSON.stringify(request), function(result){
    console.log('sessionKey', result.result);
}, 'json');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment