Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While you could do that directly from your PHP page, I suggest <strong>not to do that</strong>, for many reasons, from high failure risks (in case page execution gets interrupted suddenly, for example) to security risks (your httpd user will have write access to its own configuration + some stuff on the filesystem where it shouldn't).</p> <p>Some times ago I wrote a similar control "website creation control panel" that works pretty much this way:</p> <ul> <li>The php script receives the website creation request and stores it somewhere (e.g. in a database). dot.</li> <li>Another script, running as root via cron each, let's say, five minutes checks the website creation requests queue. If there is any: <ul> <li>Mark the site creation task as "locked"</li> <li>Create the directory at appropriate location, populate with scripts etc.</li> <li>Change all the permissions as needed</li> <li>Create new virtualhost configuration, and enable it</li> <li>Make the webserver reload its own configuration</li> <li>Mark the site creation task as "done"</li> </ul></li> </ul> <p>The second script can be written in whatever language you like, PHP, Python, Bash, ...</p> <h2>About apache configuration</h2> <p>To create a directory "mapped" to your domain, you could use something like this:</p> <p>First of all, "slugify" your domain name. I usually take the (sanitized!) domain name, and convert all dots with double-dash (that is not a valid domain name part). I don't like dots in file/directory names a part from file extension separation.</p> <p>Then, you can create something like this (assuming domain is <code>www.example.com</code>):</p> <pre><code>&lt;VirtualHost *:80&gt; ServerName www.exampple.com DocumentRoot `/my-sites/wwwroot/www--example--com` &lt;Directory "/my-sites/wwwroot/www--example--com"&gt; Options -Indexes FollowSymLinks Order allow,deny Allow from all AllowOverride All &lt;/Directory&gt; ErrorLog /var/log/apache2/www--example--com_error.log CustomLog /var/log/apache2/www--example--com_access.log vhost_combined &lt;/VirtualHost&gt; &lt;VirtualHost *:80&gt; ## redirect non-www to www ServerName www.example.com ServerAlias example.com RedirectMatch permanent ^(.*) http://www.example.com$1 &lt;/VirtualHost&gt; </code></pre> <p>Assuming you are placing your site files in directories like <code>/my-sites/wwwroot/www--example--com</code>.</p> <h2>Some security-related improvements</h2> <p>In my case, I also preferred <em>not</em> running the second script by root either; to do so you have to add some changes in order to let a less privileged user do some things on your system:</p> <ul> <li>Create a directory with write access for your user, let's say <code>/my-sites/conf/vhosts</code></li> <li>Create an apache virtualhost containing the following line: <code>Include "/my-sites/conf/vhosts/*.vhost"</code>, and enable it</li> </ul> <p>Then, let your user reload apache configuration, by installing <code>sudo</code> and adding this to your <code>/etc/sudoers</code>:</p> <pre><code>Cmnd_Alias A2RELOAD = /usr/sbin/apache2ctl graceful youruser ALL=NOPASSWD: A2RELOAD %yourgroup ALL = NOPASSWD: A2RELOAD </code></pre> <p>And, of course, also give write permissions to your websites base directory to the user that will be used to run the script.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload