Lullabot / trusty32-lamp

An Ubuntu 14.04 VM for PHP with built in profiling
GNU General Public License v3.0
32 stars 10 forks source link

Installation with drupal-composer/drupal-project #46

Closed mtift closed 5 years ago

mtift commented 6 years ago

I have spent many hours over the past few days trying to figure out how to get this work with https://github.com/drupal-composer/drupal-project without success.

I read the README, https://github.com/Lullabot/trusty32-lamp/issues/31, and the issues mentioned.

I've tried symlinks to docroot from web, renaming web to docroot, various apache configurations (e.g. lots of "Allow from all" changes), and many other configuration changes, such as:

sed -i "s/docroot/web/" Vagrantfile
sed -i "s/docroot/web/" site-aliases/aliases.drushrc.php 

In some cases, I'm getting a WSOD, which in others I'm getting 403s.

When I install with composer create-project drupal-composer/drupal-project drupal --stability dev --no-interactionand then try to run this command from within the VM, I'm getting [Exception] Bootstrap failed.:

../vendor/bin/drush site-install --db-url=mysql://root@drupal.local/drupal

I feel like I must be missing something obvious because I can get this to work when I do something like this:

#!/bin/sh

cd /var/www
git clone https://github.com/Lullabot/trusty32-lamp d8
cd /var/www/d8
sed -i "s/trusty-lamp\.local/d8\.local/g" Vagrantfile
mkdir www
cd www
git clone http://git.drupal.org/project/drupal.git docroot
cd docroot
composer install
cp sites/default/default.settings.php sites/default/settings.php
echo "
\$databases['default']['default'] = array(
  'database' => 'd8',
  'username' => 'root',
  'password' => '',
  'host' => '127.0.0.1',
  'driver' => 'mysql',
);
\$settings['trusted_host_patterns'] = array('^d8\.local$',);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);" >> sites/default/settings.php
vagrant up
vagrant ssh -c 'mysql -u root -e "CREATE DATABASE d8"'
vagrant ssh -c "mysql -u root -e 'GRANT ALL PRIVILEGES ON *.* TO \"root\"@\"%\";'"
vagrant ssh -c "cd /vagrant/www/docroot; drush si -y --db-su=root --db-url='mysql://root@d8.local/d8' --account-pass=admin"
vagrant ssh -c "sudo update-alternatives --set php /usr/bin/php7.0"
vagrant ssh -c "sudo a2dismod php5.6 && sudo a2enmod php7.0; sudo service apache2 restart"
vagrant ssh -c "cd /vagrant/www/docroot; drush cache-rebuild"
gnome-open http://d8.local

So I'm thinking there must be something different with https://github.com/drupal-composer/drupal-project and maybe I should not bother even trying to use that, or that maybe it's not worth the effort.

Does that work for anyone else to use drupal-composer/drupal-project?

q0rban commented 6 years ago

What I've typically done is:

  1. Clone this repo
  2. If the www dir already exists, rm -R www
  3. composer create-project drupal-composer/drupal-project:8.x-dev www --stability dev --no-interaction
  4. cd www && ln -s ./web ./docroot

If your local PHP version differs wildly from what you'll be using in Vagrant, you may need to do just checkout the composer.json directly and put it in www, then ssh to the vagrant box and run composer install there.

We should probably document this. Related is #31.

mtift commented 6 years ago

Thanks for the tip. I'm not sure what I did differently, but this works for me with composer 1.6.3 and PHP 7.0.27 on my host machine (laptop):

#!/bin/sh

