Symfony2 - Apache vhost for app_dev different port

6,995

If you don't want to use

http://my_application.my_domain.net/index_dev.php

That does pretty much the same job, here the solution:


After having allowed your external IP to my_application/web/app_dev.php

// ...
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !in_array(@$_SERVER['REMOTE_ADDR'], array(
        'xxx.xxx.xxx.xxx', // <- your IP
        // ...
    ))
) {
// ...

Configured /etc/apache2/ports.conf to tell Apache to listen in the additional port

#...
NameVirtualHost *:80
Listen 80
NameVirtualHost *:8081
Listen 8081
#...

Simply duplicate the applications vhost (if you are using one)

$ sudo cp /etc/apache2/sites-available/my_application \
          /etc/apache2/sites-available/my_application_dev

and change the file pointed by the url rewriter

<VirtualHost *:8081>
    ServerName my_application.my_domain.net

    DocumentRoot "/var/www/my_application/web"
    <Directory "/var/www/my_application/web/">
        #...
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ /app_dev.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

Finally activate the new vhost

$ sudo a2ensite my_application_dev
$ sudo service apache2 restart
Share:
6,995

Related videos on Youtube

joshbroton
Author by

joshbroton

Web developer at Masao. Fan of Django/python, Symfony/php, Vue/javascript, Docker EPITECH promo 2004.

Updated on September 18, 2022

Comments

  • joshbroton
    joshbroton over 1 year

    As I'm using url rewriting to access my Symfony2 application, it is directly available from

    http://my_application.my_domain.net
    

    Now I'd like to be able to access the dev environment simply using a different port like:

    http://my_application.my_domain.net:8081