XMAPP - PHP - Error 400 - php

So, this question has probably been answered before but i have changed ports in my conf files which most other posts has not. I'm suspecting this is why it won't work.
So, first i had a problem where skype was using the ports xmapp used, so i changed them to : 8080 and 4433. I also changed server name to : localhost:8080 and www.example.com:4433
When i try to go to localhost:4433 using google chrome i get :
Error 400
"Bad Request!, Your browser (or proxy) sent a request that this server could not understand."
And when i try with just localhost i get a white page.
And when i try t go to phpadmin "localhost/phpmyadmin"
it displays a white page.
Both mySql and Apache servers are running without any errors.
Any idea why and how to fix this problem? I've spent 15 hours now fixing 3 different errors.

actually you have change this port at two places in httpd.conf file,i.e
1) Listen 80
2) ServerName localhost:80
at the above places the port value should be 4433, as per your changes

Old question, but I had this error start suddenly to my XAMPP instance on WIndows 7.
It started when I was doing a cleanup and removed a folder that was referenced as a redirect in the .htaccess file.
e.g.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
If the folder public is removed/renamed, this error will start to occur, even with the simplest of PHP or HTML files being requested.
I fixed by removing the .htaccess - when I need it again I'll add it back in with the right paths.

Related

Wordpress 404 no found on all pages except the homepage

I've got a 404 no found on all pages except the homepage in my wordpress.
It didn't make this mistake on the pre-production server, but in production. I migrated the site from preprod to prod with duplicator's plugin.
The production server is a vps ovh that I installed myself. It use letsencrypt for https. It uses a ufw firewall and openSSH and WWW Full are allowed. My apache server does not detect an error with sudo systemctl status apache2.
I've been following some topics on it, like changing the permalinks settings, when I check "Default" and save, I don't get error 404 on my other pages, it works. I noticed that in this case the content of my .htaccess file was erased. When I reset my default permalinks settings, I get the error again and I can no longer access my pages (except the homepage).
In the general settings of wordpress, the web address of wordpress is https://www.abysolutions.com and the web address of the site is https://www.abysolutions.com. In wp_options table, the values of siteurl and home are https://www.abysolutions.com.
On ovh in the area dns my domain abysolutions.com has this entry: A 146.59.234.157. However, there is no A entry for www.abysolutions.com.
Here are some configuration files :
/etc/www/apache2/sites-available/abysolutions.conf :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName abysolutions.com
ServerAlias www.abysolutions.com
DocumentRoot /var/www/abysolutions
<Directory /var/www/abysolutions>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/abysolutions-error.log
CustomLog ${APACHE_LOG_DIR}/abysolutions-access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =abysolutions.com [OR]
RewriteCond %{SERVER_NAME} =www.abysolutions.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
This file is enabled with sudo a2ensite abysolutions.conf.
I disabled default file sudo a2dissite 000-default.conf.
My .htaccess on /var/www/abysolutions : (when my permaliens settings in enabled)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I did sudo chown -R www-data:www-data /var/www/abysolutions and sudo chmod -R 755 on it.
I restarted the server with sudo systemctl reload apache2 and the rewrite mod is activated with sudo a2enmod rewrite.
I installed all the php extensions required for wordpress by following this link : https://wordpress.org/support/topic/which-php-extensions-are-needed-to-run-a-fully-operational-wordpress-site/
But it still doesn't work...
It's not the first time I install a vps and put a wordpress on it, and I always do the same steps. And then for some reason it gets stuck. The only noticeable difference I see with my previous installations is that when I migrated the site with Duplicator it offered me https://www.example.com instead of https://example.com in my previous installations. What I don't understand is why my url appears with www.
EDIT :
In the health of the site, I noticed 2 critical errors :
An active PHP session has been detected:
A PHP session was created by a session_start() function call. This interferes with the REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.
and
Your site was unable to complete the closure request:
Looping requests are used to launch scheduled events, and by theme and extension editors to check the stability of the code.
The loopback request on your site failed, which means that the features that rely on these requests are not currently working as they should.
Error: cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received (http_request_failed)
And in the recommended improvements :
The REST API encountered an unexpected result:
The REST API is one way for WordPress or other applications to communicate with the server. An example is the editor's screen, which is used to display and save your publications.
The call to the REST API returned the following unexpected result: (404) 404 Not Found Not Found The requested URL was not found on this server. Apache/2.4.38 (Debian) Server at www.abysolutions.com Port 443
Background updates may not work properly:
Unable to confirm if the wp_version_check() filter is available.
EDIT 2 :
So by comparing my .htaccess with the one of my preproduction server, I noticed that some rules added by the SimpleSSL plugin were missing. I also noticed that in my /etc/apache2/sites-available/abysolutions-le-ssl.conf file, the rules were missing.
I think it is this last solution that corrected my error. Bye!
Visit your site:
https://domain.tld/wp-admin/options-permalink.php
Click Save.
If it doesn't work, change the URL settings to Plain, click save. Then if it works, change back settings as you want.

