nginx php5-fpm loading old php.ini file - nginx

I have a PHP-based site running off the usual Nginx and php5-fpm combination. The sites-available config has a few different server blocks in it, e.g. one for the main www.mysite.com and one for blog.mysite.com subdomain. Originally, when I first created the site, I set the auto_prepend_file PHP value in my php.ini (in /etc/php5/fpm/), to let's call it 'common.php'. However, I now don't want common.php included for the blog subdomain, so I removed auto_prepend_file from php.ini and added it to the sites-available for the www subdomain, via
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/mysite/app/lib/common.lib.php";
Nothing too fancy there. However, despite restarting both nginx and php5-fpm, I can still sometimes see common.php being included, generally after you've restarted nginx & php5-fpm, reloaded the page, then reload again, i.e. it's fine on the first reload.
When I do a phpinfo() when the file is included, I can see that PHP has loaded the correct php.ini file (i.e. the one I removed the auto_prepend_file from), but the auto_prepend_file value is still set to common.php!
Is there anything else I need to restart? Should I be looking for auto_prepend_file somewhere other than /etc/php5/fpm/php.ini? Thanks

Related

Getting 404 "Not Found" after messing with Apache's configuration

Earlier I was trying to set up HTTPS on mediawiki and followed a guide that said to remove "Listen 80" on the ports.conf Apache file. As soon as I did that the website went down and not its displaying a 404 error not found. I did add the Listen 80 line again but to no avail.
I'm running a linode VPS (Debian 10) with LAMP, Wordpress installed and now mediawiki.
I am new to the Linux environment so I'm not entirely sure what could be wrong, but I suspect there's a misconfiguration in the Apache files. When I initially installed Wordpress, I moved the entire site to www/html and deleted the Wordpress folder so it would load on my domain's main page. Everything was working perfectly fine until I changed that "Listen 80" line.
Any help would be appreciated.
Things I tried:
Restarting apache
Checking the several configuration files and making sure the directories are correct
You have to set up "Virtual Host" correctly. When you put "Listen 80" into you configuration file, You need to set up more things there, like path to the folder (directory) where you have stored all your web stuff.
This is how my apache configuration file looks like:
/etc/apache2/sites-enabled/001-custom.conf
listen 8081
<VirtualHost *:8081>
ServerAdmin webmaster#localhost
DocumentRoot /web/CustomDirectory
ErrorLog /weblogs/8081e.log
CustomLog /weblogs8081c.log
</VirtualHost>
Hope this helps :)

WAMP server not processing index files (shows directory listing instead)

Suddenly WAMP decides to give me a directory listing instead of processing the index files. For example if I go to http://localhost, it gives me a directory listing then I can click index.php and it will load.
But as for my dev sites, they are on wordpress and simply clicking the index file does not work in this case. Any ideas on what may have gone wrong where it doesn't seem to be processing the files properly? It was working yesterday and haven't changed any settings, so I'm at a loss
Check your Apache conf file. You should have something like :
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>

Nginx - change the welcome page

I started an nginx container and would like to modify the content of the default page.
I changed the file /usr/share/nginx/html/index.html
Unfortunately nginx still shows me the usual welcome page when I curl localhost.
How would I change the default page in nginx?
I disabled cache in nginx via sendfile off;
Probably you did something like this in your Dockerfile:
COPY ./index.html /usr/share/nginx/html/index.html
Try this instead:
COPY ./index.html /usr/share/nginx/html/

Redirect loop on wp-admin or wp-login.php

