I am trying to configure a Wordpress project on my localhost, but when I open the browser on localhost
I only see the files in the root of my wordpress project.
If I click on index.php
or access localhost/index.php
it executes the PHP as expected.
I have installed apache 2.4
, php 7.2
and php-apache 7.2
.
My project is in /srv/http/mysite
:
The relevant lines in /etc/httpd/conf/httpd.conf
file:
LoadModule rewrite_module modules/mod_rewrite.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Note: Since httpd.conf is very big I showed only the lines I know to be relevant. If this is not enough I can upload the entire file on pastebin.
The file /etc/httpd/conf/extra/httpd-vhosts.conf
:
<VirtualHost *:80>
ServerAdmin webmaster@test.localhost
DocumentRoot "/srv/http/mysite/"
ServerName test.localhost
ServerAlias test.localhost
ErrorLog "/var/log/httpd/test.localhost-error_log"
CustomLog "/var/log/httpd/test.localhost-access_log" common
<Directory "/srv/http/mysite/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The file /srv/http/mysite/.htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My /etc/hosts
file:
127.0.0.1 localhost
127.0.1.1 mycomputer_name
127.0.2.1 test.localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
About this last file I noticed that if I remove the <IfModule ...>
and </IfModule>
site it works and redirects to index.php
, but I would prefer not to change this file since it works the way it is on the remote server that uses ubuntu
.
The main question is why this is not working but I would be also happy to know what the <IfModule mod_rewrite.c>
is doing and why it is being ignored even though LoadModule rewrite_module modules/mod_rewrite.so
is enabled.
I know this is not an easy question but I have not found anyone with this same problem on the web. I will be very grateful for any help.