Zend Framework App .htaccess - php

I'm trying to make a simple Zend Webapp running on a shared host. The root folder after logging on FTP server is a folder named 'www'. So the structure is:
/www
/tasklist
/application
/library
/public
/.htaccess
Hosting provider demands to have all paths in .htacccess file absolute. Considering this, the path to main index.php of my Zend app is:
http://aportsupport.cz/tasklist/public/index.php
Which is also a link at which I am able to access my app but with other paths to certain files (css, js etc.) do not work. When I try to access my app with:
http://aportsupport.cz/tasklist/
I only get 404 or 403 error depending on various setups of .htaccess I've already tried.
I have no access to error log, nor any server configs. Default controller is 'index', action 'index', module 'default'.

In a Zend application, the .htaccess should be in your public folder, so your folder tree will look like this:
/www
/tasklist
/application
/library
/public
/.htaccess
Your .htaccess can be kept simple for most Zend applications. Try this text out for .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
What this breaks down to is that no matter what url is requested from this root directory, it will try to fetch the file /www/tasklist/public/index.php, which will bootstrap the Zend application.
Remember that if your hosting provider does not support Zend Framework, it may not work out at all. Hosting providers like http://www.phpcloud.com/ do allow Zend-based applications but you have to specify it on container creation.

Thank you for your response, however, I've finally managed to make it work myself. For all those who might have similar issues this solution worked for me:
I created a subdomain 'tasklist.aportsupport.cz' which has its own root folder on my shared host. In this folder I put all Zend folders with their default structure. Also I created index.php file in which I wrote this:
<?php include 'public/index.php';
This index.php is located in root of tasklist.aportsupport.cz with default Zend Framewrok .htaccess in which I added this line:
RewriteBase /
Also all CSS, JS, imgs etc. files are located in that root folder. Everything works just fine!

Related

How to deploy laravel project on the godaddy hosting server (Plesk Onyx CPanel)

I currently new for deploying a project files to the godaddy hosting sites, so before i post this, I read some related question created already here in stackoverflow, I just confuse because there cpanel has public_html folder and my panel has no public html. so right now I experience
HTTP Error 404. The requested resource is not found.
The things only I do is to move the laravel files in the httpdocs.
My CPanel : Plesk Onyx 17.8.11
For the folder structure:
So Inside of httpdocs are all of my laravel files
Website shows like this..
Hope someone help me for this problem.
I think the reason your folder structure is like this is that your GoDaddy Hosting is a Windows Shared Hosting.
What to basically need to do is create a folder for your app on the home directory and then on the httpdocs, put the public folder from your app.
GoDaddy Plesk Folder List:
cgi-bin
error_docs
httpdocs
logs
<your laravel app folder minus the "Public" folder>
Inside the httpdocs folder:
App_Data
.user.ini
Default.aspx
web.config
<+ contents of your Public folder>
Once this is complete, you will need to edit a few files:
From Public Folder: index.php
Find:
require __DIR__.'/../vendor/autoload.php';
Change to:
require __DIR__.'/../<laravel app folder>/vendor/autoload.php';
Next Find:
$app = require_once __DIR__.'/../bootstrap/app.php';
Change to:
$app = require_once __DIR__.'/../<laravel app folder>/bootstrap/app.php';
After this, make sure the .env file is properly configured and all the tables from your local database is mirrored in you server database.
Also, if you have open_dir problems, you can disable it on the PHP Settings from Plesk but I am not sure what are the issues this will cause in the long run.
Well, there are two ways...
1st in cpanel search for "Installatron Applications Installer" or somekind of app installer :)
In installatron app installer screen on right top find "Applications Browser" from there search for Laravel and install it by choosing your domain(If you have more than one domain)
After installation copy and replace your local files with the remote files.
2nd second way, .zip your local laravel folder. And upload your files to your server, and then extract the files.
NOW FROM HERE IT'S THE SAME FOR BOTH WAYS->
"public" directory in laravel project will be in the root of your remote server(root folder for your domain, If you have addon domains for ex. public_html/example.com then "public" folder should be in that example.com)
make another folder and put all other laravel files and folders in that folder.
open and edit /public/index.php
change these two lines->
require DIR.'/../vendor/autoload.php';
app = require_once DIR.'/../bootstrap/app.php';
to reflect the file structure in your server.
For ex. if "public" folder is in the same directory with "vendor" and "bootstrap" remove /..
Edit your .env file pay attention to database credentials.
PS: do not change database host address it should remain same.
AND FINALLY the .htaccess files
you need to have two .htaccess files
one in "public" directory content like this->
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Second .htaccess file will be in the root folder of the domain with content->
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
ONE PROBLEM YOU MIGHT COME ACCROSS if php version problem stating that composer dependencies version is php7.xx bla bla
If this happens go to cpanel again and search for "Select PHP Version"
From there change your current PHP version to suit with the PHP version you get in the error. And you need to click "Set as current"!
That's it :)

Deploying Yii2 into shared hosting, Directly to basic template folder

I have read the doc from Yii2 official website to deploy yii2 into share host from this : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html, and about discussion on this : stackoverflow.
So, I decide to use sftp to upload the yii2 folder.
And this is the list of directory in my share host.
access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)
You know, because the share host can hold on domains untill 5 domains,
is it possible to upload yii2basic folder into public_html folder ?
So the result like this :
access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)
Because now, if I want to access my web, I have to write like this : mydomain.com/basic/public_html/index.php
I need like this :
mydomain.com/index.php
Please guide me.
Yes you can upload it inside the public_html folder but the only problem that I have been facing nowadays with yii2 basic app is the pretty URLs, you can clone or upload entire contents inside the public_html folder, what I did is as follows only the difference is I have a web folder instead of www
directory structure
public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web
public_html/.htaccess
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
public_html/web/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this works but in the URL it shows /web/index.php?r=site/index and as soon as I turn the prettyUrl on in the config file urlManager it would only show default index page and every link I try to open ends up on the home page view although the URL in the address bar is correct and urlManager parses the rules correctly, this is as far as I have gone.
If you don't mind bunch of Yii 2 folders in your root folder just place all basic template folders (except web) and files in the root folder. Then place the content of web folder in the public_html folder.
It should be something like:
access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets

Remove public from URL Laravel 5.3

I'm using Laravel 5.3 is there a easy way to remove public from URL? is it necessary to add a htacces. when I change the htacces it is getting a n error like below,
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess or Laravel related files, just point web server to a public directory instead of Laravel project directory:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
Add a .htaccess file in root which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Yes it is very simple no need to add extra htaccess,
Create a new folder in your laravel project folder.
Name it whatever you like. Example :- source
Move all the files from root into 'source' folder except 'public' folder.
4 . Move all the files from public folder to root.
5 . Change the autoload.php path
6 . Thats all. remove public folder if necessary.
In the root directory create a .htaccess file and put the following in
it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Even above solution(s) work(s) for you,but I would recommend not to do this.
Here is the reason why.
-You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
-you have to configure apache for user not access .env, git files , config folder's file
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.
Copy all files and folder from public folder to root folder and edit your .htaccess file as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And dont forget to change the paths in index.php file.
For details refere following links
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511

Apache rewrite for Laravel /public

I am sorry about this, but my htdocs root is wrong and I can't change that. So I have to make it work in the /public folder.
I use the normal Laravel .htaccess file with the following rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If I open http://kemtime2_neu.pr.domain.de/public I get redirected to http://kemtime2_neu.pr.domain.de/public/http://kemtime2_neu.pr.domain.de/public/login
How can I fix this?
I would love to make it work from http://kemtime2_neu.pr.domain.de/ but getting it to work with http://kemtime2_neu.pr.domain.de/public/ would be fine.
I use the 3 solution of this post and works fine:
http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258
Solution 1 - Alternate installation path with symlink.
This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.
For example:
Install your application to /home/applications/mysite.com
Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs
Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs
Solution 2 - .htaccess with mod_rewrite
This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Step 1. Place Laravel in your document root folder.
Step 2. Place the following .htaccess file in your document root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments
Solution 3 - merge the public folder into the installation root
This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:
require '../paths.php';
to
require 'paths.php';
Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.
Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.
I solved it partly. If I have a .htaccess in the root instead of /public with
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.

fuelPHP: Can't Access My Controllers Directly

I am trying to learn fuelPHP and I came form a CI background. I am using this tutorial so that I can familiarize myself on this.
http://net.tutsplus.com/tutorials/php/getting-started-with-the-fuel-php-framework/
My problem is in step 2. When I access my simple controller
http://localhost/fuel/public/index.php/hello
I get a 404 error.
*fuel is the directory of this freshly installed fuelPHP on my localhost.
When I set this to be my default route, the controller works.
Did something change in the new version that prompted this?
Here is my .htaccess on the /public/ folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Thanks.
You are making it very complicated for yourself by installing FuelPHP like this.
It has been designed in such a way that the 'public' folder is your webservers document root, which means all fuel stuff is outside your document root, and the .htaccess is directly inside your document root.
By not only installing it entirely inside your document root, but also in a subfolder of that document root, you need to modify your rewrite rules. Start by adding
RewriteBase /fuel/public
to the one in public, and see if that helps. Also, this .htaccess is made for "standard" apache type installations. If you run anything else you might need a different .htaccess. If you use fcgi for example, get the .htaccess from the 1.4/develop repo, it's more fault tolerant towards your webserver type.
Final remark: you should not use localhost as hostname. It's an illegal name in a lot of RFC's, one of them being the one that documents the use of cookies. You'll have all kinds of session issues with some browser (versions) if you use "localhost". Instead, setup virtual hosts (a better solution then subfolders anyway), and use a hostname like "mymachine.local".

Categories