1

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.

  • 3
    We can't really tell since you haven't shown us your script; only what you think it does. You may be 100% right and it does do what you think it does, or you may be wrong and in fact it does something else. What URL do you enter? Where do you enter it? How do you enter it? Please edit your question and show us the actual commands you use. – terdon Mar 19 '17 at 21:24
  • 2
    What does the Apache error log say? – roaima Mar 19 '17 at 21:41
  • Thanks for the edit, but we still don't know where the error occurs. When you enter which URL? At which command does it fail? At which step? Also, does your root password contain special characters? – terdon Mar 20 '17 at 9:38
  • Let's say for example we use www.example.com. FIrst I download a backup from DirectAdmin. Then I copy the backup file and the script to the destination folder on my server. After thats done I execute my script which is asking me for the root password (this does include special characters) so it can create a database and user credentials. This still works and a database is created. Then the script is asking for a website name which is "example". After the script enters all nesaccery info I add a entry to my Windows hosts file. After entering www.example.com in the browser I get a 500 error – Rob Michiels Mar 20 '17 at 9:56
  • 1
    @PdC: (1) Please use accurate edit summaries.  You seem to be repeatedly using canned edit summaries that have no relation to the edit.  For example, here you said, “Minor grammar errors fixed and syntactic sugar added.” (which you have used verbatim on at least two other edits), but all you did was fix capitalization.  (You do also sometimes fix formatting.) (2) When you edit a post, please do your best to fix all the problems with it.  Yesterday I rejected one of your suggested edits because it made low-priority changes to capitalization and formatting, but left a spelling error untouched. – G-Man May 12 '17 at 1:30
-1

Oh, You need to use ip_conntrack, Do the following steps:

  1. modprobe ip_conntrack
  2. get list of variables of sysctl with sysctl -a |grep -i conn:
    output is ":

    net.netfilter.nf_conntrack_acct = 0
    net.netfilter.nf_conntrack_buckets = 65536
    net.netfilter.nf_conntrack_checksum = 1
    net.netfilter.nf_conntrack_count = 116
    net.netfilter.nf_conntrack_events = 1
    net.netfilter.nf_conntrack_expect_max = 1024
    net.netfilter.nf_conntrack_generic_timeout = 600
    net.netfilter.nf_conntrack_helper = 0
    net.netfilter.nf_conntrack_icmp_timeout = 30
    net.netfilter.nf_conntrack_log_invalid = 0
    net.netfilter.nf_conntrack_max = 262144
    net.netfilter.nf_conntrack_tcp_be_liberal = 0
    net.netfilter.nf_conntrack_tcp_loose = 1
    net.netfilter.nf_conntrack_tcp_max_retrans = 3
    net.netfilter.nf_conntrack_tcp_timeout_close = 10
    net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
    net.netfilter.nf_conntrack_tcp_timeout_established = 432000
    net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
    net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30
    net.netfilter.nf_conntrack_tcp_timeout_max_retrans = 300
    net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 60
    net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 120
    net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
    net.netfilter.nf_conntrack_tcp_timeout_unacknowledged = 300
    net.netfilter.nf_conntrack_timestamp = 0
    net.netfilter.nf_conntrack_udp_timeout = 30
    net.netfilter.nf_conntrack_udp_timeout_stream = 180
    net.nf_conntrack_max = 262144
    
  3. change net.ipv4.netfilter.ip_conntrack_max varibale.

  4. store in file.
  • Please could you explain why this would fix a 500 error? – roaima Mar 19 '17 at 21:42
  • This variable tell to kernel how many client can connect to server.No difference , www, squid, or any client. – PersianGulf Mar 21 '17 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.