Duplicate Laravel web app to subdomain and separate the database - php

I have a web app built using Laravel and MySQL. It's currently running on my www.domain.com
I would like to know how to "duplicate" the web app to a subdomain with a separated database?
The web app has login and signup features. There's also email notification sent to clients if they sign up, make changes, etc.
The reason I'm doing this is because I have two types of clients, local and overseas clients. Therefore I have to separate them since they use different currencies and languages. So, when my team login to the subdomain, they'll know they have to speak in our local language, but when they login to the www.domain.com, they'll know they have to speak English.
Thanks very much, will appreciate any help
UPDATE The database has been successfully copied to a new database, however the sign up and login pages of the subdomain are linked to the main domain.

You could look up https://hyn.readme.io which does pretty much exactly what you want. It lets you setup new tenants which are assigned a subdomain and creates a separate database while at the same time sharing your actual application between them all.
If needed you can add tenant-specific overrides of the default apps views and whatnot by adding them to the tenants own folders.

According to your comment earlier, you are getting error in phpMyAdmin when trying to upload database. Why not just copy the database in phpMyAdmin? Go to database you want click on Operations then under Copy Database type name of new database and select copy structure and data. That should solve your issue.

Related

Multiple Domains and Domain Specific database queries in Laravel

So we have been developing a content management system on laravel and everything is finished. Our plan was to ship it as downloadable solution for customers but now things have changed and we have decided that we will provide it as a SAAS. As it will be used by multiple customers and they will be either using their own domain or our subdomain, I figured out the following solution.
Detect the domain or sub domain and query it against the database
Get the relevant id from a table storing the domains
Set the id in a session or a global variable
Get the settings of the site using that key
For all the subsequent queries to database, add a default where('domain_id',$idOfDomain) so that to avoid mixing up of the data by users of different clients
I don't know if that's the best approach but currently i feel like it's the solution. Now the problem is that I don't know
How to load the domain id and settings from database before code in controller is executed. Just like the configuration file in laravel
I tried to set a default key on models but it was not much successful and I want to know how to set and retrieve domain id in all models as editing all the codes in controller will be too much time consuming
Besides if someone has better and secure solution then the above one then please share it.
Thanks :)
Have a look at the package delatbabel / site-config, it sounds like it does most of what you want. Search on packagist or github. It will pre populate the laravel config data based on database contents, depending on what domain The browser is pointing to.

linking android application to the mysql database phone and link the info as well

