Currently my local code and production code follow the same directory structure. After, pushing my changes from local, i pull it on the server and it works fine.
Website path is something like http://abcde.com/code/laravel/public
code directory is under version-control
Now, i'm trying to change path to http://abcde.com
i followed this guide and thinking about moving source code out of server directory. So, the structure:
/var/www will contain content of laravel's public folder
/var/source will contain laravel
But then how'll i manage it with Git because the structure will be different?
Edit: I'm aware of two solutions:
Changing apache root
use .htaccess to remove public
For 1, there is a possibility that we'll add another directory admin in www, which will have its own source code. So, existing content of www will be moved to a sub-directory.
For 2, It's not recommended to keep source code inside web server root.
Please correct me if i'm wrong.
My thought is, you can make symlinks to preserve your directory structure, with this you help apache to keep it original configuration, and at the same time will no have any issues with version control.
Symlink is by using this command: ln -s /path/to/origin path/to/destination.
Bests ;)
There is a simpler procedure. Pull you complete project in var/www and add a .htaccess in var/www which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Now you will be able to use http://abcde.com
Related
I've built a Laravel site locally, and everything works wonderfully—but when I've tried deploying it to my shared host (Hostinger), I cannot get everything replicated or set up correctly. The obvious problem is that Hostinger puts the public-facing code in a public_html folder, which my Laravel setup does not have (it has public instead).
Also, I'm using GitHub for version control and (hopefully) deployment. I'm able to connect my GitHub repo directly in Hostinger, but the problem is, it pulls my code into public_html instead of the root.
I'm really sorry if this question/problem is dumb; I'm more of a web designer than developer these days, and I just need a damn portfolio site up and running. :)
Local directory structure:
root
--app
--bootstrap
--config
--database
--node_modules
--public
--resources
--routes
--storage
--tests
--vendor
I've read various articles and posts about either copying contents of public into public_html after uploading the code, and then changing __DIR__ suffixes in index.php; or ways to change public to public_html locally up front...but the former didn't work and the latter scares me since so much of my Laravel workflow using npm run and whatnot utilizes the public dir.
I also don't really want to have my remote and local out of sync. My desired workflow:
code locally <---
| |
npm run dev/watch --
|
npm run prod
|
push to GitHub
|
deploy to host
|
enjoy fresh website without any changes to remote files on host :)
You don't want to move the contents of public to the root and serve your app from the root because you will expose important config files such as .env.
Create another .htaccess in your root with the following contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Which will rewrite all of your urls to the public directory. This should work in the local and production environment.
Have you tried to change public path in Laravel :
See answer here maybe this is a solution.
I developed my laravel application on wamp. I am finally done and rent a cloud hosting server with CPanel interface. I uploaded all my files on public html and tried going to the site. It's supposed to go to login page but not working.
I used to deploy classic html file, this is the first time I'm deploying a PHP laravel site. I've successfully imported my MySQL database so it's ready. I'm just clueless of the configuration etc.
I'll walk you through the steps. Since you mentioned about public_html folder, I assume that this solution will work for you. Please follow the steps and change myapp to whatever your app name is.
Copy your project's public folder into public_html folder and rename it (Say myapp_public)
You will see a .htaccess file in public_html folder. Edit the contents of that file as follows:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^myapp_public
RewriteRule ^(.*)$ myapp_public/$1 [L]
Copy other folders in the root directory inside another directory say myapp
Now the final thing that you need to do is, to edit index.php file at the path public_html/myapp_public/index.php (if you followed the steps I wrote above). Change require statement as follows
Change require statement as follows:
require __DIR__.'/../../myapp/bootstrap/autoload.php';
Change $app variable as follows:
$app = require_once __DIR__.'/../../myapp/bootstrap/app.php';
And this should do it. Drawing out the simple directory structure for easiness.
~
|__ myapp
| |____ .env
| |____ app
| |____ artisan
| |____ .........so on
|
|__ public_html
|_____ .htaccess (this is the file to edit)
|_____ myapp_public
|________ .htaccess
|________ index.php (this is the file to edit)
|________ robots.txt ...... so on
I will explain in detail if you do not understand what is happening here.
EDIT
Make sure that you have installed composer via cURL as apt-get wont work on shared hosts. Once done, run composer install from your project's root directory i.e. myapp if you followed above steps.
Finally I got it, Vishal's answer really helped, but I needed to change my PHP version setting to 5.5 or higher, after looking at the error log and googling the error. Thanks again Vishal. I still have problems with database connection but I think I can handle it from here.
I'm new in Laravel 5.
I found this Laravel 5 - Remove public from URL on Stack Overflow to remove public folder from my Laravel 5 App. Only I have a question about the security.
When I am removing public from URL, then I have to change the basic folder structure of Laravel 5. Yes, it's working fine without the public from the URL.
But what's about the security of Laravel, because I am changing the default folder structure? Is it secure to use?
You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.
Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.
If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory ofpublic_html, do the same but create symlink from$LARAVEL_PATH/publictopublic_html/$PROJECT_SUBDIR`.
That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)
you this link you provided is not about changing the actual file structure of the framework, this example uses mod_rewrite to rewrite the url of your application. In other words you are telling your server that you would like to point to that directory without the full path is visible to the end user.
Also take a look on the below answers of the link you've provided.
Rename the server.php in the your Laravel root folder to index.php and
copy the .htaccess file from /public directory to your Laravel root
folder. -- Thats it !! :)
I logged into openshift application using filezilla.
Earlier for normal website i just drag and drop files at www directory its works pretty fine but in at this case i found some other folders and i am unable to get an idea where should i drop my php app in at this particular machine. I am unable to locate where the index file is located also. if I am using git for the deployment of application it works pretty fine.
Openshift makes it easy to upload program changes by checking out the container. Adding the code and the pushing it.
see How to git-checkout first application created on OpenShift? on how to do that.
I'm not sure about the structure when you use filezilla to connect to the Openshift container, but it should be similar to the checked out structure
index.php Template PHP index page
.openshift/ Location for OpenShift specific files
action_hooks/ See the Action Hooks documentation
markers/ See the Markers section below
pear.txt List of pears to install
Depending on what cartridge you are using:
php/ # for backward compatibility with OpenShift Origin v1/v2
public/ # Zend Framework v1/v2, Laravel, FuelPHP, Surebert etc.
public_html/ # Apache per-user web directories, Slim Framework etc.
web/ # Symfony etc.
www/ # Nette etc.
./ # Drupal, Wordpress, CakePHP, CodeIgniter, Joomla, Kohana, PIP etc.
See https://developers.openshift.com/en/php-repository-layout.html for more details.
try this:
goto app-root > repo
put your files in this folder. if you put a index.php, it will be accessible through the web.
but there's a more convenient method.
create a folder name php inside the repo folder and openshift will use it as a document root. which means all other files will be unaccessible from the public.
conclusion
put all other files in app-root>repo. put the index.php in the php folder and link other files accordingly.
optional:
use GIT. its easy and way more convenient than sftp. you need to learn only 4 commands.
git add
git commit
git push
git clone
that's it!
edit1
IF php/ dir exists THEN DocumentRoot=php/
ELSE IF public/ dir exists THEN DocumentRoot=public/
ELSE IF public_html/ dir exists THEN DocumentRoot=public_html/
ELSE IF web/ dir exists THEN DocumentRoot=web/
ELSE IF www/ dir exists THEN DocumentRoot=www/
ELSE DocumentRoot=/
above is the priority of document roots in openshift. use whatever you like.
Had the same problem. You need to turn off APC cache. This can be done via an .htaccess file:
php_flag apc.cache_by_default Off
I'm trying to deploy an PHP application which is written with Zend Framework to a shared cPanel server.
There are not many tutorials available on this area online, however, I followed several of them. It is successful to run the test page which proves the zend framework is installed correctly.
However, since cPanel server has a default root directory called public_html/, it is impossible to simply rename it to the Zend Server's default public/.
As a result, I had two options in mind: (Say the project name is AAA)
1) upload my projects under the /public_html/ directory, then the project will be like /public_html/AAA/public, and etc.
However, this one simply fails to work.
My thought would be something wrong here with the baseUrl setting, however, no matter I comment ( which is to remove the baseUrl) or set to the root page, ( in this case /public_html/AAA) both failed.
2) I tried to follow the way listed in this article: http://blog.motane.lu/2009/11/24/zend-framework-and-web-hosting-services/. Still failed.
Can anyone suggest how to do it?
Really appreciate your help!
Just symlink it:
ln -s public public_html
then this structure will work:
htdocs/
myvhost.com/
public/
application/
library/
public_html # this is actually a symlink pointing to public
Whatever you do, dont just throw everything in the publicly accessible area... its just bad form :-)
I don't think ZF cares what you name your "public" directory. It's just the convention that's typically used.
I can't think of any ZF component or common use case where anything explicitly points at "public/...".
A project structure like this should work:
myproject/
application/
library/
public_html/ # this used to be public until you renamed it.