echo "# Setup drupal8.local"
cd /var/www
git clone https://github.com/Lullabot/trusty32-lamp drupal8
cd /var/www/drupal8
sed -i "s/trusty-lamp\.local/drupal8\.local/g" Vagrantfile
composer create-project drupal-composer/drupal-project:8.x-dev www --stability dev --no-interaction
cd www
ln -s ./web ./docroot
cp web/sites/default/default.settings.php sites/default/settings.php
composer install
echo "
\$databases['default']['default'] = array(
  'database' => 'drupal8',
  'username' => 'root',
  'password' => '',
  'host' => '127.0.0.1',
  'driver' => 'mysql',
);
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);" >> sites/default/settings.php
vagrant up
vagrant ssh -c 'mysql -u root -e "CREATE DATABASE drupal8"'
vagrant ssh -c "mysql -u root -e 'GRANT ALL PRIVILEGES ON *.* TO \"root\"@\"%\";'"
vagrant ssh -c "sudo update-alternatives --set php /usr/bin/php7.0"
vagrant ssh -c "sudo a2dismod php5.6 && sudo a2enmod php7.0; sudo service apache2 restart"
vagrant ssh -c "cd /vagrant/www/docroot; drush si -y --db-url='mysql://root@drupal8.local/drupal8' --account-pass=admin"
gnome-open http://drupal8.local
q0rban commented 6 years ago

This would be worthwhile to document since it's bound to be an issue for others. I ran into the same thing until I settled on the above approach.

deviantintegral commented 6 years ago

Also see https://github.com/drupal-composer/drupal-project/issues/64

Something to double check is the SYNC_TYPE variable in the Vagrantfile. vboxsf is the only one that works everywhere, but is painfully slow. I use NFS normally, so a new site setup is:

These changes to Vagrantfile:

diff --git a/Vagrantfile b/Vagrantfile
index cd38681..9589fa7 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -5,7 +5,7 @@
 # Set the hostname of the VM. This will almost always need to be changed to
 # match your project. This should be fully-qualified, ending in a TLD like
 # .local or .lan.
-HOSTNAME = "trusty-lamp.local"
+HOSTNAME = "d8.local"

 # Set this to true to add a public IP for this machine. The IP will be served
 # by whatever network gives your host an IP address. This is useful for testing
@@ -28,7 +28,7 @@ PUBLIC_NETWORK = false
 #     performance issues in Vagrant 1.6. See
 #     https://github.com/smerrill/vagrant-gatling-rsync for a temporary
 #     solution.
-SYNC_TYPE = "vbox"
+SYNC_TYPE = "nfs"

 # By default, sync a "www" directory within this project. This can be changed
 # to an absolute path. By default, Apache is configured to look for a docroot

Then ln -s docroot web && vagrant up && drush @d8.local si --db-url=mysql://root@localhost/drupal8. Both drush and Drupal's installer will create the database automatically, if the user has permissions to do so.

Would be glad to get some README updates out of this.

deviantintegral commented 6 years ago

Oh, and that drush alias assumes you've followed https://github.com/Lullabot/trusty32-lamp#drush-alias-autoconfiguration

q0rban commented 6 years ago

Then ln -s docroot web && vagrant up && drush @d8.local si --db-url=mysql://root@localhost/drupal8.

I assume you mean ln -s web docroot.

mtift commented 6 years ago

I'm able to get this to work with drupal-project out of the box, but not with an existing site that uses drupal-project as described above. For my existing site, I have a script that looks something like this:


echo "# Setup mysite.local"
cd /var/www
git clone https://github.com/Lullabot/trusty32-lamp mysite
cd /var/www/mysite
sed -i "s/trusty-lamp\.local/mysite\.local/" Vagrantfile
git clone git@mygitserver.org:user/mysite.git www
cd www
ln -s web docroot
composer install
vagrant up
vagrant ssh -c "cd /vagrant/www/docroot; drush @mysite.local si --db-url=mysql://root@localhost/mysite"

But when I visit mysite.local, I get 403 Forbidden. It seems like all of the permissions are set correctly. I've been poking around in /etc/apache2 on the vagrant VM and everything the same as with drupal-project. I don't see any errors in /var/log/apache2/error.log and access.log is empty in the vagrant VM.

How do I troubleshoot a 403 on a vagrant instance?

deviantintegral commented 6 years ago

That is super odd that the logs are empty. There should be a 403 in the access log.

mtift commented 6 years ago

I'm really not sure why, but I got it working. If I figure it out, I'll add a comment back here. I think this might have had something to do with settings.php, but I need to do some more testing.