Zend Server localhost and mod rewrite - mod-rewrite

I am using zend server and zend studio on my local windows machine php 7 with MySQL community installed.. I have went through several documents in order to set up my projects properly but I have ran into a issue.. I wanted to use the automatic upload and have the ability to enable back to local development. and have successfully done so.. my issue is that I had to deploy to localhost when I am not uploading to server in order to work with local..
mod re write is enabled and working.. but my first issue is that it seems to create 2 directories
The application name is orbit_cms
the application url: http://localhost/orbitcms
now I have a .htaccess in the folder orbitcms with the following.
RewriteEngine on
#Production
#RewriteCond %{REQUEST_FILENAME}.php -f
#RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
#Development
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
then if I go to http://localhost/orbitcms/index.php it works,
but this will not
http://localhost/orbitcms/index
now if I put in the app folder name
http://localhost/orbit_cms/index it works
now zend writes a config when it deploys and here it is
Alias /orbitcms "C:\Program Files (x86)\Zend\ZendServer\data\apps\http\__default__\0\orbitcms\1.0.0_41/"
<Directory "C:\Program Files (x86)\Zend\ZendServer\data\apps\http\__default__\0\orbitcms\1.0.0_41/">
AllowOverride All
Options +Indexes +FollowSymLinks +ExecCGI
DirectoryIndex index.php
Require all granted
</Directory>
The other issue is the mod re write..
the production part does not work on localhost but the development one does.. any reason why?

Related

After Deployment, Images not showing in Laravel

I created Common Helper for Image Upload & Common Trait Function for get Images Full URL from Storage & I tested it in Laravel's default inbuilt server it's 1005 perfectly works.
but after Deployment I can't Display Images. it's show 404 error to me
I shared my Common function of Get Full URL path of Image from storage.
app/Traits>HasProfilePhoto.php file
public function getProfilePhotoUrlAttribute()
{
return $this->profile_photo_path
? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path)
: \URL::to('/').'/adminLTE/dist/img/user-img.png';
}
above function will returns Image's Full URL Path Like."test.com/storage/users/user.png"
using Laravel's Default Inbuilt server it returns Full URL like this. http://localhost:8000/storage/users/user.png & using that path image display perfectly
but after the deployment in local Windows using XAMPP Server, it returns Full URL like this. http://localhost/ProjectFolderName/storage/users/user.png & it's show 404 Not Found
NOTE:- If I use FULL Url like this:- http://localhost/ProjectFolderName/public/storage/users/user.png then image displayed
Please Help me what's my mistake there?
*
**How I deployed my Laravel Project see below:- **
*
root/server.php file renamed with index.php
& root/public/.htaccess file copied at root directory
Rename the server.php file to index.php is not good practice for security reasons as well. So if you need to hide the public path from the URL then create a .htaccess at root level:
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</ifmodule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</ifmodule>
Updated by Harsh Patel:- 8th September 2021
Actually Problem is about defining Virtual Host in Server... I was defined DocumentRoot path & Directory path as like "C:/xampp/htdocs/projectFolderName/ this.
I was identified my mistake in deployment from here medium's Blog
but as per Laravel Documentation , we need to direct all requests to public/index.php in other words Laravel's Public Folder is an Our Server's Root (public_html) folder that's why I need to define DocumentRoot & Directory up to public folder like this C:/xampp/htdocs/projectFolderName/public
We need to define our Laravel Web in Apache Server's Virtual Host Config.
for XAMPP Server
step 1: open C:\xampp\apache\conf\extra path location in XAMPP Server
step 2: Open httpd-vhosts.conf File
step 3: define virtual host rule as like below
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:/xampp/htdocs/projectFolderName/public"
<Directory "C:/xampp/htdocs/projectFolderName/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
IF you faced any problem to define Virtual Host in XAMPP then you can see Full detailed answer about How to define Virtual Host in XAMPP
& If you Use WAMPP Server then you can see Full detailed answers about How to define Virtual Host in WAMPP
Maybe you just need to set your projects URL inside .env to start with http://
APP_URL=http://your-project-url
Without this, images will not have proper URL but when you copy image path and open it inside new tab, image will be available anyway.

