k0ala
By:
k0ala

Apache2 Restart Problem

June 26, 2017 1.2k views
Apache Debian

So everytime i type "service apache2 restart" into putty, i get an error

apache2: Syntax error on line 268 of /etc/apache2/apache2.conf: Syntax error on line 30 of /etc/apache2/sites-enabled/000-default: Expected </Directory> but saw </VirtualHost>
Action 'configtest' failed.
The Apache error log may have more information.
can anyone help me?

8 Answers
hansen June 26, 2017
Accepted Answer

Hi @k0ala
Can you post the file here /etc/apache2/sites-enabled/000-default ?

  • I don't think so? I'm on file zilla and whatever I try to do to the 000-default folder it says

    Error: Directory /etc/apache2/sites-available/default: no such file or directory
    Error: Failed to retrieve directory listing

    • If I try to download or enter the folder, it says that ^^

      • @k0ala
        In PuTTY, simply write this command:

        cat /etc/apache2/sites-enabled/000-default
        

        And then copy-and-paste the content here - you might need to scroll a little to get everything.
        And please use the </> button in the comment editor to make sure it doesn't lose formatting.

        • <VirtualHost *:80>
                  ServerAdmin webmaster@localhost
          
                  DocumentRoot /var/www
                  <Directory />
                          Options FollowSymLinks
                          AllowOverride None      </Directory>
                  <Directory /var/www/>
                          Options Indexes FollowSymLinks MultiViews
                          AllowOverride All
                          Order allow,deny
                          allow from all
                  </Directory>
          
                  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
                  <Directory "/usr/lib/cgi-bin">
                          AllowOverride None
                          Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                          Order allow,deny
                          Allow from all
                  </Directory>
          
                  ErrorLog ${APACHE_LOG_DIR}/error.log
          
                  # Possible values include: debug, info, notice, warn, error, crit,
                  # alert, emerg.
                  LogLevel warn
          
                  CustomLog ${APACHE_LOG_DIR}/access.log combined
          </VirtualHost>
          

@k0ala Just starting a new thread, since it was getting a little narrow.

My guess would be that this is your problem:

        <Directory />
                Options FollowSymLinks
                AllowOverride None      </Directory>

Which should look like this:

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

But I don't understand why it says line 30 in the error, when this is clearly not line 30.
Anyways, let's edit the file with this command to make it look like the above:

nano /etc/apache2/sites-enabled/000-default

When you are done editing, hold CTRL key and press X key, release keys, press Y key and press Enter key.

Now restart Apache service apache2 restart.

  • thank you so much!

  • Ok well now when i restart apache it says
    "service apache2 restart
    [ ok ] Restarting web server: apache2 ... waiting ."

    • Run this command to show the last 20 lines from the error log:

      tail -20 /var/log/apache2/error.log
      
      • [Mon Jun 26 01:09:50 2017] [error] [client 23.250.117.178] script '/var/www/proxy.php' not found or unable to stat, referer: RefererString
        [Mon Jun 26 01:13:50 2017] [error] [client 178.165.89.97] script '/var/www/proxy.php' not found or unable to stat, referer: RefererString
        [Mon Jun 26 01:14:17 2017] [notice] caught SIGTERM, shutting down
        PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ming.ini on line 1 in Unknown on line 0
        [Mon Jun 26 01:14:18 2017] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u8 configured -- resuming normal operations
        [Mon Jun 26 01:14:36 2017] [alert] [client 91.230.47.3] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
        [Mon Jun 26 01:14:58 2017] [alert] [client 208.91.115.10] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
        [Mon Jun 26 01:15:29 2017] [alert] [client 176.112.8.181] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: RefererString
        [Mon Jun 26 01:15:47 2017] [notice] caught SIGTERM, shutting down
        PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ming.ini on line 1 in Unknown on line 0
        [Mon Jun 26 01:15:48 2017] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u8 configured -- resuming normal operations
        [Mon Jun 26 01:19:05 2017] [alert] [client 46.161.9.32] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
        [Mon Jun 26 01:19:09 2017] [alert] [client 115.28.167.101] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
        [Mon Jun 26 01:21:00 2017] [alert] [client 93.179.68.158] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
        [Mon Jun 26 01:21:12 2017] [notice] caught SIGTERM, shutting down
        PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ming.ini on line 1 in Unknown on line 0
        [Mon Jun 26 01:21:12 2017] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u8 configured -- resuming normal operations
        [Mon Jun 26 01:22:31 2017] [notice] caught SIGTERM, shutting down
        PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ming.ini on line 1 in Unknown on line 0
        [Mon Jun 26 01:22:32 2017] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u8 configured -- resuming normal operations
        
        

