# Deploy Slim project to Hostgator using subdomain

**URL:** <https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187>\
**Category:** Questions\
**Created:** [May 24, 2019, 5:26am UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187 "2019-05-24T05:26:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![geekykidstuff](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@geekykidstuff](https://discourse.slimframework.com/u/geekykidstuff)\
**Post date:** [May 24, 2019, 5:26am UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/1 "2019-05-24T05:26:16Z")

</div>

I have a very simple Slim app that works fine on my Ubuntu machine but I get an error 500 when I deploy it to a Hostgator shared account using a subdomain.

I suspect the problem lies in my .htaccess file.

The structure of my files is:

```
project/
├──api/
│ ├── .htaccess
│ ├── services.php
├──src/
    ├──vendor/

```

My Slim app (services.php):

```
<?php
    use \Psr\Http\Message\ServerRequestInterface as Request;
	use \Psr\Http\Message\ResponseInterface as Response;
    require_once '../src/vendor/autoload.php';

    $c = new \Slim\Container();

    $c['notFoundHandler'] = function ($c) {
	    return function ($request, $response) use ($c) {
	        return $c['response']
	            ->withStatus(404)
	            ->withHeader('Content-Type', 'text/html')
	            ->write('Invalid endpoint');
	    };
	};

    $app = new \Slim\App($c);	
	$app->post('/myEndpoint', function (Request $request, Response $response, array $args) {
		if($request->getHeader("key") != null && $request->getHeader("key")[0] == "123456789="){
			$reqdata = $request->getParsedBody();
			$data = $reqdata['data'];
			return json_encode('{"data":'.$data.',"response":"OK","errorcode":"0"}');		
		} else {
			return '{"data":"","response":"Access denied","errorcode":"9999"}';
		}
	});

	$app->run();

```

My .htaccess file:

```
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule . services.php [QSA,L]
    </IfModule>
    # Use PHP71 as default
    AddHandler application/x-httpd-php71 .php
    <IfModule mod_suphp.c>
      suPHP_ConfigPath /opt/php71/lib
    </IfModule>

```

I created a subdomain ([api.mydomain.com](http://api.mydomain.com)) with project/api/ as document root.

When I make a POST request in my local installation to

```
127.0.0.1/api/services.php/myEndpoint

```

works as expected and returns the data. However, when I make the same request to my Hostgator subdomain:

```
api.mydomain.com/services.php/myEndpoint

```

I get the error 500.

Note that if I add a simple test.php file to my api/ directory that only prints something, e.g.

```
    <?php
      echo "OK"
    ?>

```

and I go to [api.mydomain.com/test.php](http://api.mydomain.com/test.php), it works fine and prints the string.

What do I need to change or add in my .htaccess for my slim app to work?

---

<div class="post-metadata">

**Author:** ![l0gicgate](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@l0gicgate](https://discourse.slimframework.com/u/l0gicgate)\
**Post date:** [May 24, 2019, 5:39am UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/2 "2019-05-24T05:39:24Z")

</div>

What is the error message, can you provide that from your error logs?

---

<div class="post-metadata">

**Author:** ![Mikalay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/mikalay/32/720_2.png) [@Mikalay](https://discourse.slimframework.com/u/Mikalay)\
**Post date:** [May 24, 2019, 1:01pm UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/3 "2019-05-24T13:01:23Z")

</div>

Try adding

```auto
RewriteBase /

```

to `<IfModule mod_rewrite.c>`

And make a POST request at the URL `api.mydomain.com/myEndpoint`

---

<div class="post-metadata">

**Author:** ![geekykidstuff](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@geekykidstuff](https://discourse.slimframework.com/u/geekykidstuff)\
**Post date:** [May 24, 2019, 3:22pm UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/4 "2019-05-24T15:22:13Z")

</div>

I don’t get an error.log file like when a PHP file fails. The only error I get is the answer from the POST request. A rendered version looks like

![Screenshot%20from%202019-05-24%2010-21-17](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/1X/e809515acc877d3abeb7f63bb51544cca415fa14.png)

---

<div class="post-metadata">

**Author:** ![geekykidstuff](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@geekykidstuff](https://discourse.slimframework.com/u/geekykidstuff)\
**Post date:** [May 24, 2019, 3:24pm UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/5 "2019-05-24T15:24:07Z")

</div>

I tried it but didn’t fix it. Still get the same answer. I added that line after RewriteEngine on, so my .htaccess now looks like

```
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule . services.php [QSA,L]
</IfModule>
# Use PHP71 as default
AddHandler application/x-httpd-php71 .php
<IfModule mod_suphp.c>
    suPHP_ConfigPath /opt/php71/lib
</IfModule>
```

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [May 24, 2019, 5:33pm UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/6 "2019-05-24T17:33:56Z")

</div>

Did you mean

```auto
RewriteRule ^ services.php [QSA,L]

```

Instead of

```auto
RewriteRule . services.php [QSA,L]

```

You should get access to Apache’s error log, as that would tell you exactly what is going on, rather than guessing.

---

<div class="post-metadata">

**Author:** ![geekykidstuff](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@geekykidstuff](https://discourse.slimframework.com/u/geekykidstuff)\
**Post date:** [May 24, 2019, 7:13pm UTC](https://discourse.slimframework.com/t/deploy-slim-project-to-hostgator-using-subdomain/3187/7 "2019-05-24T19:13:56Z")

</div>

Thank you! That did the trick.

I checked the Apache error log but, at least the log Hostgator provides, shows nothing.

Also, another thing I had to do is move my project directory to the public\_html folder. Then, I created the subdomain again and pointed it to that directory.

I’m still very ignorant about how .htaccess works. What’s the difference between

`RewriteRule ^ services.php [QSA,L]`

and

`RewriteRule . services.php [QSA,L]`

Thank you so much.