How to get redirect working (.htaccess) when using PHP -S localhost server?

I used xampp in the past in order to develop websites on a local computer, but I recently found it less cumbersome to simply start a server using the PHP -S localserver:8000 where 8000 is the port number. I managed to get phpmyadmin working that way and access databases. So all was fine ... until I tried to re-use redirecting rules within a .htaccess file.
The rules work well on the my web provider's servers, but it doesn't work on localhost. I assume there's something to do in order to turn the re-write rules on but since I am not longer using xampp, I don't know if there's still something like Apache running in the background, etc. If someone has experience with this setup, I would like to know how or if this can be be done.
EDIT
The redirect is basic:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule lessons/(.*)$ page.php?url=$1
And to make the question more meaningful (addressing some of the comments below), I think Finwe answered my question rightly, that is: "this doesn't work with the PHP approach, .htaccess is specific to Apache".
My question wasn't about "what alternative solution do I have". The solution I would use is probably to go through a combination of AJAX/PHP to solve the limitation but that's surely not the most straightforward workaround.
PHP's internal server does not recognize .htaccess files. That is a privilege of using Apache server.
The redirects must be a part of your PHP application to retain them across all platforms.
With PHP internal server, you can run it with a PHP file parameter.
If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.
PHP -S localserver:8000 router.php
The script could then replace the htaccess file checking and "routing" requests to lessons/.
For more complex applications I would suggest using a "real" webserver such as Apache or nginx as the built-in server has more limitations, such as hanging on external HTTP requests, as it is only single threaded.
This is what I do to get htaccess working properly on localhost. I create a virtual host for each app am building
<VirtualHost *:8000>
ServerName app.local
DocumentRoot "C:/path/htdocs/app"
<Directory "C:/path/htdocs/app">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
With this, I can now access my app from my browser using the local domain name app.local. I found out that htaccess works well following this which is apparently the same thing with online server you access with a domain name

CakePHP missing controller on EC2

I have a Cake 2.3.8 app that works fine on localhost and I uploaded it to an Ubuntu 12.04 EC2 instance, but on the index/home file I'm getting a "Missing Controller" error.
The CSS, header and footer load fine on the home/index page, but it can't seem to find the controller. Every single other page/controller of my app won't even load, I get a 404 error.
I tried this but my issue still persists.
What else should I look for that would cause it to not find the controller and not even load any other pages?
Update
I moved my contents to /var/www so it would be accessed through my-ec2-instance.com. When I go to my-ec2-instance.com/index.php the page displays (which is PagesController/home.ctp). However, anything else gives a 404 error. Modrewrite is also enabled
I can also access my actions when I reference index.php, although it displays in mobile format for whatever reason (I have a responsive template). Ex: www.my-ec2-instance.com/index.php/users/login works, although it's in a mobile format
www.my-ec2-instance.com/index.php //works
www.my-ec2-instance.com/index.php/users/login //works, but mobile format
www.my-ec2-instance.com/users/login //404 error
Please connect your instance via putty then press
sudo nano /etc/httpd/conf/httpd.conf
Check the given below line and remove the # tag
LoadModule rewrite_module modules/mod_rewrite.so
After that you can replace:
AllowOverride None
with
AllowOverride All
Note: AllowOverride None -> AllowOverride All.
From Crtl+X then press Y then press Enter (you can use this command according to your OS)
After that you can execute the command in putty
sudo service httpd restart
Then check your .htaccess file (please make sure your .htaccess should be correct) for cakePHP .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Sounds like an issue with your .htaccess file which is what would properly rewrite short URLs & handling controller routing.