Hey guys im faced with a challenge of linking my localhost mysql/php when adding something in a form that form should also be linked with my android application.
ex. I have made a form for the admin whereby they could add a new bus route and it will be stored into their database using php mysql in localhost server now that new route should also be linked to my android application it should display the new route (My android application uses sqlite database so two different database here) so when users use the application when they search for new route it should also display as well
How can i go with that? any ideas please im really stuck in this
thank you
Well there are generally 2 approaches to follow when you want to 'Sync' your web database to your mobile database
Push Notifications: You could send a push notification to all your users, whenever a new route is added to the mysql db. When the notification is received by your app, (it's not necessary you show the notification to the user) you could just ping the server for the new route, or you can send the 'route' in the message part of the push notification if you can, and then add this new route to your sqlite database.
AccountManager: Using the AccountManager is the preferred method when you want to Sync your data. The AccountManager uses the SyncAdapter to Sync your apps data with it's cloud. When Android pings the servers of other apps for syncing, it pings your app's server too, and syncs your data. This method also takes care of issues like, if the internet connection was not working when it was intended to sync, so android will schedule the next sync soon.
To provide a good service, you should take a look at a client-agnostic API architecture.
In this architecture, you have a PHP/go/whatever-written API, that can or can not be REST (but it's reccomended), that will provide, given a HTTP petition, the desired result.
Using PHP in the simplest way, you should create different .php files, one for each action ( www.myserver.com/getRoutes.php, www.myserver.com/getRouteDetail?routeId=3), and make those PHP files query the MYSQL database and return (echo) XML / JSON / Raw text.
this should then be parsed by your mobile application, and added/updated to your SQLite database.

Multiple instances/sessions of a web app codeigniter

I am new to backend coding but I am getting the hang of codeigniter. I have deployed the simple task board application hosted on github and everything is fine. As it stands this application uses sessions to create a single dashboard that can be shared by multiple users. I would like to be able to set this up so that a user could register and start their own dashboard. For simplicity it would be good if this new instance or session (not quite sure if I have the terminology right) could share the same database.
So my question is can someone tell me what I need to research in order to develop this? I dont think I have the right terminology to ask google or manuals for what I need.
I prefer you to use codeigniter session library and for dashboard, you may be stored much data in session, so use "Saving Session Data to a Database"
check this link : http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Creating Multiple portals from a site and serving the portals

I need to build a strategy or plan for implementation of a site
the situation is the following:
i have a site for people which belong to a community say xyz.
now i need to provide an account for the individuals of such communities on my site
when they logs into my site, there will be a feature to build a portal for themselves with some functionalities
like wise when n no of people logs in they might create n no of portal for themselves with some functionalities
the people will also create or use a n no of domain name respectively for the portal.
my problem or questions is:
How can i plan to create such a website?
Do i have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
How can i setup the site at domain automatically?
Update 1
I think the main website will already have a domain name for it
The other portals created through the main website will also have domain name for themselves as they are for some users
but the question is i have my main website domain name already using the code base which is serving the main website, now can i create domain names through my main website for the users and also ask the newly created domain names to use the same code base of my main website?
Actually i am planning to create domains through my application(please guide how can i create domain from my application) than after creating the domain can i ask the newly created domain to use the code base of my website which created the domain.
than there in the code base i do a domain name check as suggested in few other forums i guess, and load the content for the portal in the newly created domin
is this possible? if yes also can you guide me how can i:
create domains from my application? and than
during domain creation process through my application, how can i configure the new domain being created to my application code base?
is this the right way of implementing it?
1) How can i plan to create such a website?
Think about what exactly it is that the user requires. They have made an account, and want a portal to their own personal domain on the server. A domain on a server is just a file, so when they create that new portal, you might want to simply add a new HTML file under a logical directory, and populate it with some standard HTML.
2)Do I have to create separate code base files for each individual portal? or my current website portal code base can serve for each individual created portals?
I guess you can make the difference specified by a query string in the URL. For example, add database values for each user, and do something like this:
www.mywebsite.com/portal.php?id=40395
Your page will then use that id value, and take values from the database to populate the page with. That way you only have one file, portal.php, but it serves for any number of people.
3)How can i setup the site at domain automatically?
Like I said, the domain is just a file on the server. For example:
www.mywebsite.com/files/directory/hello.php
is just referring to the structure of files on the server. Namely:
www.mywebsite.com
files
directory
hello.php
If you place a file, goodbye.php in the same place, you can access it in a similar way.
www.mywebsite.com/files/directory/goodbye.php
PLEASE NOTE : You have provided no code, so I don't feel obliged to provide any in return. If you haven't took a swing at the problem of implementing the solution, then I guess I won't either.

Upload images to a newly created domain using PHP

Use Case:Working on a project where user can create his own site and publish it to internet.(Something similar to this or this). The user can create and later edit his website.When the user wants to publish we create a domain of his choice(a subdomain at first.Can be a different domain later).
Issue:What we want to do is,have the images stored directly on the domain created for the user(The domain initially would be created as a subdomain).For example,our site is at www.xyz.com,then the subdomain can be ABC.xyz.com.This will help to maintain a single copy of images for both the publish and the edit domain.We don't want to store the same image at two different locations.
Research:
Two possibilities that I found could be used:
1) Have a php upload script(upload.php) on each domain created that would be called when user uploads any image.-->Not sure how efficient it would be
2) Use FTP to transfer images from a domain to another.(Some cross domain mechanism)-->Not sure about the security issues here
Do I need to have any kind of cross domain script to be written?Please,help me with how to go about the issue.I don't want the entire code but the logic that would take me in the right direction.Suggestions,if my approach is wrong are welcome.Thank you for your time.
Note: I am still figuring out other alternatives.If I get my code in some shape,will update it.

Categories