V
V
Vlad Odies2016-09-11 09:04:20
linux
Vlad Odies, 2016-09-11 09:04:20

Auto create a subdomain with the site?

Hello. I plan to open my own service of donation pages for Minecraft game servers. The idea looks like this:
The user registers on the service, indicating the name of his server, the script processes the form and executes the sh script on a dedicated server under Debian. The sh script creates a folder with the name of the user's server, unpacks the archive prepared in advance, creates a config.php file with standard settings for my cms, indicating the site address, names there, and creates a database. As a result, we get a subdomain with an installed and mood script.
What I have:
Xeon E5 dedicated machine.
Donate page
script Script for sh with creating a directory and unpacking the archive
Knowledge and some budget.
Unresolved points:
How to use a php form to execute a Sh script with parameters like %username_dir% , %site_title%, so that Sh would create a folder with a name, unpack the existing site archive there and create a config according to the template with the address, site name specified by the user during registration.
I could in principle hire a freelancer, but I want to personally understand the principle and develop. Thanks in advance for any ideas.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Pavel Volintsev, 2016-09-11
@copist

When I first got acquainted with a server that creates third-level subdomains, and also knows how to "park" second-level domains, I first of all imagined that directories for user scripts were automatically created there, a config for Apache, and some kind of root daemon does sudo service apache reload
But on it turned out not to be the case.
1. There is a rule in DNS (see https://toster.ru/q/7456) - all ***.myservice.ru subdomains are sent to one IP
Replace 192.168.1.1 with your server IP
2. Do not use Apache/nginx binding a virtual host to a domain name (myservice.ru or another), all requests are sent for processing to one script (PHP?)
nginx

{
    listen 80;
    # server_name не указывать
}

3. In the application code (PHP), the domain is calculated in the HTTP request and based on this the response is built
. The user has a domain name in the user table, that is, the user Vasya is the domain vasya.myservice.ru
$domainName = $_SERVER['HTTP_HOST']; // vasya.myservice.ru
$userDomain = $db->findUserByDomain($domainName);
echo 'Владелец этой страницы: ', $userDomain->fullName; // Владелец этой страницы: Вася
// ...

It if speech about the web interface. And if you have really different applications (binaries?) installed from the archive, then you need to run different commands from PHP, for example
1. Create a directory, generate htaccess or host configs for Apache
2. Unpack the archive / or link some common part through symlink
3. Force Apache to reload configs
For these commands you will need php.net/manual/en/function.system.php php.net/manual/en/function.exec.php or php.net/manual/en/function. shell-exec.php
The last item is the most insecure, because you need to give the Apache user the right to execute the command as root. It's better to do this by cron or on behalf of a special daemon service, and not from PHP.

V
Victor Pleisun, 2016-09-11
@neovictor

WildCard to the rescue,
+checking the subdomain name, no folders with sites are needed

F
Fenix957, 2016-09-12
@Fenix957

When a user adds all this, let php create newusers.txt, and by cron you will run some kind of script that parses this file in turn and creates everything you need. depending on how often users registrate and set the time for crowns. if it's very frequent let the script be checked every few minutes. and at the end of the script, let it delete the . at the expense of subdomains have already been said) although there are many options when a folder is simply created and it becomes a subdomain. htaccess to help)

L
Lander, 2016-09-11
@usdglander

system()
upd: In general, such things are resolved through htaccess.

X
xmoonlight, 2016-09-12
@xmoonlight

It couldn't be easier:
1. In DNS, we prescribe * and IP-shnik.
2. Checking the HOST on the URI router when requesting anyusername.servername.com
3. Making the transfer to the right folder (or loading the right script) depending on the 3rd-level domain from which we take the user (after checking its existence).
4. Also, you can do it with system services that are not user subdomains with a transparent "rolling" of the session.
Everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question