Getting an error when I visit http://localhost

I am trying to access localhost on my xampp via the Chrome browser but I get this error message:
Object not found!
The requested URL was not found on this server. If you entered the
URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
Apache and MySQL are turned on so I don't understand.
You can access "localhost" just fine.
The "404: file not found" error indicates the server can't find the requested file once you've connected to localhost.
ADDENDUM:
Maybe try to create a regular html file called test.html in one of
your vhosts that is not working. Then try to visit that url. That
should give you some clue as to what may be the problem. – Gohn67
This is good advice. Try it. Specifically:
1) Create the following five files:
C:/xampp/htdocs/dummy-host.localhost/test.html
C:/xampp/htdocs/my/test.html
C:/xampp/htdocs/launcher/public_html/test.html
C:/xampp/htdocs/website/httpdocs/test.html
C:/xampp/htdocs/my/test.html
2) Make sure each of these directories exist, and each has a "test.html" with the words "TESTING 1...2...3" in it
3) Try each of these five URLs in your browser:
http://localhost/test.html
http://itutormaths.web/test.html
http://itutormaths.mod/test.html
http://itutormaths.hub/test.html
http://my.itm/test.html
4) Report back the exact error you get from each browser URL
Navigate here:
http://localhost/
If that works, everything is okay.
Paste wordpress to xampp/htdocs, and you should not get any error.
I had a similar issue and this is how I resolved it:
Open the httpd:conf file on the Apache module in XAMPP (click the Congif button)
Scroll through the file - after the first set of comments (#) there is a line of code which says 'Listen 80'. Change this to 81 (or whatever other port you want to use).
Open web browser and explicitly define the port in the web address:
127.0.0.1:81
The may or may work for you; I initially had the issue that Apache wouldn't start at all, which is why I changed the port number (couldn't be bothered to figure out which service was using port 80 - if you want to you can use the command netstats -a or netstats -b in command prompt to figure it out)
Hope this helps
I just encountered this and solve this by creating .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /yourfoldername/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Apache site root for development directories on localhost

I think I'm missing something and don't think I really understand how rewriteBase works.
The problem I have is that I have a production site where the site is in the root directory yet I have my development site in a localhost subdirectory. Eg http://www.sitename.com/ vs http://localhost/sitename/
If I have for example an images folder I want to reference the images from the site root by using the initial slash in the href. Eg Using a relative href (without the initial slash) is not an option. This will work on the production site but the development site is looking for http://localhost/images/imagename.jpg instead of http://localhost/sitename/images/imagename.jpg
So I thought all I needed to do was setup the following in my .htaccess file to force the site root to my subdomain within the development environment:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /sitename
But this still uses localhost as the site root instead of localhost/sitename.
Can anyone please give me some pointers?
-------------------------EDIT---------------------------
I stopped trying to do this in the .htaccess file and tried to just use the html command but this also didn't work.
In the end I set up Virtual Hosts in Apache on the local server but it seems like such an awful lot of overkill to just change the site root. I'm also concerned that other developers on the LAN network won't be able to access the site properly via the virtual host.
I'm really needing some 'best practice' advice please on setting up a workable development environment in WAMP.
RewriteBase alone, basically, tells Apache where to apply the RewriteRules. Here you don't have any. By the way, you can either remove the RewriteBase directive altogether, or change it to:
RewriteBase /
The following two lines should get it to work for your development environment only:
RewriteCond %{ REQUEST_FILENAME } !-f
RewriteRule ^(.+)$ /sitename/$1 [L,QSA]
These two directives mean: "if the requested file does not exist (-f), and only in that case, rewrite the url prepending /sitename/ to the requested URI ($1)".
For more info you can have a look at Apache mod_rewrite docs and Apache URL rewriting guide.

Categories