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


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


If you don't want to use


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 \

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]

Finally activate the new vhost

$ sudo a2ensite my_application_dev
$ sudo service apache2 restart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.