Problems with friendly routes PHP - php

I did a basic project of an API using pure PHP, I used .htaccess to make everything written after my endreço, was assigned to the $path. I used a xampp through Windows 11 and changed the apache settings so that the rendered folder was that of my application
C:\xampp\htdocs\API
and everything worked perfectly, then transferred the files from my repository to my ubuntu machine on an EC2 AWS instance and changed the apache server settings so that the rendered folder was also changed, I used the following command:
sudo nano /etc/apache2/sites-available/your_domain.conf
and i set it up as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
when accessing my localhost, in windows, my application works normally (I will attach some images), but in my instance, it shows a Not Found error
here's my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]
my code
working on windows
index.php working on ubuntu
error in ubuntu :/
I believe the problem is in the apache settings in ubuntu but do not know how to solve, help!

Related

How to perfectly set up virtual host for codeigniter project?

I am trying to make a virtual host for a codeigniter project. I have done this in httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login">
Require all granted
</Directory>
</VirtualHost>
and in application/config/config.php,
$config['base_url'] = 'http://dev.facebook-login.com';
and
$config['index_page'] = '';
the browser opens the landing page. but when transiting from any other uri it says object not found.
And when i configure httpd-vhosts.conf like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login\index.php"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.php">
Require all granted
</Directory>
</VirtualHost>
It arises problem with assets things, i,e images and some css doesnt loads. How can I solve it?
I am on windows 10 and I use xampp with virtual host this is way I set up.
Put forward slash at end of base url
$config['base_url'] = 'http://dev.facebook-login.com/';
First go to
Windows > System32 > drivers > etc > host
You may need to open as administrator to be able to save it
You might see some thing like
127.0.0.1 localhost
Below that create another one for dev.facebook-login.com like example:
127.0.0.1 localhost
127.0.0.1 dev.facebook-login.com
Save it
Then go to the
xampp > apache > conf > extra > httpd-vhosts.conf
open it as administrator so you can save it.
No need for the index.php on DocumentRoot
<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
ServerName dev.facebook-login.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
Save it and restart the severs.
I use this for my htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
httpd-vhosts.conf
Listen 1122
<VirtualHost *:1122>
DocumentRoot "D:\laragon_server\www\hugpong_production"
<Directory "D:\laragon_server\www\hugpong_production">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
https://www.namecheap.com/support/knowledgebase/article.aspx/10026/33/installing-an-ssl-certificate-on-xampp/
php 8 is not ready for CI4 as of jan 2021!
XAMPP has preloaded ssl certificate in php 7 packages
consider uncommon vhosts extra and place this in it
my only persistent issues is codeigniter 4 routes, have to turn on php spark serve to get XAMPP to route pages outside of default index, nothing else works, its garbage to that extent, will try with composer next....a whole book needs
to be wrote about codeigniter 4 routes and why they don't work, 200 pages plus
<VirtualHost localhost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<VirtualHost example.com *:8080>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
//my project folder is codeignite4 without using composer this time
//i added listen 8080 under listen 80 in htppd.conf
ServerName example.com
<VirtualHost truservex.com *:443>
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
ServerName example.com
SSLEngine On
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
// you can verifiy these file locations, certificate data
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
// going without the Directory tag can be helpful to drop in vhosts
<Directory "C:\xampp\htdocs\codeignite4\public">
Require all granted
doing this i was able to replicate the original install, create site access
using http://localhost:8080 or http://example.com/ as my base url
in my example index.php is removed, set to ''
when using command prompt to get into codeignite4 project folder i can
launch php spark serve and routes will work that were previously 404
Using Xampp 7.3.25 Dec 2020 because php 8 will not run error
free with codeigniter 4 as of this date, this worked for me as
my first codeigniter 4 virtual host setup, my install had
difficulty initially with using port 80, seems to want to for
port 443 if it can..I'm not a server pro but i wanted to
leave this for the next guy....This is strictly name based
virtual hosts for develop, ip based would have obvious
advantages. Because i had trouble in initial CI4 testing with
port 80 the (*) in virtual hosts vs (*:80) seemed to solve one
hurdle in searching for more ports, now i can finally begin my
first project ...my default URL was also changed to example.com
in appstarter/apps/config file. Carefully reread <tags> for
typos, its easy to shut server down!
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/"
ServerName localhost
<Directory "C:/Xampp/htdocs/">
Require all granted
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/appstarter/public/"
ServerName example.com
ServerAlias www.example.com
# maybe don't attempt to use dir tag, shuts down server
# the directives at httpd.conf appear to suffice
I have added a htaccess file in the appstarter/public
I assume this is primitive, can get far more advanced
The Apache help pages helped me focus a bit more on
what i must accomplish, name based virtual hosts this case
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
2.2 Apache configuration: :Apache server context important!
Order allow,deny :The hackers are winning.....
Allow from all
2.4 Apache configuration:
Require all granted

Codeigniter vhost LAMP configuration troubleshoot

