I developed an application with laravel 4.2.8 and now I am having trouble deploying it. I followed this answer https://stackoverflow.com/a/16683938/3153380 but its not working. I am getting a white screen and the headers are returning a 500 Internal Server Error status.
I read around that laravel 4.2 is a bit tricky to set up on shared hosting is this true? I can seem to find a working solution so those that have deployed 4.2 before please help. My folder structure is like below
root/
laravel_base/
app/
...
public_html/
siteroot/
assets/
packages/
uploads/
index.php
...
Any pointers?
First make sure that your shared host runs php >= v5.4. Second try to follow this steps:
Create a folder outside your public_html/ or www/. Ex: project/
Copy every folder and file (except the public folder) from your laravel app into that project/ folder
Copy the content of public/ folder into your public_html/ or www/ (the .htaccess must be there too)
Inside public/ locate the index.php file and change the following paths:
a. Path to autoload.php
require __DIR__.'/../bootstrap/autoload.php';
into
require __DIR__.'/../project/bootstrap/autoload.php';
b. Path to start.php
$app = require_once __DIR__.'/../bootstrap/start.php';
into
$app = require_once __DIR__.'/../project/bootstrap/start.php';`
After all that it should be working.
I did something similar to #Helder Lucas - I also had to edit the bootstrap/paths.php file:
# change: 'public' => __DIR__.'/../public',
'public' => __DIR__.'/../../public_html',
I created a script to setup laravel projects for shared hosting environments. Here is the gist: https://gist.github.com/meganlkm/74dba6c4350ed58bf7bb
Try to play with .htaccess
In your public_html, add a .htaccess to forward the request
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^yoursite.com/public
RewriteRule ^(.*)$ yoursite.com/public/$1 [L]
</IfModule>
i.e.
public_html
├── yoursite.com <-------- laravel project
├── .htaccess <-------- this file
It was pretty easy to get Laravel 4/5 running on OpenShift Online. For anyone else running into hosting issues, check out: https://hub.openshift.com/quickstarts/115-laravel-5-0
I just add a new folder in the / folder on my shared hosting
www.domain.com
Where i add a sub folder called
public/
So that the path looks like this
/www.domain.com/public/
And from the CPANEL i link the domain name root folder to the
www.domain.com/public/
And then i just upload the laravel application in
/www.domain.com
It works for laravel 4.2 and 5.
And there is no security breaches because the root domain folder is in the public folder of the laravel app, no need for updating the .htaccess file.
It just works.
Related
This is the first time I am developing a Laravel Vue app. When I use php artisan serve, everything works fine. But when I load it with http://localhost/myProject/public, assets are not loaded. My images are in img directory inside public folder. I was using blade templating to manage this issue when I use Laravel alone. But now I can't use blade since it is a Vue component. How can I run the project without php artisan serve? My Ultimate aim is to deploy the project in godaddy shared server. Please help me.
Debug your application using 'php artisan serve' while you develop from your local machine.
When you publish it into godaddy,
compress the project folder (say 'my_project') and upload the zip file ('my_project.zip') to 'public_html' directory in godaddy.
unzip the folder.
Now the directory structure will be 'public_html/my_project...'
you will have a 'public' directory inside 'my_project'.
Now create a subdomain which points to the 'public' directory.
That's it. Now load the subdomain.
The assets and api's will work perfectly.
just rungit clone [your_project_address] in the www folder and then run 'php artisan migrate', of course, you should have configured well.
#ThasheelApps this is your solution to access api's.
Create a .htaccess file in root folder and paste the following code there:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This issue occurs many times due index.php in url. if you try your api endpoint including index.php, it will work perfectly. to prevent this issue we need to follow above soution htaccess
Follow these steps:
zip your project after npm run dev and php artisan serve without
any error.
Go to your shared hosting location and outside fo public_html
make a folder name say myproject. Inside this folder extract all
your project files.
cut your public folder from project folder on root, go to your
subdomain folder under public_html and paste.
go to index.php inside public folder and
require DIR.'/../vendor/autoload.php'; and
$app = require_once DIR.'/../bootstrap/app.php'; pointing to your project location on root.
That is all. Enjoy, if you have properly created and attached your DB to your project.
I have a second domain on my shared hosting account.
My laravel project is in the root dir
The laravel public folder is under public_html. public_html/public
Note: I don't want the public files directly under public_html because I have other files that would be overwritten.
I've already changed these to lines in my index.php file.
require DIR.'/../../MyOtherDomain.com/vendor/autoload.php';
$app = require_once DIR.'/../../MyOtherDomain.com/bootstrap/app.php';
The question is how do i point the laravel project to use the index.php file under public_html/public?
Thanks in advance.
Add a .htaccess file in your root directory and paste the following code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Save and reload your browser.
Since you're using shared hosting, you need to change the document root of the domain to public_html/public. Then you need to point index.php to your Laravel project (which must only be located outside the public_html folder) by editing the following code:
require DIR.'/../../MyOtherDomain.com/vendor/autoload.php';
$app = require_once DIR.'/../../MyOtherDomain.com/bootstrap/app.php';
Note- MyOtherDomain.com folder should contain the Laravel project.
I am a newbie to Laravel.
I want to upload Laravel project from local to shared hosting server.
Scenario is like below:
I have a site (abc.com).
I want to deploy Laravel project inside this site so that URL will be like abc.com/xyz
I have moved Laravel project files and folders inside xyz folder.
But site is not running.
What paths needs to change and in which files?
Please help.
It will run as abc.com/xyz/public
This can be done, but keep in mind that having the Laravel files in your web server root is not recommended.
How you can accomplish abc.com/xyz:
In folder xyz where laravel is installed you can add this in a .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Again, this setup is not recommended, because the Laravel files should never be in or above your root.
A better way would probably be to install Laravel in the dir below the root and set xyz as your public directory. You would just have to change the paths in index.php to make sure it searches for the Laravel files below your web root.
I'm trying to setup laravel (5.4.12) in shared hosting. Following this tutorial I had deleted my public_html and created soft-link for public_html to public folder of laravel project. I had successfully setup laravel (5.3.29) following the same tutorial for my previous project. But this time when I try to open base url it downloads index.php file of public directory of laravel folder. Can anyone help me out.
You can do it without deleting public_html folder.
for routing to public forlder just add these lines to .htaccess files
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Normally PHP files are downloaded when the web server isn't configured to serve PHP files. Sounds like you need to talk to your hosting provider.
Finally found the solution. The issue was with PHP version. I had selected PHP version 7.1.0RC4,I changed it to 7.0.12 and the problem is gone.
Laravel 5 setup without artisan serve command
Rename the server.php in the your Laravel root folder to index.php
copy the .htaccess file from /public directory to your Laravel root
folder.
I am working on a yii2 project, and would like to deploy it to an apache server where the entire website is expected to exist in the /public_html directory, and /public_html is the web root for that host. The issue is that yii2 expects the web root to be /web, and it expects most of the site hierarchy to exist outside of the /web directory.
I would prefer not to have to change the webroot to /public_html/web, and for future projects, it may not be an option. So, is there a way to place the entire site hierarchy in /public_html , and still have the site work correctly?
I have tried creating a /public_html/.htaccess file with the following contents:
RewriteEngine on
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
And this seemed to work correctly, at first. Nothing outside of /public_html/web was accessible, and files within subdirectories of /web, such as /web/js/signup.js which could be accessed via the url http://localhost/js/signup.js, but this caused my routing rules (which were set up on a local system where I could have the web root pointing at /web) to no longer be recognized.
So, I would be happy with either an alternate to the .htaccess route, or a suggestion to how to fix the routing rules so that the .htaccess route would work.
Edit for Clarification
I have a hosting provider where the web root is ~/public_html . Yii has documentation explaining that you can rename www to public_html, and have everything that would normally be outside of /www located in ~, along with the various dotfiles and user-documents that Linux normally places in ~. I would prefer to have all site-related directories together (under the webroot).
As an alternative, a two-directory structure, such as the following would work:
~/
|--- (Various dotfiles and subdirectories unrelated to the web site)
|--- yii - Contains all subfolders that should be outside of the web root
|--- commands
|--- config
|--- controllers
|--- (etc...)
|--- public_html - Contains everything that can be within the web root.
|--- (etc...)
This has been asked so many times that they made a page for it in the Yii2 docs.
I personally answered this too many times to remember.
This can be done via the use of aliases.
Move your web directory to the new webroot (assuming ~/mysite.com is your existing site):
rm -rf ~/public_html
mv ~/mysite.com/web ~/public_html
Then, you move everything that was outside of your webroot to the new directory:
mv -prf ~/mysite.com ~/mysite.example-external
At this point, you should have a web root at ~/public_html , and you should have everything else in ~/mysite.example-external. You then edit your ~/public_html/index.php file. Please note that this is not considered part of yii core, so it's ok to modify it. The new index should have some variation on this:
<?php
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
$thepath = __DIR__ . '/../mysite.example-external';
require( $thepath . '/vendor/autoload.php');
require( $thepath . '/vendor/yiisoft/yii2/Yii.php');
$config = require( $thepath . '/config/web.php');
(new yii\web\Application($config))->run();
From here, you also have to add aliases to your ~/mysite.example-external/config/web.php file, so yii can find its core files. In the web.php, at the point where $config is assigned a value, modify it to look something like the following:
$config = [
'aliases' => [
'webroot/assets' => '/Users/XXXXXX/mysite.example-external/web/assets',
'root' => '/Users/XXXXXX/mysite.example-external/web',
],