1

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.

VinGarcia
  • 1,015
  • 12
  • 19
  • Possible duplicate of [index.php not loading by default](https://stackoverflow.com/questions/2384423/index-php-not-loading-by-default) – Dieter Donnert Jan 26 '18 at 22:34
  • I have trouble finding this answer you mention, because problems with Apache on Arch Linux are usually different from what you would see in other distros. So, I would argue that keeping this question would be beneficial for Arch Linux users, but I am not an expert on stackoverflow rules, I will agree with your decision if you think this should be deleted. But it is likely that the answer you mention won't be spotted by other Arch users. – VinGarcia Jan 27 '18 at 19:24

2 Answers2

4

Apache needs to be setup to recognize your index files (in this case index.php)

Do you have the following in your Directory

DirectoryIndex index.php

So

<Directory "/srv/http/mysite/">
    DirectoryIndex index.php
    AllowOverride All
    Require all granted
</Directory>
KaffineAddict
  • 436
  • 2
  • 11
0

In httpd.conf you should have something like...

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>

This would be your catch-all fall-back.

And then in your httpd-vhosts.conf one of many site descriptions might look something like...

<VirtualHost *:8080>
    ServerAdmin admin@siteName.com
    DocumentRoot "e:/Stack/Sites/siteName/web"
    ServerName siteName
    ServerAlias siteNameUser
    <Directory "e:/Stack/Sites/SiteName/web">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "logs/siteName.error.log"
    CustomLog "logs/siteName.access.log" common
</VirtualHost> 

Note: The DirectoryIndex index.php in httpd-vhosts.conf site declaration is unnecessary if you included the fall-back defaults in httpd.conf

If you are not wanting to use default port 80 then in either file have something like: Listen 8080

For localhost I use: in httpd.conf... Listen 127.0.0.1:8080 and in httpd-vhosts.conf Listen 8080

In your hosts file you will need to define something like... 127.0.0.1 siteName siteNameUser www.siteName.com

Currently using: Apache/2.4.33 (Win64) PHP/7.2.4 ~ MySql 5.7.22 homebrew stack. The httpd-vhosts.conf example portion is for Drupal 8.x - For WP your DocumentRoot and Directory will differ.

You can listen on multiple ports such as 8080 for dev, 8081 for test, 8082 for prod. Also you can have many different site definitions in your httpd-vhosts.conf file.

I prefer to define all sites in httpd-vhosts.conf, but you could just place them in httpd.conf

Jim
  • 41
  • 4