CakePHP application cannot start in localhost - php

I'm trying to get a CakePHP application to work. I use xampp and put my application files in /xampp/htdocs. For .htaccess configuration I refer to http://book.cakephp.org/1.2/view/37/Apache-and-mod_rewrite-and-htaccess . After that I'm trying to run my application, but I've got this message in browser.
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
All my other applications in which I have not used the CakePHP, runs well on localhost, without any errors. I think the problem connected with .htaccess. Any suggestions ?
EDITED
My .htaccess files
**/xampp/htdocs/app/webroot/.htaccess**
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
**/xampp/htdocs/app/.htaccess**
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
**/xampp/htdocs/.htaccess**
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

I think your .htaccess files look correct. You might need to tell Apache where the webroot of your app is. Try adding a vhost entry in your Apache configuration
inside \xampp\apache\conf\extra\httpd-vhosts.conf
try adding something like:
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:\xampp\htdocs\app\webroot <-(use the actual path here)
</VirtualHost>
The you should then be able to access the CackPHP app by visiting http://localhost
Be sure to remove any other VirtualHost blocks that might conflict, although if you are working with a fresh copy of XAMPP everything in this file will be commented out.
Don't forget to restart Apache for the change to take effect.

Related

Apache2 Module Rewrite it is not working as it should

I created an MVC system in PHP and use the Apache Rewrite module to protect some folders and compose URL's.
I created the base on my development machine that I use Xampp and I even used the same system on an online server (client) and everything works fine.
But I want to have this same MVC system on the server that we set up in the company where I work for other developers to use it, but this server is not working properly.
On the server giving this problem, I have installed Ubuntu 20.04 (Desktop), Apache 2, PHP 7.4.13 and MySQL. I have already enabled the Rewrite module.
And I'm using the same .htaccess that I'm using both on my machine (Windows) and on the server that is online (public webserver) Linux.
Below the .htaccess files I'm using
That first .htaccess file I use to always redirect the client into the public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
This second is inside the public folder and is to compose the URL
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /criate/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
The latter is inside the App folder and I use them to not have access to that folder
Options -Indexes
My Apache default.conf file
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow, deny
allow from all
Require all granted
</Directory>
But what is happening, when accessing the project url, let's assume it is: https://api.aplication.com
Works perfectly well, takes me to the application home with all right. But when I click the login button, for example. Give me the following error.
Not Found
The request URL was not found on this server
But there is, because I made a copy of the project that is working both on Windows and on the online server that is Linux too.
What configuration do I have to see and analyze to resolve this issue?
In phpinfo it says what module is active. Thanks
I already found what I was doing wrong in the .htaccess files, follow what I changed, that in all .htaccess files.
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
Options -Multiviews
RewriteEngine On
RewriteBase /criate/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
It was just removing the conditions that check if the module is active or not, I will study further to find out how to do these conditions in LINUX.

Nette framework Url not working on localhost

The PHP Nette framework, Url is not working on localhost. On the live server it is working fine but when I installed it on localhost from the latest backup from hosting server it does not work.
My .htaccess file is as:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ /www/$1 [L,NE]
</IfModule>
My Localhost URL on Wamp which the home page is working properly
http://localhost/ongoingclients/www/www/
But other urls are not working.
what does it mean that it is not working? It shows 404 from apache?
try to check that
mod_rewrite in apache is enabled
AllowOverride in apache vhost settings is set to All
The above issue is resolved by .htaccess of rule RewriteBase
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ongoingclients/www/www/
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\. - [F]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]
</IfModule>
Got success, thank you.

Phalcon framework displays index of page instead of application

I wanted to use learn phalcon so i tried installing it on ubuntu. I did everything like in tutorial and i can see phalcon in phpinfo(). I made sample project like in tutorial with following htaccess files but all I can see when typing localhost/tutorial is index of /tutorial instead of Hello! message
#/tutorial/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ((?s).*) public/$1 [L]
</IfModule>
#/tutorial/public/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
Try removing the <br> tags from your .htaccess files. If the previous doesn't work check your apache configs for the localhost, maybe it doesn't AllowOverride.
Also you can use the steps from here to create a virtual host on apache with it's document root set to the path of tutorial folder.
Everytime you change the configs of apache, remember to do a reload or a restart of the apache service.

Laravel 5 needs index.php using Apache virtual host

