Hi, I am logged in as a root user. I could enter /var/www/html. But I dont find the htaccess file? I installed WordPress 5.8 Ubuntu 20.04 with the one click installer. What do I have to do to access the htaccess file? Do I have to set up AllowOverride all? I cant get into /etc/apache2/apache2.conf as a root user. It says permission denied. Or do I have to install something?
Thank you in advance
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!
Accepted Answer
It’s strange that you can’t edit your Apache2 files however it’s not necessary to do so. The changes you are looking for can be added in your .htaccess file.
To be sure your DocumentRoot is /var/www/html
, you can check your Apache2 website’s conf like cat /etc/apache2/sites-enabled/000-default.conf
. In there you’ll see the DocumentRoot, it should be /var/www/html
but check to be sure.
Now, once you are sure the DocumentRoot path, create the .htaccess file
- touch /var/www/html/.htaccess
Don’t forget to change the file’s ownership
- chown www-data:www-data /var/www/html/.htaccess
Now, in the file, you can add the standard WordPress .htaccess info:
- # BEGIN WordPress
- <IfModule mod_rewrite.c>
- RewriteEngine On
- RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
- RewriteBase /
- RewriteRule ^index\.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
- </IfModule>
-
- # END WordPress
That should be it.
Hi there,
You don’t need to make any changes to the Apache config file as the AllowOverride
is already enabled in the Apache virtual host for the default site here:
/etc/apache2/sites-enabled/000-default.conf
You can create a new .htaccess
file with the following command:
touch /var/www/html/.htaccess
chown www-data: /var/www/html/.htaccess
Here is an example of a default .htaccess
file content that you could then add to the file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Another alternative way of quickly generating the file without manually creating it is to go to the wp-admin
-> click on settings -> then Permalinks -> change the permalinks settings and click save. This will automatically create a new .htaccess
file for you.
Hope that this helps!
Best,
Bobby
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.