I put together a quick WordPress site locally using MAMP, then checked it into an SVN repo. I then checked it out on to my development server.
I didn't change anything except to run the search and replace tool script from Interconnectit to updated the URL of the site in the database on the server.
Initially, I got a 500 server error. Checking the logs, I discovered that this "SoftException" was because index.php was writeable by group - the permissions were 664. No problem - a quick change of permissions to 644 sorted that. So now the frontside was working.
However, strangely, the admin side of the site did not work. It just produced an endless redirect loop in all browsers.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
Nothing has changed since the local development version. The htaccess file is just a standard WordPress one. Nothing weird... still working fine locally.
So what's going on?
For whatever reason /wp-admin/ path causes a redirect loop, but /wp-admin/index.php does not. As such, we can use .htaccess to redirect the /wp-admin/ path to /wp-admin/index.php by adding the following line to your .htaccess file after "RewriteBase /" line like this:
RewriteBase /
RewriteRule /wp-admin/ /wp-admin/index\.php [L,P]
It worked for me like that.
You final .htaccess would probably look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule /wp-admin/ /wp-admin/index\.php [L,P]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Checking the permissions of wp-login.php revealed that they too had somehow been set to 664 - the same permissions that caused index.php to fail and caused the 500 server error.
I changed the permissions of wp-login.php to 644 and hey presto, the WordPress login page showed up.
But on logging in, another redirect loop. So, once again, looking at /wp-admin/index.php, the permissions were 664 rather than 644.
Fixing them led to problems with the next files in line - the dashboard was a right mess. One by one, changing from 664 to 644 corrected the issues (/wp-admin/load-scripts.php, /wp-admin/load-styles.php).
So it became obvious that a recursive change of permissions was the only way to sort things out.
My UNIX isn't exactly top notch, but this appears to have worked (running from Mac OS X Terminal). I ran it from the root directory of this WP install.
find . -type f -perm 664 -print -exec chmod 644 {} \;
There might be a better command, but I understand this to mean "find all files with 664 permissions and change them to 644".
It has fixed my problem.
If you're using Cloudflare you might want to try adding this to the TOP of your wp-config.php file:
define('WP_SITEURL', 'https://www.example.com');
define('WP_HOME', 'https://www.example.com');
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if(isset($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https')){
$_SERVER['HTTPS']='on';
}
It's important that you add it to the top of the wp-config.php file or you'll end up with "Sorry, you are not allowed to access this page" error messages.
Credit: https://www.meltajon.com/dev/wordpress-wp-admin-redirect-loop-with-cloudflare-ssl
if your webserver is nginx,you may need check the configure file of your nginx. If there is
if (!-f $request_filename){
rewrite ^/(.+)$ /index.php?$1& last;
}
Replace these lines with
try_files $uri $uri/ /index.php?$args;
See also Nginx Pitfalls , WordPress wiki page on nginx
with nginx config I had originally only this line and experienced the same redirect issue:
location / {
try_files $uri /index.php$is_args$args;
}
after adding this everything was fine:
location /wp-admin/ {
index index.php;
try_files $uri $uri/ /index.php$args;
}
If you are useing Cloudflare, from SSL/TLS tab of your Cloudflare account, select Full encryption. It will solve the issue.
I just had to flush my redirects.
Since I couldn't access the Admin I added this to the top of my functions.php file:
flush_rewrite_rules();
exit;
Saved it and refreshed my site.
Then remove the code from your functions.php file and then refresh again.
That did it for me.
I also think it might be a good measure to resave your permalinks.
PS. I think the main issue came from theme-my-login as it was redirecting to /login.
I was getting DoS pages when trying to publish in my WP site. I found advice that changing permissions in the function.php file to 600 could solve the issue, also to add to that file a script snippet . It was a WP help page. I was able to get to the publishing in a work-around way. Still have the DoS when I try to open the editor.
My problem was that the hardisk was full. Trying to log into the wordpress administration panel was redirecting me to wp-login.php. I was able to log in again the moment I deleted some files.
To remove the lines
define('DOMAIN_CURRENT_SITE', 'www.sitename.de');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
from wp-config.php should do the job.
These lines are not necessary for a multi
In the sites-enabled folder you will need to edit the configuration for your site and add the multisite redirection rules. For Ubuntu 14.04 you will be able to find the path under /etc/nginx/sites-available
Add the following block in your server block and you should be able to avoid the infinite redirection loop.
#Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
I had a similar issue in my case it was due to restoring a db script that was created with WP Migrate DB. The script had merge tags in like "## DEV URL ##" which i needed to fix before running the script on mysql and pointing the wp-config.php to the correct database.
In my case it was Apache's DirectoryIndex issue. The wp-admin was being accessed by wp-admin/index.php but not with wp-admin and showing ERR_TOO_MANY_REDIRECTS.
It sounds like Apache's DirectoryIndex may be set "incorrectly". Try resetting this at the top of your .htaccess file:
DirectoryIndex index.php
See the full answer here.
Can't access admin dashboard with wp-admin without /index.php after it
If you have nginx, then also check your index config. As for me I had an issue: I've set the following:
server {
server_name _;
root /var/www/html;
index /index.php;
}
So as you see I've set index.php with trailing slash, which means that all rewrite requests will go to the index.php in document_root. For WP it's wrong, because wp-admin directory has its own index.php
The above answers got me pretty close. In our particular case, someone at some point had added in some rules to the htaccess file in the site root and in the admin folder to block traffic from everywhere except some whitelisted IPs (when attempting to access wp-admin).
Example:
<Files wp-login.php>
order deny,allow
Deny from all
# Allow from this IP address
allow from 123.45.67.89
</Files>
Adding our IP to the whitelist in both files remedied the problem.
I faced same problem after I restore backup from other server , it was promising issue I solve it this way .
chown -R www-data:www-data /var/www
chmod -R g+rwx /var/www
Where /var/www the place to store website files , replace it with suitable path according to your configuration , e.g /usr/share/nginx/www << default Nginx

Disable all parent htaccess

I have wordpress installed in the root of my website public_html
Although I have other folder inside a projects folder running their own websites.
The .htaccess in the wordpress folder (parent-most folder) might be causing issues for the inside folders.
Is there a way, I can mention for a folder not to look any higher for htaccess files ?
DETAIL:
The two main issues I am currently having our
- if I set the status code to 500, I am get redirected to my home page (index.php)
- if a page is not found, it gets redirected to index.php
Thanks.
Put this code in your .htaccess under DOCUMENT_ROOT directory (just above your wordpress rewrite stuff):
RewriteRule ^subfolder(/.*|)$ - [L]

Resources