When I load pages that are not root, the page won't load without index.php before the route. The error I get:
Not Found
The requested URL /login was not found on this server.
Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
To start with I have a virtual host file containing:
//also tried adding DirectoryIndex here before <directory>
<directory /var/www/mydomain.com>
DirectoryIndex index.php
AllowOverride ALL
</directory>
and a .htacces in my public with :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have another domain with the same .htaccess and appache config on the same server and it works fine. Also I did restart apache. If I use phpinfo on my index.php/route page I see at Loaded Modules:
mod_rewrite mod_setenvif
When running the website localy with xampp everything works fine.
For hours i'm trying now but I can't fix it or find any error (logs are empty) or any solutions that I haven't tried yet.
Edit:
Im using Ubuntu Ubuntu 14.04 x64 on a digital ocean VPS. And I tried turning it on and off again (as suggested). PHP Version 5.5.9-1ubuntu4.9. I followed this tutorial to config everything (except the direcoty part). I changed the location of the apache log and a file error.log is created on the given directory but no errors are in it.
My currently appache config is : (i've triple checked the white parts where the domain name is).
When I run apache2ctl -t D DUMP_VHOSTS I get
this looks fine to me, also tried disabling the default config but it didnt help.
Note: i've replaced my real domain with mydomain.com in reality I use my real domain on these spots.
Thought how do I know for sure that the conf file im editing is the one being used by the domain?
This is the correct Alternative htaccess rule for Laravel 5 suggested to use when the default doesn't work:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The Options +FollowSymLinks I believe plays an important role because the DirectotyIndex acts like a symlink.
Also check /app/config/app.php to make sure you haven't set the Config('app.url') to contain the index.php.
If you have laravel installed in a sub-directory see this:
How can I remove "public/index.php" in the url generated laravel?
Have you tried turning it all off (shutdown), and then turning it on again?
If everything is as you say, it should work. I would try a restart to see if it changes anything.
If it doesn't, please update with what OS you are using.
I ended up deleting the complete conf file and copied it again from the one thats working. I took the default .htaccess from laravel and it worked. Unfortunately I still dont know what was wrong though. The current conf file looks like
<Directory /var/www/mydomain.com>
AllowOverride ALL
DirectoryIndex index.php
</Directory>
My .htaccess in /public
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I had almost exactly the same problem today, which #dasper also helped me out on. I am using digital ocean Ubuntu 14.04 also, and I had to run the command a2enmod rewrite then reload apache2. It seemed that even though rewrite appeared to be on, it actually wasn't.
First, make sure mode_rewrite is enabled. I am sure you have probably done this but I want to make sure nothing is missed.
Next, see what version of apache you are running since the syntax has changed between 2.2 and 2.4. This should not be a big deal and highly doubt this is the culprit but could save you trouble in the future
Next, try putting the rewrite condition inside of the vhost information instead of the htaccess file. This can help a little with performance as well as give you a console warn/err when restarting apache where the htaccess errors could be squelched.
<directory /var/www/mydomain.com>
Options -MultiViews
AllowOverride ALL
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</directory>
Beyond this point I would be at a loss without some more logging or information from the server. You can also add CustomLog into the vhost and report all requests processed by the server.
The problem could be with your virtual host configuration and/or a misplaced .htaccess file.
Make sure your .htaccess file is in the public/ folder and that the DocumentRoot is set to that public/ folder.
And also, the < Directory> directive isn't controlling your virtual host but rather controls the folder itself and how it can be (or can't be) accessed on the server. To change the configuration of the virtual host do so inside the < VirtualHost> directive.
Here is an example of a virtual host configuration:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/var/www/mydomain.com/public"
DirectoryIndex index.php
</VirtualHost>
Here is the default Laravel Apache config:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and here is an alternative:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try to rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder.
Solution found here
I believe your directory path is wrong. You need /public on the end because Laravel treats that directory as the web root. Try this:
<directory /var/www/mydomain.com/public>
DirectoryIndex index.php
AllowOverride ALL
</directory>
But the better solution is to put the contents of the .htaccess file in your virtual host. Like this:
<VirtualHost *:80>
DocumentRoot "/var/www/mydomain.com/public"
ServerName mydomain.com
ServerAlias *.mydomain.com
<Directory "/var/www/mydomain.com/public">
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
Also, you should make sure your config file is loaded by running:
apache2ctl -t -D DUMP_VHOSTS
This will print a list of all the loaded vhosts. If yours isn't in that list then make sure it is enabled by running:
a2ensite [name_of_your_config_file]
Then restart apache with:
service apache2 reload
One more note: don't forget to edit /etc/hosts and add 127.0.0.2 yourdomain.com

Cakephp showing errors when deployed in server

When i upload cake php in server, it gives me the following error:
URL rewriting is not properly configured on your server
Class 'PDO' not found in /home/is306t3/public_html/lib/Cake/Model/Datasource/Database/Mysql.php on line 177
I have included the htaccess file as advised by cakephp:
root htaccess as follows:
IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app htaccess as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
and finally the app/webroot htaccess as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RRewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
The directory structure of my website is
-app
--webroot
---htaccess
--- test.php
--htaccess
-lib
-htaccess
Hope someone can help. Thanks!
Sounds like an Apache configuration issue. You need to confirm that the mod_rewrite is enables on Apache. Here is an article that talks about how to enable it:
http://www.lavluda.com/2007/07/15/how-to-enable-mod_rewrite-in-apache22-debian/
If you do not have access to the Apache configuration, you will need to contact your hosting provider.
UPDATE
Oh I just noticed. Try updating your webroot/.htaccess:
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Notice the ? in the rule? It should resolve it.
I'm not sure about the rewrite error but I had that PDO error as well. I had to add these two lines to the top of my .htaccess file.
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php
This is for HostGator though. The issue was they use php 5.2 as default for compatibility and you have to add these two lines to use 5.3 which has PDO. Maybe it will work there.
I know hardly anything about .htaccess rules but RewriteBase / isn't in any of my .htaccess files for Cake.

Categories