SexyMF SexyMF - 1 year ago 94
PHP Question

Create a new virtual host via php fails on Permission denied

I have 2 problems:

  1. when I run:


    I get the error:
    failed to open stream: Permission denied

  2. How do I safely
    apache (after adding a domain) from PHP.
    I don't think
    $res = shell_exec("sudo service apache2 reload")
    is working, I dont get anything in return.

Answer Source

Its a bad practice, why don't you go and create a default virtual host that will answer to any domain.
In the app level you can do some protections about it. This way you are shortening your code to the minimum.
He is an example (dont use it as it is, needs to be tested):

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/the_site>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download