apache2 drupal

Apache2 drupal

/etc/apache2/sites-available/do_not_change.local.conf

 

<VirtualHost do_not_change.localhost *:80>
  DocumentRoot /var/www/do_not_change/do_not_change-manager/web
  ServerName do_not_change.localhost
  ServerAlias do_not_change.local
  ErrorLog ${APACHE_LOG_DIR}/do_not_change_error.log
  LogLevel debug
  CustomLog ${APACHE_LOG_DIR}/do_not_change_access.log combined
  <IfModule mpm_itk_module>
    AssignUserId utilisateur www-data
  </IfModule>
  <Directory /var/www/do_not_change/do_not_change-manager/web>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
  <FilesMatch \.php$>
      # Apache 2.4.10+ can proxy to unix socket
      #SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
      SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
  </FilesMatch>
</VirtualHost>

 

#!/bin/bash
drupalsite=$1
origdir=`pwd`
version=10.0.9
#CHANGE THE USERNAME from j to your username.
u=`whoami`
#DEFAULT PASSWORD FOR THE MYSQL USER.
motdepasse="Motdepasse780!";
motdepasse_reg='Pozzewerdz1!';

if [[ -z "$2" ]]; then
  echo "To enable script debug mode uncomment '#set -x' (remove the # symbol)";	
  sleep 3
  #debug
  #set -x
fi

if [[ -n "$1" ]]; then
  echo "Create a website by the name of ${1}.local"
elif [[ -z "$1" ]]; then
  echo "Please specify the site name."
  echo "example: sudo ./create_drupal_site.sh sitename";
  exit;
fi


sudo cp /etc/apache2/sites-available/do_not_change.local.conf /etc/apache2/sites-available/${drupalsite}.local.autogenerated.conf
cd /etc/apache2/sites-enabled
sudo ln -s ../sites-available/${drupalsite}.local.autogenerated.conf ${drupalsite}.local.autogenerated.conf
cd /etc/apache2/sites-available
sudo sed -i -e "s/do_not_change/${drupalsite}/g" ${drupalsite}.local.autogenerated.conf
sudo sed -i -e "s/utilisateur/${u}/g" ${drupalsite}.local.autogenerated.conf
LINE="127.0.0.1 ${drupalsite}.local"
FILE='/etc/hosts'

sudo chmod 666 /etc/hosts
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
sudo chmod 644 /etc/hosts

sudo service apache2 restart

echo "The script creates a db called ${drupalsite}"
echo "mysql-uroot -p #if you run this script as sudo you won't need to enter a password. "
alter="ALTER DATABASE ${drupalsite} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

mysql -uroot -p$motdepasse -e "create database if not exists ${drupalsite} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
#mysql -uroot -p --database=${drupalsite} -e $alter;
creer_utilisateur="CREATE USER '${drupalsite}'@'localhost' IDENTIFIED BY '${motdepasse_reg}';"
mysql -uroot -p$motdepasse --database=${drupalsite} -e "$creer_utilisateur";
privileges="GRANT ALL PRIVILEGES ON ${drupalsite}.* to '${drupalsite}'@'localhost';FLUSH PRIVILEGES;"
mysql -uroot -p$motdepasse --database=${drupalsite} -e "$privileges";

echo "sudo mkdir -p /var/www/${drupalsite}/${drupalsite}-manager"
[[ -d /var/www/${drupalsite}/${drupalsite}-manager ]] || sudo mkdir -p /var/www/${drupalsite}/${drupalsite}-manager

echo "A restart is necessary to pick up the new vhost"
sudo service apache2 restart
cd /var/www/${drupalsite}
sudo chown ${u}:www-data /var/www/${drupalsite} -R
if [ ! -f drupal-${version}.tar.gz ]; then
  wget https://ftp.drupal.org/files/projects/drupal-${version}.tar.gz
fi
cd /var/www/${drupalsite}/${drupalsite}-manager
tar -pxzf ../drupal-${version}.tar.gz
#drupal-${version}.tar.gz
mv drupal-${version} web
cd web
sudo chown ${u}:www-data /var/www/${drupalsite} -R
sudo chmod 775 /var/www/${drupalsite} -R
composer install


echo "sudo mkdir -p /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/files"
[[ -d /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/files ]] || sudo mkdir -p /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/files

cp /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/default.settings.php /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/settings.php
sudo chmod 775 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/files
sudo chmod 664 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/settings.php

sudo chown ${u}:www-data /var/www/${drupalsite} -R
if grep -q "^    namespace' => 'Drupal" /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/settings.php
then
  echo "Database settings in /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/settings.php is already configured.";
  dbSetupTest=1;
else
  echo "chmod 775 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default"
        chmod 775 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default
  settings_file=/var/www/${drupalsite}/${drupalsite}-manager/web/sites/default/settings.php;

  if [ -z $passvar ]; then
    passvar=$motdepasse_reg;
  fi
  if [ -z $uservar ]; then
    uservar=$drupalsite;
  fi
  echo "chmod 664 $settings_file"
        chmod 664 $settings_file
  echo "\$databases['default']['default'] = array (" >> $settings_file
  echo "  'database' => '$uservar'," >> $settings_file
  echo "    'username' => '$uservar'," >> $settings_file
  echo "    'password' => '$passvar'," >> $settings_file
  echo "    'prefix' => ''," >> $settings_file
  echo "    'host' => 'localhost'," >> $settings_file
  echo "    'port' => '3306'," >> $settings_file
  echo "    'isolation_level' => 'READ COMMITTED'," >> $settings_file
  echo "    'namespace' => 'Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql'," >> $settings_file
  echo "    'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/'," >> $settings_file
  echo "    'driver' => 'mysql'," >> $settings_file
  echo "  );" >> $settings_file
#  echo "chmod 555 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default"
#        chmod 555 /var/www/${drupalsite}/${drupalsite}-manager/web/sites/default
fi
#echo "Bonjour" >> /var/www/${drupalsite}/${drupalsite}-manager/web/index.html

echo "Mysql username: root"
echo "Mysql password: ${motdepasse}!"
echo "Mysql username: ${drupalsite}"
echo "Mysql password: ${motdepasse_reg}"
echo "";
echo "Félicitations VOTRE NOUVEAU SITE Drupal $version EST PRÊT: http://${drupalsite}.local/install.php"

cd $origdir;

 

 

Commentaires

missing composer dependency, apt-get install composer

set up .bash_aliases

edit the mysql password in the script

created scripts folder with owner:group permissions, created script with 755 execute perms

also going to need MAX_ALLOWED_PACKET at 32MB or 64MB or so

and increase php.ini memory limit and other limits.

 

drupal/core 8.8.0 requires ext-dom * -> the requested PHP extension dom is missing from your system

 

Troubleshooting: change the password from password to whatever your password is