Question

Htacces not found Ubuntu 20.04 Apache 2 Wordpress 1 click installation

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


Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
December 30, 2022
Accepted Answer

Hi @neverdevelopment,

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

  1. touch /var/www/html/.htaccess

Don’t forget to change the file’s ownership

  1. chown www-data:www-data /var/www/html/.htaccess

Now, in the file, you can add the standard WordPress .htaccess info:

  1. # BEGIN WordPress
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine On
  4. RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  5. RewriteBase /
  6. RewriteRule ^index\.php$ - [L]
  7. RewriteCond %{REQUEST_FILENAME} !-f
  8. RewriteCond %{REQUEST_FILENAME} !-d
  9. RewriteRule . /index.php [L]
  10. </IfModule>
  11. # END WordPress

That should be it.

Bobby Iliev
Site Moderator
Site Moderator badge
December 30, 2022

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel