Deploying Symfony2 on shared hosting - php

I can not find reply to my question.
I am trying to understand how i should deploy symfony2 app on shared hosting.
I know i should rename my "web" catalog to "public_html", but i have many sites in this catalog.
My catalog's structure is like:
-public_html
-www.firstsite.com
-www.secondsite.com
...
-www.nextsite.com
-private_html
So where i should put my files? app,src,vendor under public_html, and files from web i should put directly to "public_html"? Or catalog web should be in public_html and other files under public_html?
So i will have:
-public_html
-...
-web
-private_html
-app
-src
-...
EDIT:
Now i have whole app in "public_html/example/"
It's work fine, but it is safe?

You should create a folder for your new website inside "public_html".
Let's say you have the domain "example.com".
You will have: public_html/example.com, public_html/example2.com, ..
Inside the folder example.com you will copy the folders: app, src, public.. (all Symfony's project main folders and files).
To answer to your question. "EDIT: Now i have whole app in "public_html/example/" It's work fine, but it is safe?". Yes, it's safe.
Just search on google for: "prevent directory traversal", if you want to make sure that it's secure.

Alternative solution could be installing/deploying Symfony in a folder outside "public_html", let's name it "symfony_app".
Then, your directory structure could look something like this:
-public_html
-www.firstsite.com
-www.secondsite.com
...
-symfony_app
And then, you should make a symlink of a Symfony "web" folder in the "public_html" folder.
For example:
ln -s /home/your_username/symfony_app/web /home/your_username/public_html/www.symfony-site.com
** folder named "www.symfony-site.com" must not exist in "public_html" before creating symlink!
Last step would be adding new subdomain in cPanel. There you should connect your new subdomain with "www.symfony-site.com" symlink inside "public_html".

Related

Will there be any issue if I redirect laravel project root path to public directory?

I want to deploy the Laravel project to my shared hosting.
When I go to my site main domain (example.com) It displays all directory and files but (example.com/public) works fine.
What if I just create an index.php file in the project root directory with following code
<?php
header('Location: ./public');
?>
It just redirects me to example.com/public.
Just tell me if there will be an issue that may occur at any point?
I am new to Laravel.
I don't care to remove the public directory. I only care if someone goes to example.com then it just redirects example.com/public to work fine.
Update
Just keep it short and simple answer (Yes/No) then explain it.
Is there will be an issue that occurs with the above steps (actions)? (Yes/No)
did you point your vhost to to the public directory?
For Apache
DocumentRoot [Laravel root direcoty]/public
For Nginx
root [Laravel root direcoty]/public;
Laravel Deploment
I'd suggest the easy way, by create a symbolic link of public_html and link it to your laravel project's public directory. don't forget to set your project folder permission.
here's the example: https://blog.netgloo.com/2016/01/29/deploy-laravel-application-on-shared-hosting/

Where to put composer in a CMS that is going to be used in other projects?

Currently I am developing a small headless CMS. If anyone wants to use it he should just copy the root folder of my CMS and put it into his public_html folder. So for any requests to the CMS the URL looks like this:
example.com/my-cms-name/subfolder/...
To better organize third-party libraries I decided to use composer. But now I have the composer.json file and the vendor file in my CMS folder which is going to be in the public_html folder. So everything from composer will be available for everybody which is obviously not a good practice.
How can I overcome this problem? Should I do all composer things separately in a different folder? But then the user of my CMS has to include multiple folders into multiple directories which makes everything more complicated...
I agree to Half Crazed. Probably people will have to upload your CMS files via FTP anyway and set a root path. So you might as well divide your scripts in private and public ones. So a directory structure like this might be a good idea.
-config
-public_html (root path that people must point their domain to)
-css
-javascript
-images
-index.php
-.htaccess (optional)
-src (where your namespaced script should reside )
--MyApp
-vendor
-composer.json
-composer.lock
Update composer.json and add your own src, run update command. Then include the vendor autoload.php in your index.php and go the router/controller way.

Hide "web" from URL in Symfony2.8 application

I have two different Symfony2.8 applications. During development they are accessible via two separated domains (virtual hosts): www.app1.local and www.app2.local. And everything works fine. But finally both applications should be deployed to the one server with one domain. Therefore I created two folders for each application.
Document root is /httpdocs, so file /httpdocs/test.php is accessible via www.domain.com/test.php. Two folders are /httpdocs/app1 and /httpdocs/app2. Each contains different installation of Symfony2.8 with own bundles etc.
And what is the problem? The web in URL. The URL to application looks like www.domain.com/app1/web/index.php instead of www.domain.com/app2/web/index.php. I'm trying to hide this web from URL but I don't have idea how to do this.
In general, it should be configurated via web-server itself. But if you don't have any access to configuration of web-server (Apache, nginx), you can do the following.
Put in your /httpdocs/app1 copy of app1/web, and in /httpdocs/app2 copy of app1/web
Applications themselves put in some other place.
So it will look, for example, like this:
app1/
app/
bin/
... # <--no web among these folders
composer.json
...
app2/
app/
bin/
... # <--no web among these folders
composer.json
...
httpdocs/
app1/
bundles/
....
index.php
app2/
bundles/
....
index.php
And then in your index.php fix paths to application
$loader = require __DIR__.'/../../app1/app/autoload.php';
include_once __DIR__.'/../../app1/var/bootstrap.php.cache';
(and same for app2, but with app2).
Also, fix both composer.json
"symfony-web-dir": "../httpdocs/app1",

Affect on security of Laravel 5 when change folder structure to remove public folder

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 !! :)

Setup Projects with CakePHP

If you setup your document root as C:\xampp\htdocs\ and you create a project folder named "ProjectX" where you include all your project files and folders and subfolders, how are you going to make your project runnable with url "http://localhost/projectx" ? I would like to learn how your config and routes files you included in your projects are changed ?
you can refer below link
http://book.cakephp.org/1.3/en/view/912/Installation
cheers
I would not run them as "localhost".
If you link css/js/img absolute to the / root, you will run into problems later on your life server.
it is always best to use virtual hosts and simulate the "real life" on your system:
http://www.dereuromark.de/2011/05/29/working-with-domains-locally/
You can create a folder projectx in C:\xampp\htdocs\
Then copy all the CakePHP files in C:\xampp\htdocs\projectx\ (including .htaccess, app\, lib\ and all. Setup the salt, cypher, db files and you should be able to access it through http://localhost/projectx/

Categories