I am new to Apache environment. Preferably I do not want .htaccess file, but I think I have not choice. My application runs without problem in my notebook which is windows environment using WAMPSERVER. But when I deploy to hosting server which uses Apache, I face some problems. I am not sure the following structure is correct for CodeIgniter application. Following is the directory structure in hosting server...
httodocs/
/survey
/admin
/config <-- $route['default_controller'] = "admin";
/controllers
/models
/views
/...
/statistic
/config <-- $route['default_controller'] = "statistic";
/controllers
/models
/views
/...
/mySurvey
/config <-- $route['default_controller'] = "mySurvey";
/controllers
/models
/views
/...
/css
/images
/scripts
/system
/...
/index.php <-- $application_folder = 'mySurvey';
/admin.php <-- $application_folder = 'admin';
/Statistic.php <-- $application_folder = 'statistic';
What I did was just duplicate the Application folder and rename to admin, statistic and mySurvey respectively, I set the default controller as stated above.
all application base_url() = 'http://survey.myhost.com' which is a sub domain under myhost.com
The root index.php is actually CI application environment which allow user to go to mySurvey application by default, when they enter "http://survey.myhost.com".
From the first page on, when I access http://survey.myhost.com/index.php/mySurvey/index/0
I got error:
`The specified CGI application misbehaved by not retruning a complete set of HTTP headers.`
The same message shows when I access http://survey.myhost.com/admin.php/admin/login or http://survey.myhost.com/statistic.php?statistic/chart/1 (note that I also do use query string for my application)
Obviously, these have to do with the route. I do not have any .htaccess file at the server because WAMP does not need it, Appreciate if anyone can advice where can I put the .htaccess file and what is the correct mod-rewrite for the structure above and is this structure appropriate.
Regards,
KK Gian
root
/subs
/survey (survey.domain.tld)
/application (CI application folder)
/config
/models
...
index.php (CI index.php file)
/statistics
/application (CI application folder)
/config
/models
...
index.php (CI index.php file)
/mySurvey
/application (CI application folder)
/config
/models
...
index.php (CI index.php file)
/system (CI system folder)
in every index.php (subs/survey/index.php, subs/mysurvey/idnex.php, subs/statistics/index.php) you will link at root/system/ folder so
$system_path = '../../system';
now you can easily go to survey.myhost.com, statistics.myhost.com etc. remove index.php, admin.php strings from url ($config['index_page'] = '';)
hope I got what you want
sorry for my english
Related
Im trying to deploy my laravel project with namecheap however I'm getting a 500 server error.I've updated the server.php and index.php to point to the correct directories but I'm still getting the error. I've checked the error.log file in the public_html directory but it doesn't give any error when loading the site. I've also double checked the .env file to make sure the correct database credentials were entered.
index.php
if (file_exists(__DIR__.'/../nue/storage/framework/maintenance.php')) {
require __DIR__.'/../nue/storage/framework/maintenance.php';
}
require __DIR__.'/../nameofproject/vendor/autoload.php';
$app = require_once __DIR__.'/../nameofproject/bootstrap/app.php';
server.php
require_once __DIR__.'/../nameofproject/public_html/index.php';
Whenever I deploy my Laravel project in a sharedhost. These things I do
Copy the entire application directory (appname) inside public_html
Path to the domain will be "public_html/appname/public"
Link storage path using ssh
If your Laravel project is installed in the webroot (assuming public_html), then do the following:
Move the contents of public/ up one dir to the webroot. index.php and server.php should now be in the same dir as your .env.
In index.php, change ../vendor/autoload.php to just vendor/autoload.php and ../bootstrap/app.php to just bootstrap/app.php.
In server.php, change public/index.php to just index.php.
I am trying to deploy my Laravel project on a shared host(godaddy) and so far I have only partially succeeded.
Steps I followed:
Create a subdomain abc.xyz.com , root -> public_html/finance/.
Upload my laravel project to a folder which is at same level as that of public_html
softlink the public directory of my project to public_html/finance/
I found that going to abc.xyz.com didn't work but abc.xyz.com/public did so I set up a redirect which redirects abc.xyz.com to abc.xyz.com
making Storage accessible for web.
dumpautoload, caching config and routes.
migarting databases.
Now I can successfully login which takes me to abc.xyz.com/public but my all other routes which does not have /public do not work.
For example:
abc.xyz.com/public - works
abc.xyz.com/home - doesn't work
I noticed that if I manually add /public to all routes they work!. so abc.xyz.com/public/home works.
my .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
So how can append /public like abc.xyz.com/public to all the routes?
I am not very good at modifying .htaccess but I tried some solutions from online and they did not work.
Excerpted from Deploy Laravel 5 App on Shared Hosting on Linux Server. The original authors were Donkarnash, PassionInfinite, Pete Houston and Kyslik. Attribution details can be found on the contributor page. The source is licenced under CC BY-SA 3.0 and may be found in the Documentation archive. Reference topic ID: 2410.
By default Laravel project's public folder exposes the content of the app which can be requested from anywhere by anyone, the rest of the app code is invisible or inaccessible to anyone without proper permissions.
After developing the application on your development machine, it needs to be pushed to a production server so that it can be accessed through the internet from anywhere - right?
For most apps/websites the first choice is to use shared hosting package from hosting service providers like GoDaddy, HostGator etc. mainly due to low cost.
note: you may ask your provider to manually change document_root, so all you have to do is upload your Laravel application to server (via FTP), request change of root to {app}/public and you should be good.
Such shared hosting packages, however do have limitations in terms of terminal access and file permissions. By default one has to upload their app/code to the public_html folder on their shared hosting account.
So if you want to upload a Laravel project to a shared hosting account how would you go about it? Should you upload the entire app (folder) to the public_html folder on your shared hosting account? - Certainly NO
Because everything in the public_html folder is accessible "publically i.e. by anyone" which would be a big security risk.
Steps to upload a project to shared hosting account - the Laravel way
Step 1
Create a folder called laravel (or anything you like) on the same level as the public_html folder.
Eg:
/
|--var
|---www
|----laravel //create this folder in your shared hosting account
|----public_html
|----log
Step 2
Copy every thing except the public folder from your laravel project (on development machine) in the laravel folder (on server host - shared hosting account).
You can use:
- C-panel : which would be the slowest option
- FTP Client: like FileZilla to connect to you shared hosting account and transfer your files and folders through FTP upload
- Map Network Drive: you can also create a mapped network drive on your development machine to connect to your shared hosting account's root folder using "ftp://your-domain-name" as the network address.
Step 3
Open the public folder of your laravel project (on development machine), copy everything and paste in the public_html folder (on server host - shared hosting account).
Step 4
Now open the index.php file in the public_html folder on the shared hosting account (in cpanel editor or any other connected editor) and:
Change:
require __DIR__.'/../bootstrap/autoload.php';
To:
require __DIR__.'/../laravel/bootstrap/autoload.php';
And Change:
$app = require_once __DIR__.'/../bootstrap/app.php';
To:
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
Save and close.
Step 5
Now go to the laravel folder (on shared hosting account -server) and open server.php file
Change
require_once __DIR__.'/public/index.php';
To:
require_once __DIR__.'../public_html/index.php';
Save and close.
Step 6
Set file permissions for the laravel/storage folder (recursively) and all files, sub-folders and file within them on shared hosting account - server to 777.
Note: Be careful with the file permissions in linux, they are like double edged sword, if not used correctly, they may make your app vulnerable to attacks. For understanding Linux file permissions you can read https://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions
Step 7
As .env file of local/development server is Ignored by git and it should be ignored as it has all the environment variables including the APP_KEY and it should not be exposed to public by pushing it into the repositories'. You can also see that .gitignore file has .env mentioned thus it will not upload it to repositories.
After following all the above steps make a .env file in the laravel folder and add all the environment variable which you have used from the local/development server's .env file to the .env file of production server.
Even there are configuration files like app.php, database.php in config folder of laravel application which defines this variables as by default in second parameter of env() but don't hard-code the values in these files as it will affect the configuration files of the users who pulls your repository. So it is recommended to create .env file manually!
Also laravel gives .env-example file that you can use as a reference.
That's it.
Now when you visit the url which you configured as the domain with your server, your laravel app should work just as it worked on your localhost - development machine, while still the application code is safe and not accessible by anyone without proper file permissions.
You can probably move your public/.htaccess and public/index.php to the root files of your laravel project.
You need to change the document root for you website to be the public folder of your application i.e.
public_html/finance/.
should be:
public_html/finance/public
https://laravel.com/docs/5.4/installation#configuration
Hope this helps!
The problem is that you have placed the entire project in the public directory - public_html, haven't you? This is a bad practice (security).
Your domain (abc.xyz.com) points to your application root directory, should go to the app/public dir.
Update Solution: require DIR.'/../bootstrap/autoload.php';
Is now: require DIR.'/../vendor/autoload.php';
So Change To require __DIR__.'/../laravel/vendor/autoload.php';
In addition to pointing to the correct files and folders, add the below .htaccess file. Credit - Kylevorster
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I'm building a Laravel application, and it will be in a subfolder of a current project. I'm trying to get rid of the /public in the URL, so that the users can view the project at this URL :
www.domain.com/project
instead of the default ...
www.domain.com/project/public
I did some digging on StackOverflow and the Laracasts forum, and I tried this, in a .htaccess file at the root of my project :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
However, my routes doesn't work anymore when I do this. Even the default route for / stopped working.
A lot of answers mention that the best way is to change the root in the Apache config, so that it serves the files from /public instead of at the root of the directory.
The problem is that this in a subfolder of a main project, how can I make it so that only this project is affected? The website at www.domain.com works fine and does not have a /public in the URL.
There are a couple options. I don't think you want to try fixing this at the htaccess level with mod rewrites (or anything like that)
One option is to create another virtual host that listens on an abitrary port (eg, 8080). Then set the document root for this virtual host to .../public/
Another option, you can spoof the dns in your /etc/hosts or Windows hosts file, and set up a dev.domain.com virtual host.
•Go to mainproject/public>>
a. .htacess
b. favicon.ico
c. index.php
d. robots.txt
e. web.config
1.cut these 5 files from public folder,and then paste on the main project folder that’s means out side of public folder… mainproject/files
2.Next after paste ,open index.php ,modify
•require __DIR__.'/…/bootstrap/autoload.php'; to
•require __DIR__.'/bootstrap/autoload.php';
modify
- $app = require_once DIR.'/../bootstrap/app.php'; to
- $app = require_once DIR.'/bootstrap/app.php';
I have a site with the url http://localhost/my-site/. A file called test.php exists on root, a folder named test does not exist.
When I open a link like http://localhost/my-site/test/, the file test.php is opened. Should it not give a 404 error instead? I have no .htaccess file doing any funny business. The rewriting seems to be done before any .htaccess file is being run, as a rewrite rule of test/ does not match anything. A rewrite rule of test.php does however match.
I am using WampServer 2.2 with Apache 2.4.2.
This sounds like a mod_negotiation/Multiviews issue.
In the appropriate place (say, in your vhost config, or in the htaccess file in my-site's directory, include in the Options a - multiviews:
Options -Multiviews
I would like to setup a staging and production environment on one shared server. So, optimally, I would like to be able to create a structure like the following on the server:
/stage/
/lib/
/web/
/js/
/css/
index.php
...
/production/
/lib/
/web/
/js/
/css/
index.php
...
However, although I am able to change the document root of an added subdomain or addon domain, I am unable to change the document root of the primary domain. So, I am stuck with the document root being /public_html/.
I would like the staging environment to be accessible through stage.domain.com (pointing to /stage/web/), and every other subdomain, *.domain.com or domain.com, route to the production environment (pointing to /production/web/).
With that in mind, I believe I need a robust mod_rewrite script to do the job (.htaccess level). Since, I am a novice at mod_rewrite, does someone know how to write a script that will transparently route the requests appropriately?
or
Is there a better way to handle these two environments on a shared server?
If you can't change the document root of main domain. Can you create a symlink in public_html name production folder to /web/production. Enable symlinks.
RewriteCond {REQUEST_FILENAME} !-f
RewrireRule ^(.*)$ production/$1 [QSA,L]