Hi
I’m trying to follow along with this guide How To Set Up mod_rewrite for Apache on Ubuntu 14.04
I get to ‘Step 3 — Setting Up .htaccess’
I run this command
sudo nano /etc/apache2/sites-enabled/000-default.conf
Which opens 000-default.conf
The guide says
Inside that file, you will find the <VirtualHost *:80> block on line 1. Inside of that block, add the following block:
/etc/apache2/sites-available/default
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
The guide then says
Your file should now match the following. Make sure that all blocks are properly indented.
and it shows this code:
/etc/apache2/sites-available/default
<VirtualHost *:80>
<Directory /var/www/html>
. . .
</Directory>
. . .
</VirtualHost>
The instruction in the previous step says put all the code inside the the <VirtualHost *:80> block. Yet the example shows part of the code /etc/apache2/sites-available/default is outside the <VirtualHost *:80> block.
Confused?
After following the guide, 000-default.conf looks like this:
<VirtualHost *:80>
/etc/apache2/sites-available/default
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# 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 www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# 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
Restart the server with this: sudo service apache2 restart
I get an error message, plus my website shows a 500 internal error:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
Not sure what that means, but I’m pretty sure the text I saved in 000-default.conf is wrong.
If I delete this and restart the server, no error message and I can access my website:
/etc/apache2/sites-available/default
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
What am I doing wrong?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Directory directive is inside of <VirtualHost *:80>.
<VirtualHost *:80> means that you are opening VirtualHost block.
</VirtualHost> means that you’re closing Virtual Host block you opened with above block.
Every other directive that you have between this two blocks (<VirtualHost *:80> and </VirtualHost>) is inside that block.
I’m not sure if you added this by mistake: /etc/apache2/sites-available/default and line 2, but it should not be there. That means to be label and not added to file.
So your correct file should be:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# 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 www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# 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>
Save file, exit editor and make sure you restart Apache!
- sudo systemctl restart apache2
If problem persist you can do config test:
- sudo apachectl configtest
It should return you is syntax OK or not.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.