Categories: php, apache, .htaccess, slim

PHP Slim4 on Apache2 gives HttpNotFoundException

1 answer

Links I've seen include:

https://akrabat.com/running-slim-4-in-a-subdirectory/

https://discourse.slimframework.com/t/slim-4-httpnotfoundexception/3273/18

and some others

I'm trying to setup a Slim4 project on apache2. But trying to access it gives me the error

PHP Fatal error: Uncaught Slim\Exception\HttpNotFoundException: Not found....

I have my index file in /var/www/html/_projects/work/calc1/src.

The following is my calc.conf in /etc/apache2/sites-available:

<VirtualHost *:80>     ServerName calc.mrid.local     ServerAlias calc.mrid.local      ServerAdmin webmaster@localhost     DocumentRoot /var/www/html/_projects/work/calc1/src      ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined  </VirtualHost> 

This is my .htaccess located in src directory

RewriteEngine On RewriteBase /_projects/work/calc1/src/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L] RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

My index.php looks like this:

// use and require statements...  $container = new Container(); AppFactory::setContainer($container);  $container->set('view', function() {     return \Slim\Views\Twig::create(__DIR__ . '/public/templates'); });  $app = AppFactory::create();  // even without this line it doesn't work $app->setBasePath("/_projects/work/calc1/src");   $app->add(TwigMiddleware::createFromContainer($app));  // my routes....  $app->run(); 

Has anyone worked with Slim4 on Apache2? If yes, can you please guide me ?

All answers to this question, which has the identifier 61158280

The best answer:

The src/ directory is actually only meant for the PHP classes and must not be accessible to the web. The apache DocumentRoot should point to the public/ directory which contains your front controller public/index.php. Take a look at the Standard PHP package skeleton. More details about Slim and apache can be found in this Slim 4 Tutorial.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data