@k0ala Getting a little narrow again, so starting a new thread

Can you remove or rename the file /var/www/.htaccess, which might be the reason.
Rename command mv /var/www/.htaccess /var/www/.htaccess-OLD

  • So should i run the command? Or should i remove .htaccess

    • If you remove it, you should have it in a backup somewhere. If you move it, you still have it available.

      By the way, I would highly recommend that you hire a system administrator to update your server, since you are running a very old version of Apache and PHP, which has received several critical security updates since. And my guess is everything else on the server is also outdated.

@k0ala
What are you confused by?
The file? Do you have a backup of the file, then remove it. If not, then simply rename it.
The server? Hire a system administrator to help you with the server.

  • So if I rename it(and what do i rename it to?), what will it do and will it help me run the restart apache? I'm new to this if you couldn't tell

    • @k0ala
      I have no idea what you're trying to run on your web server, so I don't know the consequence of removing the file, but it's generating errors, so it doesn't work currently.

      What have you done to the server lately, since everything stopped working - and the configuration files has been edited?

      Run this:

      mv /var/www/.htaccess /var/www/.htaccess-OLD
      
      apache2ctl configtest
      
      apache2ctl restart
      
      • mv /var/www/.htaccess /var/www/.htaccess-OLD

        mv: cannot stat `/var/www/.htaccess': No such file or directory
        
        

        apache2ctl configtest

        Syntax OK
        

        apache2ctl restart
        nothing happens ^

@k0ala
Okay, then you've just renamed or removed the file.
Try running the following:

service apache2 start

service apache2 status
#press Q to exit the status dialog
  • service apache 2 start

    
    [ ok ] Restarting web server: apache2 ... waiting .
    
    
    

    service apache2 status

    Apache2 is running (pid 20155).
    
    

sorry for leaving @hansen, I was really tired and i went to bed... anyway

the site isn't working and even after doing everything you said and then typing "service apache2 restart" it still said waiting, and I'm following a tutorial that requires you to type that command in order for the website to work... or else you get a 404 error and that's exactly what's happenening so no the site doesn't work :/

I looked up some issues online and reinstalled things and it worked, my website was working. But now comes another issue which I don't think is a droplet issue but everytime I type "node site.js" I get this long error


[2017-06-26 15:54:00.991] [INFO] [default] - DB Connection ID: 399
[2017-06-26 15:54:00.994] [INFO] [default] - DB Connection ID: 400
[2017-06-26 15:54:00.995] [INFO] [default] - DB Connection ID: 401
[2017-06-26 15:54:00.997] [INFO] [default] - DB Connection ID: 402
[2017-06-26 15:54:01.002] [TRACE] [default] - Roll 4263
[2017-06-26 15:54:01.003] [TRACE] [default] - Sucesfully updated history
[2017-06-26 15:54:01.004] [WARN] [default] - Loaded hashd8b710dfa2c8a3d990ca1dc7                                                                                           cc0a91754ac20aa6139fb7f6d44b58ee31ece8dc
[2017-06-26 15:54:01.134] [WARN] [default] - Loaded fresh prices
[2017-06-26 15:54:01.190] [WARN] [default] - Prices loaded from cache
[2017-06-26 15:54:03.934] [TRACE] [default] - Strange error
[2017-06-26 15:54:03.935] [DEBUG] [default] - { Error: listen EADDRINUSE :::8080
    at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at Server.setupListenHandle [as _listen2] (net.js:1305:14)
    at listenInCluster (net.js:1353:12)
    at Server.listen (net.js:1453:7)
    at Server.listen.Server.attach (/home/bot/node_modules/socket.io/lib/index.j                                                                                           s:237:9)
    at Timeout._onTimeout (/home/bot/site.js:618:29)
    at ontimeout (timers.js:488:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:283:5)
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 8080 }

It was working literally 10 minutes ago and now it doesn't work

  • @k0ala
    It says { Error: listen EADDRINUSE :::8080, which in English would mean "error, address is already in use".
    So you got something else running on port :::8080 - try to restart the server, since there can sometimes be lingering processes when updating.

    • Sorry for late reply again. I rebooted the server and the error is still showing up

      • @k0ala
        I would recommend that create a new droplet - you can use the One-Click App called "NodeJS 6.11.0 on 16.04" and then you are up and running in seconds.
        We can continue to try to fix every single part of the current server, but it really needs a major overhaul and it would be far easier for you to setup a new droplet and copy all your data to that.

Have another answer? Share your knowledge.