Localhost url rewriting: mydomain/collection/resource - url-rewriting

My current project urls look like this:
localhost/mydomain/public/collection/resource.
I have several PHP projects running out of localhost at the moment. I would like the url for this project to be as it would in production so I'm not coding around the url. Is there a way to get this to be mydomain/collection/resource?

The solution was to implement apache vHosts:
<VirtualHost 127.0.0.1>
ServerName mydomain.com
DocumentRoot "C:/Bitnami/wampstack-5.6.21-2/apache2/htdocs/mydomain/public"
</VirtualHost>
<Directory "C:/Bitnami/wampstack-5.6.21-2/apache2/htdocs/mydomain/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Related

URL not found on server when uploading Laravel project

I have a Laravel project that is on a live server and I have made a copy to place in a development server. When I try to login, it says The requested URL /xxxx/login was not found on this server..
I am not quite sure what to do, as I changed my httpd.conf to
<Directory "/var/www">
AllowOverride All
Require all granted
</Directory>
and
<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>
but I am still getting the same error after restarting apache. Is there any way to solve this?
I think you didn't config for the virtual host or you config it wrong.
You can find that config file under folder /etc/httpd/conf.d/vhosts/ Below are a sample file config:
$ cat /etc/httpd/conf.d/vhosts/yoursife.conf
<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin youradmin_server_mail
DocumentRoot /your_src_path/public/
<Directory "/your_src_path/public/" >
Options FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /your_src_path/public/logs/error_log
CustomLog /your_src_path/public/logs/access_log combined
</VirtualHost>
You can create a new file if you want.

Run Laravel on another URL root path http://example.xom/laravel_proj1 and http://example.xom/laravel_proj2

I want to use Laravel projects at the same time. How you can do it? For example one project at
http://example.xom/laravel_proj1
and another on
http://example.xom/laravel_proj2
Configuration: Laravel 7 / 8 and Apache
Update: This is 2 different Projects. But are there some problems if I use this 2 equals Projects. Upsides of MySQL Datables of course.
File: /opt/bitnami/apache2/conf/vhosts/APPNAME-vhost.conf
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias *
DocumentRoot /opt/bitnami/projects/APPNAME/public
<Directory "/opt/bitnami/projects/APPNAME/public">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Usually you work with subdomains to have multiple laravel projects running at the same time. This means that one instance runs at first.example.com and the other at second.example.com. In my opinion what you are trying is more a workaround if you only have one vhost running.
So I would have two vhost files like you have now. One like:
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias first.example.com
DocumentRoot /opt/bitnami/projects/first/public
<Directory "/opt/bitnami/projects/first/public">
...
</Directory>
</VirtualHost>
and
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias second.example.com
DocumentRoot /opt/bitnami/projects/second/public
<Directory "/opt/bitnami/projects/second/public">
...
</Directory>
</VirtualHost>
Then you would add both subdomains to your hosts file. I don't know where that one is located but in there you would have to add:
127.0.0.1 first.example.com
127.0.0.1 second.example.com
This is not exactly how I do it now, but I think it could be a good starting point. You also need to activate your vhosts and restart apache.

Hosting Mutiple laravel project in sub-directory in same server

