I'm trying to setup Laravel on a HostGator shared plan. I've followed these instructions:
http://laravel.io/forum/02-13-2014-how-to-install-laravel-on-a-hostgator-shared-server
I created and uploaded the .bashrc and .bash_profile files as instructed, then I run:
source ~/.bashrc
in the terminal, but then when I run php -v I get
No such file or directoryphp
I also tried uploading an htaccess file with AddHandler application/x-httpd-php55 .php to the root directory. When I run phpinfo() now, it shows php version 5.5.10, but php -v (before I run the source command) still shows version 5.2.17.
Any idea what I'm doing wrong?
STEP 1 Copy your files
Copy your app in a non-public folder, example:
/home/foo/myapp
Move your public folder to a public folder, example:
/home/foo/public_html/public
Open your public/index.php file and change paths to reference your laravel non-public code, example:
require __DIR__.'/../../../myapp/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../../myapp/bootstrap/app.php';
STEP 2 Change php version in Cpanel
For laravel 5.2 you need at least php 5.5
https://laravel.com/docs/5.2/installation#server-requirements
this will add some lines in your .htaccess, for example, this will enable php7:
# Use PHP70 as default
AddHandler application/x-httpd-php70 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php70/lib
</IfModule>
STEP 3 Make artisan work
php command line may not work, run this command to check php version:
php -v
if it doesn't give you the correct version you may run your commands directly with php 5.6 binary, like this:
/opt/php56/bin/php artisan
STEP 4 clear caches
Sometimes you need to clear your cache, there's two ways:
With artisan:
/opt/php56/bin/php artisan optimize
Manually:
Delete this two files
bootstrap/cache/compiled.php
bootstrap/cache/services.json
How to use SSL
Hostgator shared servers have a shared SSL certificate
To use the shared SSL certificate you must access your public folder by the root of your server and your username like this:
https://gator1234.hostgator.com/~username
So for example, if you put your application in a folder called myapp it will become:
https://gator1234.hostgator.com/~username/myapp
this will mess the routes file, so you have to add this lines to your .htaccess
RewriteEngine On
RewriteBase /~username/myapp
I recently wrote an article on how I was able to host my laravel 5.5 on a shared host. (Hostgator)
https://www.5balloons.info/hosting-laravel-5-5-project-on-shared-hosting-hostgator/
So there is one simple step that seems to get overlooked with most of the issues of setting up a subdomain to host a Laravel App using HostGator's Shared Hosting plan.
HostGator Shared Server Hosting Plan
Scenario:
Domain: https://yardpenalty.com is pointing to the home/username/public_html folder which has a WordPress installation.
Subdomain: https://games.yardpenalty.com is pointing to the home/username/games/public folder which has a Laravel App installation.
Problem:
We want the Laravel App to be accessed at the Subdomain's root level...
URI at https://games.yardpenalty.com
NOT at https://games.yardpenalty.com/public.
Solution:
Step 1:
Under our HostGator Shared Server Hosting Plan we can access the tools we need using cPanel.
Step 2:
In our cPanel we go-to Domains->Subdomains and we enter a name for our Subdomain (in this instance its called games).
Step 3:
Then we select a Domain from the dropdown list and in this scenario it is yardpenalty.com which is pointing to my public_html folder.
Step 4:
Finally, under the Document Root / (a.k.a. home/user) we point it to the /games/public folder!
It should look something like the second listing from your cPanel:
I was finally able to get Laravel installed with some help from this:
http://shincoding.com/laravel/installing-configuring-laravel-shared-hosting/
Related
I have installed laravel by composer create-project laravel/laravel –-prefer-dist
after this run php artisan serve command to laravel project directory and get this result.
Laravel development server started: http://127.0.0.1:8000
But when i go to http://127.0.0.1:8000 in browser laravel project not running and give error
This site can’t be reached
127.0.0.1 refused to connect.
but http://localhost/laravel/public/ it is working. Can anyone tell me that what is proper way to run this laravel project.
Try to run in different port
php artisan serve --port=9000
and then try http://127.0.0.1:9000 will work.
As might be on port 8000 something already running on your system will not make it work.
And you can also run your laravel project without artisan serve command
If anyone wants to make the application public, the more easy and fastest way is:
Rename the "server.php" file in root directory, in "index.php"
Move your .htaccess from public folder to root directory
Make your directory accessible to Apache2 (set all file permissions
to 777).
At starting level, you can use url like this http://127.0.0.1:8000 with port-number. but in further level you must working with simple url like http://localhost/laravel/public/.
One more thing - you should remove "public" keyword from url, so you access direct your root-project. Review this link - Laravel 5 - Remove public from URL
I had that problem too! And couldn't solve it. So I installed openserver from https://ospanel.io/ and put my site on the folder domains (Windows 10), then I just start Open Server and click "My Sites" and choose my site - it opened in my browser which set by default on Open Server program and click the folder on my browser cooled "public" and there you go -> your site is working.
I now that isn't solve the problem with cmd and start thought cmd and server like http://127.0.0.1:8000, but you can take access to your local site through http://'your site'/public/'your pages'
Good luck!
Changing the port will help.
php artisan serve --port=9000
worked for me
Try this
php -S 127.0.0.2:8000 -t public/
It will start your local development to http://127.0.0.2:8000 which will work great.
OR
You can try instead
php -S 127.0.0.1:8000 -t public/ It will work in any browser as compare to command php artisan serve which open url http://127.0.0.1:8000.
Successfully landed to Laravel page by the following steps.
Note: This is after the successful installation and configuration.
Was in /var/www/html/
Created the project using the following command after Laravel installation successfully
$laravel new firstapp
here firstapp is my project
cd to firstapp (folder created with project creation with $laravel new firstapp)
serve using the following command
$ php artisan serve
The project ready to serve with the following statement as below
Laravel development server started: http://127.0.0.1:8000
You can access the laravel page using the following URL
http:///firstapp/public/
Sometimes this occur when you have installed an anti virus software. Anti-virus deleting your "server.php" file. For that you can create an exception in anti-virus for "server.php" file or creating a "server.php". You can find relevant code for the file searching. Basically server refuse to connect occurs when the "server.php" deleted or removed from the file path.
guys I have a laravel project and its working fine. Every time I start the project by typing the command php artisan serve and then by typing the url localhost:8000 in my browser. But now I want to start my project only by typing the url localhost/projectname.
So I did a little bit of digging and found out a way to do this, I made it possible by changing the server.php file from root directory to index.php and copying the htaccess file from public folder to root directory`. This way my browser loaded only html file or php file but css files and js files were not loaded so I had to modify there link on the blade file for example:
Previously a style.css file was linked as:
<link rel="stylesheet" type="text/css" href="{{asset('front_end/assets/css/style.css')}}">
Now I link the same style.css file as below:
<link rel="stylesheet" type="text/css" href="{{asset('/public/front_end/assets/css/style.css')}}">
And It works fine.
But now I have found another problem, I have stored some files (images) in the the storage/app/public/myfolder directory so to access the files I had to use the command php artisan storage:link command and to access the files(images) from above mentioned directory from blade file I use the code below:
<img src="{{$url = Storage::url('myfolder/'.$company->logo_name)}}">
This code did worked only worked when I used to start my project using php artisan serve command. Now I its not linking so what should I do? And also can you guys tell me the way that I changed the server.php file to index.php is the right way or not? And what you guys do in your real projects?
Thank You.
When deploying a Laravel project you want your nginx or apache configuration to point to your public path of your project. Changing the server.php or index.php files are not necessary.
Apache Config Example:
<VirtualHost *:80>
ServerName project.dev
DocumentRoot "/home/vagrant/projects/project/public"
<Directory "/home/vagrant/projects/project/public">
AllowOverride all
</Directory>
</VirtualHost>
As you can see with this apache config example, it points to the public directory of your project.
You can achieve this locally by installing either Apache or nginx on your local machine.
I would recommend following Laravel's documentation guide on using Vagrant's Homestead to get an idea of how this is working before you decide to run this on a server. A link here
There is a couple of options you can take to achieve essentially the same goal. This depends on the machine you are running on and personal preference.
Laravel Valet for Mac
Laravel Homestead
WAMP for Windows
MAMP for Mac
You don't need to modify any file.
You need one of this:
Web server installed locally, Apache or Nginx
A Vagrant Virtual machine for running the project like in production environemnts like Homestead
Valet
If you decide to go with Web Server, you just need to consider to point to project/public folder instead of project.
Doing with one of this options, you won't need to modify the assets url, since public shouldn't be part of your url in any case.
First of all, don't do any tweaks in server.php file, it's fine.
To run your project with url like, http://localhost/my-project.dev or simply my http://project.dev, use WAMP or XAMPP (if working on a windows machine) and lamp for linux. You can also checkout Laravel's Homestead.
Then setup virtual host.
See this tutorial for setting up virtual host on WAMP - http://www.coderomeos.org/how-to-set-up-virtual-host-on-wamp-server
And don't put your assets in public/assets folder to prevent using storage link.
Good day friends,
I know that similar questions exist for deploying a Symfony 2.7 application on shared hosting with CPanel. But in my case I do not have access to SSH. Therefore installing via Composer is out of question.
To work around it I have copied the entire sources into a sub folder in "public_html" folder. When I try to configure Symfony using "web/config.php" it gives some pre-requisites issues. To resolve this I have copied custom "php.ini" in my sub folder and also added the ".htaccess" file to root of "home/user" with following content
SetEnv PHPRC /home/user/public_html/subfolder/php.ini
But still the setting is not taking affect. Do i need to ask the hosting provider to restart the web server ? this wont be easy since it is shared hosting.
Please suggest any alternative way
Your custom .htaccess is not used by the application.
Try to add the SetEnv in the public_html/web/.htaccess that is used to browse your application.
If this has no effect, a working way is to add the following in the VirtualHost of your application:
<VirtualHost *:80>
PHPINIDir /home/user/public_html/subfolder/php.ini
</VirtualHost>
But that involves to restart apache once.
EDIT
If PHP run as CGI:
Create a wrapper script called phpini.cgi to export the directory that contains the php.ini file as PHPRC.
#!/bin/sh
export PHPRC=/home/user/public_html/subfolder
exec /path/to/cgi-bin/php5.cgi
In your /home/user/public_html/web/.htaccess add the following lines:
AddHandler php-cgi .php
Action php-cgi /cgi-bin/phpini.cgi
If php run as CGI with wrapper (for FASTCGI):
You should already have the following wrapper script:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php5.cgi
Change it to:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php.cgi -c /home/user/public_html/subfolder/php.ini
More informations and alternatives in the source.
I hope this solves your problem, it should if you are sure you are php run as cgi/fast-cgi.
I install new laravel package through composer and everything is going fine (including the error page) when I use php artisan serve and access my project in http://localhost:8000. But when I use virtual hosts (for example: example.dev), the error page is not showing, just a blank page. I'm not sure if it has something to do with my virtual host configuration because if the code has no error, the page just load normally. And I have changed the permission of storage and bootstrap/cache folder to 777.
Is there any other configuration that have to do?
Which PHP version do you use on your server? Check the logs and see if you find something there.
Try giving the entire Laravel folder 755 permissions and then change the bootstrap/cache and storage folders.
Also try editing your .htaccess file, add something like:
RewriteEngine On RewriteBase /
On Windows 7 cmd I have run composer create-project laravel/laravel blog --prefer-dist from `C:\xampp\htdocs\lara. Everything is downloaded and installed fine.
However, when I try to access http://localhost/lara/blog it shows the directory listing of apache. I followed the instruction in the documentation during the installation.
I noticed the following notes:
C:\xampp\htdocs\lara\blog does not has any index.php or .htaccess
C:\xampp\htdocs\lara\blog\app also, does not has any index.php or .htaccess
Only accessing http://localhost/lara/blog/public opens a page with the laravel logo and the words "You have arrived"
I could not able to know what's the problem?
Laravel's folder structure uses the public folder as the WWW root, effectively placing all your application's files outside of the web root to help keep them secure. What you are experiencing is normal.
You'll have to either access your application from the http://localhost/lara/blog/public URL, or set up a virtual host URL (e.g. http://testblog.dev) that is pointed to the public folder. I do not develop on Windows/XAMPP so I cannot specifically tell you how to do that part.
If you're running php > 5.4 you can serve the app using the builtin server from command prompt as well (for development purposes):
php artisan serve
I have an answer on How to install Laravel via Laravel Installer on Windows?
or
http://goo.gl/uftcSo
for more details
Hope that helps.