Stagr icon indicating copy to clipboard operation
Stagr copied to clipboard

Change document root

Open jamesrward opened this issue 11 years ago • 5 comments

I'm trying to use Laravel (and Symfony2) with this but having no luck changing the document root to use Laravel's public folder. I tried:

sudo vim /etc/apache2/sites-available/myapp

and changed it to:

<VirtualHost *:80>
        ServerAdmin [email protected]

        ServerName partnership.dev
        DocumentRoot /var/www/web/myapp/htdocs/public

        SetEnv APP_NAME "partnership"

        # PHP Settings
        <FilesMatch \.php$>
                SetEnv no-gzip dont-vary
                Options +ExecCGI
        </FilesMatch>
        AddHandler php5-myapp-fcgi .php
        Action php5-myapp-fcgi /.ctrl/~~~php
        Alias /.ctrl/~~~php /var/www/web/myapp/redir/php

        <Directory /var/www/web/myapp/htdocs/public>
                # PathInfo for PHP-FPM
                RewriteEngine On
                RewriteCond %{REQUEST_URI} \.php/ [NC]
                RewriteRule ^(.*)\.php/(.*)$    /$1.php [NC,L,QSA,E=PATH_INFO:/$2]

                Options -All +SymLinksIfOwnerMatch
                AllowOverride AuthConfig Limit FileInfo Indexes Options=SymLinksIfOwnerMatch,MultiVie
ws,Indexes
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/myapp.log
        LogLevel debug
</VirtualHost>

Then restarted apache with:

sudo /etc/init.d/apache2 restart

All I get when visiting the sites after this change is:

File not found.

Is there a correct way to accomplish this so it can better match my fortrabbit config? If I visit the myapp.dev/public url everything is working fine so the document root is my only issue.

jamesrward avatar Oct 15 '13 01:10 jamesrward

Hey @jamesrward, I the problem is what I think it is, you need to change the FPM file as-well. The file can be found at /etc/php5/fpm/pool.d/ and you need to edit the conf file with the name of your app. I think the property you need to change is the include_path property.

There is also the symlink linking to htdocs, but I don't think you need to edit that, as you will be referencing the public dir explicitly. Try just changing the FPM conf file and then restarting both PHP FPM and Apache. (service php5-fpm restart)

Let me know if it works.

gmanricks avatar Oct 15 '13 16:10 gmanricks

No luck so far. Making these changes seems to just break my setup. Here are the two conf files, my project is called partnership. /etc/apache2/sites-available/partnership:

FastCgiExternalServer /var/www/web/partnership/redir/php -socket /var/fpm/socks/partnership.sock -idl
e-timeout 305 -flush

<VirtualHost *:80>
        ServerAdmin [email protected]

        ServerName partnership.dev
        DocumentRoot /var/www/web/partnership/htdocs/public

        SetEnv APP_NAME "partnership"

        # PHP Settings
        <FilesMatch \.php$>
                SetEnv no-gzip dont-vary
                Options +ExecCGI
        </FilesMatch>
        AddHandler php5-partnership-fcgi .php
        Action php5-partnership-fcgi /.ctrl/~~~php
        Alias /.ctrl/~~~php /var/www/web/partnership/redir/php

        <Directory /var/www/web/partnership/htdocs/public>
                # PathInfo for PHP-FPM
                RewriteEngine On
                RewriteCond %{REQUEST_URI} \.php/ [NC]
                RewriteRule ^(.*)\.php/(.*)$    /$1.php [NC,L,QSA,E=PATH_INFO:/$2]

                Options -All +SymLinksIfOwnerMatch
                AllowOverride AuthConfig Limit FileInfo Indexes Options=SymLinksIfOwnerMatch,MultiVie
ws,Indexes
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/partnership.log
        LogLevel debug
</VirtualHost>

/etc/php5/fpm/pool.d/partnership.conf

[partnership]
listen = /var/fpm/socks/partnership.sock

listen.owner = vagrant
listen.group = www-data
listen.mode  = 0660

user = vagrant
group = www-data

pm = dynamic
pm.max_children = 3
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 1000
request_terminate_timeout = 300
php_value[open_basedir] = ""
php_value[include_path] = ".:/usr/share/php:/var/www/web/partnership/htdocs/public"
php_value[upload_tmp_dir] = "/tmp"
php_value[session.save_path] = "/tmp"
php_value[apc.shm_size] = "64M"
php_value[auto_prepend_file] = "/var/fpm/prepend/partnership/prepend.php"
php_value[max_execution_time] = "300"
php_value[upload_max_filesize] = "128M"
php_value[default_charset] = "UTF-8"
php_value[short_open_tag] = "ON"
php_value[date.timezone] = "America/Toronto"

And here is the error being logged.

sudo tail -f /var/log/apache2/partnership.log

[Tue Oct 15 23:10:50 2013] [error] [client 192.168.2.10] FastCGI: server "/var/www/web/partnership/redir/php/index.php" stderr: Primary script unknown

jamesrward avatar Oct 15 '13 21:10 jamesrward

hey @jamesrward I got a chance today to try it all out, and I got it working. You actually don't need to change the fpm conf file at all, so you can change that back to just htdocs without the public directory. What you need to do, is inside the vhost change the alias line and add the new path to have the subdirectory. So for your example above, the final vhost should be:

FastCgiExternalServer /var/www/web/partnership/redir/php -socket /var/fpm/socks/partnership.sock -idle-timeout 305 -flush

<VirtualHost *:80>
        ServerAdmin [email protected]

        ServerName partnership.dev
        DocumentRoot /var/www/web/partnership/htdocs/public

        SetEnv APP_NAME "partnership"

        # PHP Settings
        <FilesMatch \.php$>
                SetEnv no-gzip dont-vary
                Options +ExecCGI
        </FilesMatch>
        AddHandler php5-partnership-fcgi .php
        Action php5-partnership-fcgi /.ctrl/~~~php
        Alias /.ctrl/~~~php /var/www/web/partnership/redir/php/public

        <Directory /var/www/web/partnership/htdocs/public>
                # PathInfo for PHP-FPM
                RewriteEngine On
                RewriteCond %{REQUEST_URI} \.php/ [NC]
                RewriteRule ^(.*)\.php/(.*)$    /$1.php [NC,L,QSA,E=PATH_INFO:/$2]

                Options -All +SymLinksIfOwnerMatch
                AllowOverride AuthConfig Limit FileInfo Indexes Options=SymLinksIfOwnerMatch,MultiVie
ws,Indexes
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/partnership.log
        LogLevel debug
</VirtualHost>

By adding that in, it will essentially add the prefix before the file as they load. Hope this helps :)

One of these days I need to rebuild Stagr with all the new features that have been added to vagrant, and I will definitely add this as an option when it set's up your project.

gmanricks avatar Oct 16 '13 17:10 gmanricks

Bingo! Working beautifully for Symfony2 and Laravel after editing those 3 lines and running:

sudo service apache2 restart

If you open up the wiki I would be happy to add this information. I look forward to testing the next version of Stagr whenever it is ready, thanks for all your work on this.

jamesrward avatar Oct 16 '13 18:10 jamesrward

Sure thing that would be really cool :)

gmanricks avatar Oct 16 '13 18:10 gmanricks