Deploying on a shared host

nothing change expect my path

You need to install it in the right director under public_html folder. Then you can install it using following command

composer require slim/slim"^3.0"

Once installed, add following code in index.php file

<?php

require 'vendor/autoload.php';
$app = new Slim\App();

However, for this method to work, you must have access to composer on your hosting provider. Most of the PHP hosting providers, like Cloudways and ServerPilot, provides composer on their servers.

Running composer on a production server is not a good idea. Please don’t do that!
Run composer only within your development or CI environment. Create an artifact you can deploy on your test/staging/prod webserver.

Hi

I need help, while deployed slim framework on plesk shared hosting below mentioned issue is coming up.
actually it is working fine at local wamp server.

404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

here is my code.

index.php:

require ‘…/vendor/autoload.php’;
header(‘Access-Control-Allow-Origin: *’);
header(‘Access-Control-Allow-Methods: GET, POST, OPTIONS’);
header(‘Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With’);
header(‘Access-Control-Max-Age: 86400’);
$config = [‘settings’ => [
‘addContentLengthHeader’ => true,
‘displayErrorDetails’ => true
]];
$app = new \Slim\App($config);
require ‘…/src/routes/hostUser.php’;
require ‘…/src/routes/user.php’;
$app->run();

hostUser.php:

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Slim\Http\Message;
include_once 'Database.php';

var_dump($app);

$app->get('/loadprofile', function (Request $request, Response $response) {
    $user_email = $_GET['emailid'];
    $userid =  $_GET['usertypeid'];
    $database = new Database();
    $db = $database->getConnection();
    try {
        $stmt =  $db->prepare("SELECT * FROM user_details WHERE userid='".$userid."' AND email='".$user_email."'");
        $stmt->execute();
        $res = $stmt->fetch(PDO::FETCH_ASSOC);
        return json_encode($res);
        $db = null;
    } catch(PDOException $e){
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
});

The control reached till var_dump($app) but it is not executing /loadprofile service.

Hi @aurous The error messages looks like a typical IIS error page. Make sure, that you define the public/ directory as document root and that your web.config file is correctly configured.

@odan thanks for your time, i think error is coming up because dependencies is not being installed, trying to install but exception is coming up.

Might be useless, but do not deploy vendor/phpunit to your web server. I did and my website got hacked. Oh well, glad I caught it early enough so no real damage, just a lessoned learned.