Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Issues when trying to serve WordPress directory as main site |
|
Author |
|
stardustvega
Joined: 28 Feb 2023 Posts: 14
|
Posted: Mon 09 Sep '24 13:47 Post subject: Issues when trying to serve WordPress directory as main site |
|
|
I am currently running Apache in a local environment on Windows 11.
At this point, I have my virtual host working, my local SSL certificate working, and WordPress installed.
At the moment, you have to go to https://test-1.local/wordpress to see my WordPress, and I want to make it so that you see the WordPress site if you go to https://test-1.local.
From looking at https://httpd.apache.org/docs/2.4/rewrite/avoid.html in the Apache documentation, I understand that we want to try and avoid using mod_rewrite where possible, so I've been trying to work out how to do this without using mod_rewrite.
Here is my VirtualHost configuration as is:
Code: | <VirtualHost *:443>
ServerName test-1.local
DocumentRoot "${DOCROOT}/test-1"
<Directory "${DOCROOT}/test-1/">
Require all granted
</Directory>
<IfModule fcgid_module>
FcgidInitialEnv PATH "${PHPROOT}/php-8.3.9"
# Location php.ini:
FcgidInitialEnv PHPRC "${PHPROOT}/php-8.3.9"
<Files ~ "\.php$>"
Options ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}/php-8.3.9/php-cgi.exe" .php
</Files>
</IfModule>
SSLEngine on
SSLCertificateFile "${DOCROOT}/test-1/ssl/test-1.crt"
SSLCertificateKeyFile "${DOCROOT}/test-1/ssl/test-1.key"
</VirtualHost> |
Stuff I've Tried: DocumentRoot
I tried just changing the DocumentRoot like this:
Code: | DocumentRoot "${DOCROOT}/test-1/wordpress"
<Directory "${DOCROOT}/test-1/wordpress/">
Require all granted
</Directory> |
This kinda works but a bunch of stuff isn't loading correctly, like the themes. When I look at the access log, it shows that it's getting 404 errors back on all the files it needs from /wp-includes and /wp-content, even though they *are* there. For example:
Code: | 127.0.0.1 - - [09/Sep/2024:06:31:52 -0500] "GET /wordpress/wp-includes/blocks/navigation/style.min.css?ver=6.6.1 HTTP/1.1" 404 196 |
However, that file does exist in that location so I don't know why I'm getting a 404 error. I'm wondering if maybe the alias is making it actually look for wordpress/wordpress/wp-includes... ?
I tried throwing
Code: | Options FollowSymLinks |
Inside my Directory directive, but that doesn't seem to change anything.
Stuff I've Tried: Alias
Next, I tried switching to aliasing the directory. I made sure mod_alias was enabled in my main httpd.conf file.
After the DocumentRoot directive inside my VirtualHost, I added:
Code: | Alias "/" "/wordpress" |
This just results in everything returning a 403 Forbidden error.
I also tried changing my Directory statement to:
Code: | <Directory "${DOCROOT}/test-1/wordpress">
Require all granted
</Directory> |
But no dice there either (either with or without the FollowSymLinks option).
So I'm a bit stuck on how to proceed. Do you just have to use mod_rewrite if you're using WordPress? Or am I missing something here? |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Mon 09 Sep '24 18:31 Post subject: |
|
|
Hi,
It seems to me that the base URL is hard-coded in the WordPress database. |
|
Back to top |
|
stardustvega
Joined: 28 Feb 2023 Posts: 14
|
Posted: Tue 10 Sep '24 12:05 Post subject: |
|
|
Ah, yeah that seems to be the source of my problems.
When started, WordPress saves the path to its current directory with:
Code: | if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
} |
This means that I'm getting a 404 error because in some cases files are being retrieved through the path [my absolute path]/wordpress/wordpress/wp-content/...
Now I'm messing with mod_rewrite and trying to get it to remove the extra wordpress when necessary... |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 13 Sep '24 15:29 Post subject: |
|
|
You can add it to your wp-config.php
Code: |
define('WP_SITEURL', 'https://test-1.local');
define('WP_HOME', 'https://test-1.local');
|
or change in the database site_url and home (wp_options)
If you move often from dev to prod or vise versa you can use "All-in-One WP Migration" plugin. It is pretty slick and can replace that URL for the export. |
|
Back to top |
|
stardustvega
Joined: 28 Feb 2023 Posts: 14
|
Posted: Tue 17 Sep '24 12:06 Post subject: |
|
|
Quote: | You can add it to your wp-config.php |
Oh! I didn't think to look more deeply into wp-config after I found the initial ABSPATH definition. That worked perfectly.
Quote: | If you move often from dev to prod or vise versa you can use "All-in-One WP Migration" plugin. It is pretty slick and can replace that URL for the export. |
Thank you for the info, that's good to know! Right now, I'm just messing around in my local environment to learn things but it's always good to have tips like that for the future.
Just to leave clear info for anyone who looks at this in the future, this worked with the following setup.
My ending Virtual Host looked like this:
Code: | <VirtualHost *:443>
ServerName test-1.local
DocumentRoot "${DOCROOT}/test-1/wordpress"
<Directory "${DOCROOT}/test-1/wordpress/">
Require all granted
</Directory>
<IfModule fcgid_module>
FcgidInitialEnv PATH "${PHPROOT}/php-8.3.9"
# Location php.ini:
FcgidInitialEnv PHPRC "${PHPROOT}/php-8.3.9"
<Files ~ "\.php$>"
Options ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${PHPROOT}/php-8.3.9/php-cgi.exe" .php
</Files>
</IfModule>
SSLEngine on
SSLCertificateFile "${DOCROOT}/test-1/ssl/test-1.crt"
SSLCertificateKeyFile "${DOCROOT}/test-1/ssl/test-1.key"
</VirtualHost> |
And then I added the two lines James Blond indicated in wp-config like this:
Code: |
/* Add any custom values between this line and the "stop editing" line. */
/** Custom configuration to change home location */
define('WP_SITEURL', 'https://test-1.local');
define('WP_HOME', 'https://test-1.local');
/* That's all, stop editing! Happy publishing. */ |
|
|
Back to top |
|
|
|
|
|
|