How to Use ".wp-config.php.swp" to Create wp-config file

Tessando
Tessando used Ask the Experts™
on
I've got a client who's running Bitnami Wordpress using AWS Lightsail.

When I go to the page, it's completely white. I thought this was pretty unusual behavior so I did some Google-Fu and found a known permissions issues that has to do with Group and Ownership.

This requires adjusting the ownership of the wp-config.php file, a normal file that should be located at the root of Wordpress.

It's not.

Which is frustrating.

When I locate it using this command: locate wp-config.php

I find it in a swap file form: e.g. 2COMPANYNAME.com/.wp-config.php.swp

at

/opt/bitnami/apache2/var/cache/mod_pagespeed/v2/COMPANYNAME.com/http

How can I take that ".wp-config.php.swp" and move it to "~/apps/wordpress/htdocs", which is where index.php is for some reason and where I expected to find the "wp-config.php" file.

Thanks for your help.

Thom


...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Ah mod_pagespeed. The source of many a problem.

If you have a .wp-config.php.swp this is an editor swap file which might or might not be useful.

This file is a binary version of your file in a format only the original editor program can understand.

You can attempt recovery of your wp-config.php file like this.

# cd to the exact directory where this file lives, as some editors dislike absolute paths during recovery
cd .../2COMPANYNAME.com

# edit the file using the exact editor used before (likely vi) + follow recovery instructions.
# Likely this will be typing R + ENTER
vi wp-config.php

# If you followed the recovery instructions + now see the actual file contents, exit the editor by typing...
:wq

# You'll now have a copy of your wp-config.php file in some state, which will be better than nothing

Open in new window


Note: It's super rare for vi to die, unless to OOM Killer kills it or the machine reboots while vi is running.

In either case, you should still be able to see your wp-config.php file in the correct location.

If this is true, then you will remove the .swp file completely, as saving it may destroy the wp-config.php file your site is currently using.
TessandoIT Administrator

Author

Commented:
Thanks David. I love that VI trick and I am able to open multiple config files on the Clients server with VI, so we're good there.

What I can't seem to do is find the dang thing.

What do the commas mean in the results of this locate statement?

/opt/bitnami/apache2/var/cache/mod_pagespeed/v2/COMPANYNAME.com/http,3A/,2COMPANYNAME..com/.wp-config.php.swp,

Open in new window


In other words, when I go to "/opt/bitnami/apache2/var/cache/mod_pagespeed/v2/COMPANYNAME.com/" I cannot get to http, even as "sudo". I just haven't encountered those commas before.

Thanks!
Fractional CTO
Distinguished Expert 2018
Commented:
Ah... This is a cache file (/opt/bitnami/apache2/var/cache/...) so this file might show up when you do a locate + likely will be gone by the time you arrive.

Tip: If wp-config.php.swp shows up in your cache directory, this likely points to someone hacking your site.

Here's how this works.

1) People craft a URL which can access the wp-config.php.swp file.

2) This is likely a security flaw in bitnami packaging.

3) #2 allows *.swp files to actually be served by Apache (shudder... truly apocalyptic...), so if you happen to be editing wp-config.php + the hacker catches this file when it exists, the #2 security flaw actually provides this file to the hacker.

Note: This is why you see the file in your cache directory. If bitnami security was sensible, you should never see a .swp file being served.

BTW: Apache by default serves .swp files also... A serious security problem...

4) If you do updatedb + locate again, likely the file will be gone now out of the locate database.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today