How to point bookstack (Laravel) application's public folder on a mydomain.com/bookstack

Hi I am trying to host bookstack application which is basically a larvel application on a shared hosting, After uploading database dump from local and uploading all the files to public_html/bookstack folder.
Now I am able to visit the webapp at https://example.com/bookstack/public , but I want to host the site at example.com/bookstack only and don't want the "public" in url.
I have two questions,
1) How to achieve it using .htaccess file?
2) Inside the .env file there is an option
# Application URL
# Remove the hash below and set a URL if using BookStack behind
# a proxy, if using a third-party authentication option.
# This must be the root URL that you want to host BookStack on.
# All URL's in BookStack will be generated using this value.
#APP_URL=https://example.com
So if here I put APP_URL as https://example.com/bookstack , and remove the comment, its first giving "403 Forbidden - You don't have permission to access this resource." error and if I visit to https://example.com/bookstack/public it works fine.
Update : So I found this subdirectory setup page in bookstack documentation but it only describe how to setup if I have access of apache, which is not possible in case of shared hosting
Move the .htaccess file in /public to root.
Rename server.php file in root to index.php.
you can dos this
<VirtualHost *:80>
...
# BookStack Configuration
Alias "/bookstack" "/var/www/bookstack/public"
<Directory "/var/www/bookstack/public">
Options FollowSymlinks
AllowOverride None
Require all granted
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]
</Directory>
<Directory "/var/www/bookstack">
AllowOverride None
Require all denied
</Directory>
# End BookStack Configuration
...
for more deatail you can see this reference.
Setup Sub Path in BookStack
Thanks

CakePHP on a Mac - Homebrew HTTPD

I'm trying to run CakePHP 4 or 3.8 on macOS Catalina with Homebrew httpd and PHP 7.3.13
I run composer as mentioned on cookbook and installation goes well but, when try to run te app via browser I get this error:
safari screen
chrome screen
on error log message get "AH00052: child pid 10126 exit signal Illegal instruction (4)".
I have also the extensions intl, mbscript, pear, rewrite, etc enabled.
My virtual host is like this:
DocumentRoot "/Users/webdev/Sites/cakephp/webroot"
ServerName cakephp.localhost
<Directory "/Users/webdev/Sites/cakephp/webroot">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog "/Users/webdev/Sites/Error_Logs/error.log
the .htaccess file on root of app is:
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
And in webroot folder is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I've already tried many suggestions but nothing solve the problem.
I don't know what to do more because, just CakePHP don't work and i've other apps like Laravel and work like a charm on this machine.
If anyone can help with solution, thanks in advance.
I figured out what being wrong in my case.
When I configured virtual host and hosts file to "something.localhost" server dropped connection.
Changed configuration to "something.something_else" in httpd-username.conf and /etc/hosts, all cake instances start working.
This works for me.

Laravel version 5.7 root show index of page

Recently I am start using Laravel, and I develop a website in my local which works fine, but when I deploy it to a droplet in DigitalOcean, the root shows an index Of page.
Screen Capture is here
And when I navigate into the public folder, it shows a 500 error.
I have tried to include a few different .htaccess, which does not solve the problem. And my current .htaccess is below
DirectoryIndex index.php
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
The line "Options -MultiViews" is actually part of the .htaccess code too.
Could anyone please help me to solve this problem?
Thank you in advance.
See more here
In the server config file is the AllowOverride set to All or None? If its set to none all .htaccess changes will be ignored.
<Directory /var/www/YOURAPP/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Don't forget to generate a key...
php artisan key:generate
https://laravel.com/docs/5.7/installation

Apache mod-rewrite in httpd.conf not working

I need to make a change to my Apache web server to redirect requests for the home page from iPhone browsers to a different page. I've edited the /etc/httpd/conf/httpd.conf file and added the following:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^/$ /iphone/index.html [L]
After making the change, I restarted httpd, but the redirect doesn't work.
Am I missing something? Do the edits need to be made to a specific location in the httpd.conf file?
Other info: Server is vps hosted by Lunarpages running CentOS 5.5 and Apache 2.2.3.
For me, I use like below
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^[\./]$ <MyDomain>/iphone/index.html [L]

Resources