Running LAMP on UBUNTU 14LTS on virtualbox from win7 I found some hiccups.
I'm having trouble displaying my code igniter project in my machine. I have a followed some guides including this one:
tut 1 and tut 2
I can make the current configuration show a single HTML page, called example.com but it cannot show a complete code igniter project, I get this error when running it through the localhost:
NOT FOUND The requested URL /alpa_blog/en was not found on this server.
The project I'm working on is very big so bitnami is a bitslow so I'm planning to change to LAMP that is why I wanted to try and see a little blog on my localhost.
I have not used the LAMP on apache 2.4+ so I'm a little confuse about how to edit some files on vhost and tie them to the config.php inside code igniter.
I've tried a lot of different combination things but no success yet. Now I have my files #:
/etc/apache2/sites-available/alpa_blog.com.conf
/etc/apache2/sites-enabled/alpa_blog.com.conf
Looking like:
<VirtualHost *:80>
ServerName alpa_blog.com
ServerAlias www.alpa_blog.com
DocumentRoot /var/www/html/alpa_blog.com/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And # /etc/apache2/sites-available/000-default.conf
looks like:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
Plus my file alpa_blog.com/config/config.php code igniter's folder looks like:
$config['base_url'] = 'alpa_blog.com';
My etc/hosts folder looks like:
127.0.0.1 localhost
127.0.1.1 alpalamp-VirtualBox
127.0.1.1 example.com localhost
127.0.1.1 alpa_blog.com localhost
My var/www/html folder looks like:
alpa_blog.com ci example.com index.html phpinfo.php
Any pointers are much appreciated. Sorry for the your supposed to know that question, but it's driving me nuts.
EDIT:
I've tried several configurations on the .htaccess file.
This is my last version of the .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And config.php is like:
$config['index_page'] = '';
So after a while I found the answer, I thought to post it here just in case.
Going in the log file located at var/log/apache2/error.log I found this message:
[core:alert] [...] /var/www/html/APP-NAME/www/.htaccess: RewriteRule: bad flag delimiters, turns out that a regex expression was not properly written.
I Ended up by rewriting the rule on the .htaccessfile like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
Which solved the issue.
This post also helped out

Configuration of laravel under apache to avoid public

I recently installed laravel under a LAMP server, but can't get it to work if I don't specify public in the url for another routes than the index.php.
This is my apache site config (/etc/apache2/sites-available/furbook.com.conf):
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
Then created a symbolic link from /etc/apache2/sites-enabled:
sudo ln -s ../sites-available/furbook.com.conf
Finally, this is my .htaccess file in furbook/public:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
With this now I'm able to skip the public folder, localhost/furbook.com works redirecting to the public/index.php as expected.
But the problem is when I try to route an url like localhost/furbook.com/cats, then it throws a page not found error.
If I use localhost/furbook.com/public/catsthen works as expected.
What am I missing?
There's not quite enough information to answer you question 100% authoritatively -- here's my best guess.
If I use localhost/furbook.com/public/catsthen works as expected
Apache allows you to setup multiple "VirtualHost" configurations on a single server. A "VirtualHost" is a domain name like furbook.calhost.com that points to a specific folder on your computer. It's called Virtual because, at the time Apache was created, there was a strong bias towards "one host name/one physical server"
<VirtualHost *:80>
ServerName furbook.calhost.com
DocumentRoot "/var/www/html/furbook.com/public"
<Directory "/var/www/html/furbook.com/public">
AllowOverride all
</Directory>
</VirtualHost>
You have setup a virtual host for the name furbook.calhost.com
ServerName furbook.calhost.com
However, in your URL, you're still accessing the system via the name localhost. Accessing via localhost means apache will use the default host/site configuration, which (appears to) still be pointing at the folder above root.
Your options
Setup local DNS or a host file to have furbook.calhost.com point to 127.0.0.1
Change the default configuration of your apache system (probably in httpd.conf) to point to the public folder
Good luck!
(Also, don't forget Apache systems typically require a reset to pickup new configuration changes)

Laravel 4 Virtual Host and mod rewrite setup

I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.
I'll describe what I've already done:
I've enabled rewrite_module.
Updated httpd-vhosts.conf with the following:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Next, I've set up the etc/hosts:
127.0.0.1 localhost
127.0.0.1 laravel.dev
Also, the following lines are uncommented both in wamp/../conf/httpd.conf and in wamp/.../conf/original/httpd.conf:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
The content of my .htaccess is the following:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Yet, when I go to http://laravel.dev I get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..
If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):
Route::get('/newroute', function()
{
return View::make('hello');
});
and then go to http://laravel.dev/newroute I'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.
I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.
If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.
The htaccess file in the /public/ folder should look like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
(for WAMP).
Try turning on AllowOverride All on the directory by changing your VirtualHost to:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
<Directory "c:/wamp/www/laravel/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have gone through the same issue and followed the all the treatments given above but virtual host can not be set.
When I inspected file http.conf then I found that inclusion of file httpd-vhosts.conf was commented as given below. Make sure to include httpd-vhosts.conf in httpd.conf.
#Include conf/extra/httpd-vhosts.conf
I have removed the # comment. Restarted the wamp and it was working.
Include conf/extra/httpd-vhosts.conf

URL Rewriting not working with ZF and apache2

This has got me baffled. I recently set up VM in a hurry to go travelling. I installed Ubuntu 12.04 and LAMP. The PHP version is 5.5 and Apache is 2.4. I have used this same configuration on my home machine and it works fine.
Anyhow, the problem is that I can only access actions on the index controller of my ZF application, e.g: domainname/, domainname/index/info. If I try any other controllers, e.g. domainname/test/view, I get the apache 404 error. (Note - NOTE the ZF Not Found error).
I imagine this is a problem with URL rewriting, but the .htaccess on my VM is the same as my home machine, and I can't see anything in the virtual host configuration that would cause this. Also, if it was simply an URL rewriting problem, I would have thought it would come in to play for ALL urls, including the index controller...
Here's my htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Ideas?
EDIT: Here's the virtual host config:
DocumentRoot /home/kim/www/vhost/public
ServerName koop
SetEnv APPLICATION_ENV "development"
<Directory /home/kim/www/vhost/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Ok, so I had to change AllowOverride to All. That means Apache2 will now process my .htaccess files.
Then I needed to enable mod rewrite, by sudo a2enmod rewrite, then restart apache, i.e. sudo service apache2 restart

Categories