First of all, excuse me if this is the wrong place to ask this question.
I made a Bash script which installs a DirectAdmin backup into Apache. The steps are working but in the end I get a 500 error when opening the actual website.
Steps:
1. Unpack backup.tar.gz
2. remove unessecary files
3. Ask for database details en website name
4. Cat to admin.conf files
5. Create database and user
6. Create and cat to /etc/apache2/sites-available/website.conf
7. a2ensite and service apache2 reload
8. Create an entry in Windows hosts file
I have traced all the steps back and all seems to work but when I enter the URL I get a 500 error. Did all this without a script and everything works.
Can someone tell me where the error could come from? Is there something different when doing all these steps with a bash script?
EDIT: Here is the entire script used:
#!/bin/bash
clear
tar -zxvf backup.tar.gz
sudo cp -R ./domains/*/public_html/* ./
sudo cp ./backup/*.sql ./
rm -rf ./backup ./domains
rm backup.tar.gz
sudo chmod 775 ./config.php
echo "ROOT_PWD?"
read -s root_pwd
echo "WEBSITENAME?"
read website
echo "DB_USERNAME?"
read usrname
echo "DB_PASSWORD?"
read db_pwd
echo "DB_DATABASE?"
read db
cat > ./config.php <<EOL
<?php
// HTTP
define('HTTP_SERVER', 'http://www.$website.nl/admin/');
define('HTTP_CATALOG', 'http://www.$website.nl/');
// HTTPS
define('HTTPS_SERVER', 'http://www.$website.nl/admin/');
define('HTTPS_CATALOG', 'http://www.$website.nl/');
// DIR
define('DIR_APPLICATION', $_SERVER['DOCUMENT_ROOT'].'/admin/');
define('DIR_SYSTEM', $_SERVER['DOCUMENT_ROOT'].'/system/');
define('DIR_IMAGE', $_SERVER['DOCUMENT_ROOT'].'/image/');
define('DIR_LANGUAGE', $_SERVER['DOCUMENT_ROOT'].'/admin/language/');
define('DIR_TEMPLATE', $_SERVER['DOCUMENT_ROOT'].'/admin/view/template/');
define('DIR_CONFIG', $_SERVER['DOCUMENT_ROOT'].'/system/config/');
define('DIR_CACHE', $_SERVER['DOCUMENT_ROOT'].'/system/storage/cache/');
define('DIR_DOWNLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/download/');
define('DIR_LOGS', $_SERVER['DOCUMENT_ROOT'].'/system/storage/logs/');
define('DIR_MODIFICATION', $_SERVER['DOCUMENT_ROOT'].'/system/storage/modification/');
define('DIR_UPLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/upload/');
define('DIR_CATALOG', $_SERVER['DOCUMENT_ROOT'].'/catalog/');
// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', '$usrname');
define('DB_PASSWORD', '$db_pwd');
define('DB_DATABASE', '$db');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
EOL
chmod 444 ./config.php
chmod 755 ./admin/config.php
cat > ./admin/config.php <<EOL
<?php
// HTTP
define('HTTP_SERVER', 'http://www.$website.nl/admin/');
define('HTTP_CATALOG', 'http://www.$website.nl/');
// HTTPS
define('HTTPS_SERVER', 'http://www.$website.nl/admin/');
define('HTTPS_CATALOG', 'http://www.$website.nl/');
// DIR
define('DIR_APPLICATION', $_SERVER['DOCUMENT_ROOT'].'/admin/');
define('DIR_SYSTEM', $_SERVER['DOCUMENT_ROOT'].'/system/');
define('DIR_IMAGE', $_SERVER['DOCUMENT_ROOT'].'/image/');
define('DIR_LANGUAGE', $_SERVER['DOCUMENT_ROOT'].'/admin/language/');
define('DIR_TEMPLATE', $_SERVER['DOCUMENT_ROOT'].'/admin/view/template/');
define('DIR_CONFIG', $_SERVER['DOCUMENT_ROOT'].'/system/config/');
define('DIR_CACHE', $_SERVER['DOCUMENT_ROOT'].'/system/storage/cache/');
define('DIR_DOWNLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/download/');
define('DIR_LOGS', $_SERVER['DOCUMENT_ROOT'].'/system/storage/logs/');
define('DIR_MODIFICATION', $_SERVER['DOCUMENT_ROOT'].'/system/storage/modification/');
define('DIR_UPLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/upload/');
define('DIR_CATALOG', $_SERVER['DOCUMENT_ROOT'].'/catalog/');
// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', '$usrname');
define('DB_PASSWORD', '$db_pwd');
define('DB_DATABASE', '$db');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
EOL
chmod 444 ./admin/config.php
mysql -u root -p$root_pwd -e "CREATE DATABASE $db"
mysql -u root -p$root_pwd -e "CREATE USER '$usrname'@'localhost' IDENTIFIED BY '$db_pwd';"
mysql -u root -p$root_pwd -e "GRANT ALL PRIVILEGES ON $db . * TO '$usrname'@'localhost';"
mysql -u $usrname -p$db_pwd $db < *.sql
touch /etc/apache2/sites-available/$website'.conf'
cat > /etc/apache2/sites-available/$website'.conf' <<EOL
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName $website.nl
ServerAlias www.$website.nl
ServerAdmin webmaster@localhost
DocumentRoot /var/www/$website/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOL
a2ensite $website'.conf'
service apache2 reload
When I made a backup from DirectAdmin from the website www.example.com and I used this website in my script everything went the way it supposed to but when entering the URL in a browser, I get the 500 error.
The Apache logs are empty.