Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel1836's avatar

Installing Laravel on shared hosting

I actually have Laravel installed. I'm trying to install Symfony as well for my portfolio.

The problem is this; The Symfony Project files are located one directory up from public_html, and I understand the index.php file must be inside public_html.

But I already have a index.php from my Laravel projects, and if I replace it my Laravel projects will stop working.

I think I need an alias pointer.

But I'm unclear how to proceed for both frameworks to coexist on my site.

Can anyone help?

Thanks

0 likes
24 replies
bugsysha's avatar

They can not coexist. They need to be in separate folders and have different virtual hosts point to them.

jlrdw's avatar

@bugsysha none. And that guide is from snapey, been using since laravel 4.2.

Main laravel placed above public_html. I can either place images above or in the assets folder, i.e.,

public_html/laravel54/assets/images/

Even if I couldn't use a symbolic link, I just serve them like I did in Java, i.e.:

Java

<a href="DisplayImage?imageName=${item.dogpic}" target="_blank" class="image"><img src="DisplayImage?imageName=${item.dogpic}"></a>

// just test data....

Servlet DisplayImage

package net;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DisplayImage extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        try {
            response.setContentType("image/jpeg");
            ServletOutputStream out;
            out = response.getOutputStream();

            String path = "/stohere/uploads/imgdogs/";
            String filename = path + request.getParameter("imageName");
            FileInputStream fin = new FileInputStream(filename);

            BufferedInputStream bin = new BufferedInputStream(fin);
            BufferedOutputStream bout = new BufferedOutputStream(out);
            int ch = 0;;
            while ((ch = bin.read()) != -1) {
                bout.write(ch);
            }

            bin.close();
            fin.close();
            bout.close();
            out.close();

        } catch (Exception e) {

            response.getOutputStream().println("Exception is ;" + e);

        }

    }
}

php

<img src="<?php echo 'http://localhost/laravel70/pthru.php?dir=imgdogs&img=' .  $row->dogpic; ?>" alt="" class="image">

Class // shortened version:

<?php
$basedir = '/path_to/images';

$imagedir = $_GET['dir'];
$image = $_GET['img'];

$file = $basedir.'/'.$imagedir.'/'.$image;

header('Content-Type: image/jpeg');
ob_clean();

readfile($file);
exit(0);

?> 

On some shared host you can't symbolic link. This is only needed if images is above public_html. Otherwise not needed.

Azeem812's avatar

firstly you run your project on locally ,then upload on shared hosting after resolving issue.

bugsysha's avatar

@jlrdw I've tried that with Vesta CP and some other similar solutions few years ago and it didn't work. Thanks for changing my mind that it can work without too much tinkering.

jlrdw's avatar

I wonder if @daniel1836 has figured anything out yet.

What's weird is image uploading. PHP uploads work fine with Microsoft Edge. Edge unlike Chrome and Firefox gets the full path:

c:\somefolder\images\Ann.jpg   \ Edge

Ann.jpg   \ Chrome and FF

So in both Java and Asp.net you have to have an extra small routine to just get the last part.

Php in the above example will get only Ann.jpg. So will Apache commons. It's just the newer code that gets whole path.

But it's usually fine to store images some where else on a drive / server.

Daniel1836's avatar

I'm still working on it.

I don't need any advice on images.

I just need that index.php file in the public_html directory with the required path pointing to my Symfony project files.

But like I said I already have an index.php for my Laravel projects. Is there a way to rename index.php ('index1.php') and then make some configuration that points to it? That way I won't have to overwrite it.

jlrdw's avatar

You need to look at http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

It explains setup. First index shouldn't be directly in public_html.

public_html
------ a laravel subfolder
---------------- index.php

But the guide completely explains the folder structure in detail. Following the guide would not even mess with your Symphony set up.

Like I said I have a cake and a laravel on shared hosting and one does not interfere with the other at all.

Daniel1836's avatar

Ok, so for my Laravel projects the index.php file is located directly in public_html.

But if I understand that article you posted, I can put the Symfony index.php file in a sub folder inside public_html and that will work as well.

My next question for my Symfony index.php file I do not see anything like this.

require __DIR__.'/../../dj3core/bootstrap/autoload.php';

I only see this.

<?php
header("refresh: 5; https://mysite/Symfony/public/index.php");

How would I go about configuring it?

jlrdw's avatar

I thought you said your symfony project was configured where index is in that folder. So I meant configure laravel like that article. Either way just configuring like in that article will not mess with your symfony project.

But yes any of the Frameworks that technique should work. Cake was a little tricky.

Daniel1836's avatar

Sorry for the confusion. I meant Laravel is working. Symfony is not.

jlrdw's avatar

Yes it's done the same exact way it's just a matter of adjusting your ../../

Daniel1836's avatar

This is the entire contents of the Symfony index.php file.

<?php
header("refresh: 5; https://mysite/Symfony/public/index.php");

	echo '<title>Symfony Installed</title><div style="background: #e9ffed; border: 1px solid #b0dab7; padding: 15px;" align="center" >
	<font size="5" color="#182e7a">Symfony is installed successfully.</font><br /><br />
	<font size="4">Symfony is a Framework and doesn\'t have an index page.<br /><br />
	You will be redirected to its "public" folder in 5 seconds...<br /><br />
	Symfony aims to speed up the creation and maintenance of web applications, and to replace the repetitive coding tasks by power, control and pleasure.

Symfony is aimed at building robust applications in an enterprise context. This means that you have full control over the configuration: from the directory structure to the foreign libraries, almost everything can be customized. </font></div>';
?>

So I do not see where to configure it like in the Laravel index.php file.

jlrdw's avatar

Also if you have laravel working I would suggest now the symfony forums as they would be able to help you better.

Daniel1836's avatar

Supposing I have all the files in the right place, and assuming my configuration was done correctly, and I still encounter a HTTP 500 error message on my route what could potentially be the problem?

Just trying to narrow down my troubleshooting.

jlrdw's avatar

Is the HTTP 500 coming from Symfony or Laravel?

Daniel1836's avatar

Symfony.

I'm kind of confused right now. I'll probably figure it out eventually.

The message I got at first was composer.lock needs to be php 7.2 (current version was 7.1).

After upgrading to php 7.2 the message I get now is 500 error (undefined function), except the screen has the Symfony logo on it with links to the documentation and stuff , which gives me encouragement that I'm on the right track.

jlrdw's avatar

Have you tried any symfony forums, I only know how to get laravel working?

I tried symfony once several years back (maybe one hour), and said Nah. At the time I used another framework where I was also a contributor.

jlrdw's avatar

They don't have an active forum like this? I really don't know. Another possibility is post a question on stackoverflow.

I guess you have already looked at the symfony links I gave.

Daniel1836's avatar

Apparently Symfony will only run on PHP 7.2 or greater. That is my problem. (I'm currently using 7.1)

This is maybe a dumb question, but it is important to me not to mess up my current Laravel projects. My Laravel version is 5.2.45 and for some reason my Laravel projects stop working when I switch to PHP 7.2.

Will my Laravel projects still work if I upgrade my Laravel version to 5.4? And How do I go about upgrading my Laravel version?

Thanks

jlrdw's avatar

Each version has an upgrade guide in the documentation you need to follow that upgrade guide.

Please or to participate in this conversation.