1

I've inherited an existing Silverstripe 3.4 site and am setting up a new Vagrant VM for it. It has an /app directory that Grunt copies into /public-www on build. Composer pulls everything else into public-www.

Website loads fine. Home page, and subpages multiple levels deep like http://mysite.local/dev/tasks. However it's not possible to load the admin login page.

Surely an Apache issue. The .htaccess file is the same that is running live right now without issue. But I can't see the problem in either. The following is my apache config (/etc/apache2/sites-enabled/default.conf)

ServerName local
DocumentRoot /var/www/html
<IfModule mod_fastcgi.c>
    AddHandler php56-fcgi-www .php
    Action php56-fcgi-www /php56-fcgi-www
    Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www
    FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -idle-timeout 1800 -pass-header Authorization
    <Directory "/usr/lib/cgi-bin">
        Require all granted
    </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
    AddHandler php71-fcgi-www .php
    Action php71-fcgi-www /php71-fcgi-www
    Alias /php71-fcgi-www /usr/lib/cgi-bin/php71-fcgi-www
    FastCgiExternalServer /usr/lib/cgi-bin/php71-fcgi-www -socket /run/php/php7.1-fpm.sock -idle-timeout 1800 -pass-header Authorization
    <Directory "/usr/lib/cgi-bin">
        Require all granted
    </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
        SetHandler php56-fcgi-www
    </FilesMatch>
</IfModule>

<Directory "/var/www/">
    AllowOverride All
</Directory>

<VirtualHost *:80>
    DocumentRoot /var/www/html/mysite/public-www
    ServerName mysite.local

    <IfModule mod_fastcgi.c>
        <FilesMatch ".+\.ph(p[345]?|t|tml)$">
            SetHandler php56-fcgi-www
        </FilesMatch>
    </IfModule>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/phpmyadmin
    ServerName phpmyadmin.mysite.local

    <IfModule mod_fastcgi.c>
        <FilesMatch ".+\.ph(p[345]?|t|tml)$">
            SetHandler php56-fcgi-www
        </FilesMatch>
    </IfModule>
</VirtualHost>
Aaryn
  • 1,601
  • 2
  • 18
  • 31
  • My suggestion would be to upgrade to 3.7, if not to 4.x =) – scrowler Aug 12 '19 at 21:50
  • 1
    This is actually for a 4.x upgrade anyway. This is why we are using fastcgi so we can toggle PHP version. But, yes, it may be worth just upgrading to 3.7 and using PHP 7 on a more traditional setup. – Aaryn Aug 12 '19 at 23:28

1 Answers1

1

I found the cause of this weird URL redirection. The /mysite/_config.php file had this in it:

Director::setBaseURL('http://mysite.local');

It looks like it was there to get around errors when /dev/build was run from the command line, which I have since seen show up, but at least now admin works. I tried adding a trailing slash, and that certainly did fix the URLs, but then I couldn't log in for some reason. Remove it entirely and I can log in.

Note those errors are complaining about this:

You probably want to define an entry in $_FILE_TO_URL_MAPPING that covers "/var/www/html/website/public-www"

Despite exactly that being right above the setBaseURL() line I removed.

global $_FILE_TO_URL_MAPPING;
$_FILE_TO_URL_MAPPING['/var/www/html/website/public-www'] = 'http://mysite.local';

Which I think is in the wrong place in /mysite/_config.php. After moving to _ss_environment.php, all is well there too.

Aaryn
  • 1,601
  • 2
  • 18
  • 31
  • Good job solving your problem and reporting it back here. With setting `Director::setBaseURL('http://mysite.local/');` with a slash and then not being able to log in, I have come across this before. I believe it is a cookie issue. Try deleting all your cookies for that domain after making this change and then try logging in. – 3dgoo Aug 14 '19 at 00:17
  • 1
    Thanks. All sorted. And bonus, your response led me to solving another issue I was having after upgrading to SS4. Thanks! https://stackoverflow.com/questions/57504667/silverstripe-4-1-ss-default-admin-username-and-password-not-respected/57504940#57504940 – Aaryn Aug 15 '19 at 04:41