I am struggling to host the multiple laravel project in same server in sub-directory.
I want to run laravel project in example.com/CoreApp and example.com/DataSync
Project Directory:
- Root directory (example.com): React Js Project
- CoreApp (example.com/CoreApp) : Laravel Project
- DataSync (example.com/DataSync) : Laravel Project
Here is the current issue I am facing now.
example.com/ => It is working fine.
example.com/CoreApp => It is working fine.
example.com/DataSync => It is serving me 404 page whereas its other routes are working fine. Like example.com/DataSync/telescope is working fine.
Note: Also, I have added RewriteBase /DataSync and RewriteBase /CoreApp in respective project in .htaccess
Here's my config:
Server Config:
- Digital Ocean Server
- Apache web server
- Ubuntu 16
Here is what my virtual host look like.
<VirtualHost *:80>
DocumentRoot /var/www/sites/html
Alias /CoreApp /var/www/sites/html/CoreApp
Alias /DataSync /var/www/sites/html/DataSync
<Directory /var/www/sites/html/CoreApp>
AllowOverride All
DirectoryIndex index.php
</Directory>
<Directory /var/www/sites/html/DataSync>
AllowOverride All
DirectoryIndex index.php
</Directory>
ServerName www.example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
<Directory "/var/www/sites/html">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/sites/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateKeyFile /etc/ssl/sites/key/myserver.key
SSLCertificateFile /etc/ssl/sites/certs/example_com.crt
SSLCertificateChainFile /etc/ssl/sites/certs/example_com.ca-bundle
<Directory "/var/www/sites/html">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Change in you virtual host file for Alias as:
Alias /CoreApp /var/www/sites/html/CoreApp/public
Alias /DataSync /var/www/sites/html/DataSync/public
you have to provide location of public folder
You should provide URL up to your-directory/public. If still issue. then provide URL up to your-directory/public/index.php.

Laravel 5.2 site on localhost/Wamp

I am trying to learn Laravel.
I created a project on c:/sites where I develop all my sites. I called it larabasic.dev
I cannot open the site in my browser, it keeps switching to www.larabasic.dev and tells me server not found.
I set up a virtual host like I did to all my other sites that works well.
I tried:
1. Changing server.php to index.php and copied the public/htaccess file to the root folder
2. Going to http://larabasic.dev/public
3. Going to http://larabasic.dev/public/index.php
4. Changing vhosts file to:
<VirtualHost *:80>
ServerName larabasic.dev
ServerAlias larabasic.dev
DocumentRoot "c:/sites/larabasic.dev/public"
<directory "c:/sites/larabasic.dev/public">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</directory>
</VirtualHost>
Instead of:
<VirtualHost *:80>
ServerName larabasic.dev
ServerAlias larabasic.dev
DocumentRoot "c:/sites/larabasic.dev"
<directory "c:/sites/larabasic.dev">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</directory>
</VirtualHost>
My hosts file has these 2 entries:
127.0.0.1 larabasic.dev And
::1 larabasic.dev
Nothing helps. Again, any other sites I have developed with plain php work fine.
What am I missing?
Thank you
I've encountered the same problem and I've fixed this by giving 127.0.0.2 to my laravel application.
First, in the hosts file, you need to redirect larabasic.dev to 127.0.0.2:
127.0.0.2 larabasic.dev
Second, you need to bind the virtual host to that IP:
<VirtualHost 127.0.0.2:80>
DocumentRoot "C:/sites/larabasic.dev/public"
ServerAdmin admin#localhost
ServerName larabasic.dev
ServerAlias www.larabasic.dev
<Directory "C:/sites/larabasic.dev/public">
AllowOverride All
Options Indexes FollowSymLinks
Require local
# if you want access from other pc's on your local network
#Require ip 192.168.1
# Only if you want the world to see your site
#Require all granted
</Directory>
</VirtualHost>
This is my working configuration on my local machine.

XAMPP VirtualHosts Access From Mobile Device

Could you please help me to access XAMPP localhost sites from a mobile device (either from home network or from internet)
I am using multiple virtual hosts to access all sites using a short link for each. Please see the configuration of virtual hosts below:
<VirtualHost *:80>
ServerName mysite
ServerAlias mysite
DocumentRoot "F:/Drive/Dev/mysite"
<Directory "F:/Drive/Dev/mysite">
AllowOverride All
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mysite2
ServerAlias mysite2
DocumentRoot "F:/Drive/Dev/mysite2"
<Directory "F:/Drive/Dev/mysite2">
AllowOverride All
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>
</VirtualHost>
and the host file:
127.0.0.1 mysite
127.0.0.1 mysite2
I have tried several suggestion found here, but non of them helped...
Thanks in advance.
ngrok creates a secure public URL (https://yourapp.ngrok.io) to a local webserver on your machine
test mobile apps against a development backend running on your machine.
https://ngrok.com/

Resources