0

I have a Symfony PHP Application I want to run in a Windows server with Apache 2.4

Its files are stored in D:\Apache24\htdocs\project1\public

Its entry point is D:\Apache24\htdocs\project1\public\index.php

I followed instructions available at https://symfony.com/doc/current/setup/web_server_configuration.html and added this to my \Apache24\conf\extra\httpd-vhosts.conf:

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost

    DocumentRoot /Apache24/htdocs/project1/public
    <Directory /Apache24/htdocs/project1/public>
        AllowOverride All
        Require all granted
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /Apache24/logs/project1_error.log
    CustomLog /Apache24/logs/project1_access.log combined
</VirtualHost>

But then my project takes over the server and loads at the root, and I don't want this.

I want this project's app to be served as http://localhost/project1

How can I achieve that and comply with Symfony's routing needs?

This is my http -S output:

Included configuration files:
  (*) D:/Apache24/conf/httpd.conf
    (514) D:/Apache24/conf/extra/httpd-vhosts.conf
VirtualHost configuration:
*:80                   localhost (D:/Apache24/conf/extra/httpd-vhosts.conf:41)
ServerRoot: "D:/Apache24"
Main DocumentRoot: "D:/Apache24/htdocs"
Main ErrorLog: "D:/Apache24/logs/error.log"
Mutex default: dir="D:/Apache24/logs/" mechanism=default
PidFile: "D:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: DUMP_MODULES
Define: DUMP_INCLUDES
Define: SRVROOT=D:\Apache24
Loaded Modules:
 core_module (static)
 win32_module (static)
 mpm_winnt_module (static)
 http_module (static)
 so_module (static)
 actions_module (shared)
 alias_module (shared)
 allowmethods_module (shared)
 asis_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 dir_module (shared)
 env_module (shared)
 include_module (shared)
 isapi_module (shared)
 log_config_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 setenvif_module (shared)
 php7_module (shared)

1 Answer 1

0

You need to use the following in your vhost config: Alias /project1 /Apache24/htdocs/project1/public

More info is available at: https://httpd.apache.org/docs/2.4/mod/mod_alias.html

An alternative would be to use a custom domain for your site that's hosted on your localhost by adding a domain like project1.local, to your local hosts file.

(You will need admin to modify this file) c:\windows\system32\drivers\etc\hosts or on *nix (Mac) it's /etc/hosts

The addition would look something like the following, but don't remove anything you didn't already add: 127.0.0.1 project1.local www.project1.local

I prefer the second approach for development, as I can have my local website hostname similar to my production one. It also makes transitioning from dev to prod environments smoother as the application is only dependent on a different hostname, versus a hostname and a path.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .