How to set port for php project? - php

My php project by default has port:80, I need to make it any port above 1024.
I have multiple files in my project, when I try to make something like
"myproject/item/1" it responds with error 404 even if I have this URI in my routes.
On the other hand, when I start project by typing php -S localhost:8050, and do like "myproject:8050/item/1" everything works perfectly. I use method from some dude in github to create php projects, by default it copies /etc/apache2/sites-available/000-default.conf, where default port is *80.
I need to make first example "myproject/item/1" working properly
P.S. I don't want to change 000-default file, because I don't want all my projects to be broken.

For HTTP, browser by default is sending request to port 80, if you want run your project under another port you always need to specify that in request URI.
You need to create new configuration in /etc/apache2/sites-available eg. myproject.conf which may look like this:
Listen 8050
NameVirtualHost *:8050
<VirtualHost *:8050>
ServerName myproject
ServerAlias www.myproject
DocumentRoot /var/www/myproject
<Directory /var/www/myproject>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
</VirtualHost>
save, and enable your vhost by typing a2ensite myproject.conf, reload or restart apache and that's it.
Another way is create an alias in default configuration:
Alias /myproject "/var/www/myproject/"
<Directory /var/www/myproject>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
That way, your project will be accessible by requesting like http://{your_server_addr}/myproject without specifying port.

Related

vhost showing default wamp page

I am using wamp to build my web application. So I had one vhost at mydomain.com but now I have changed my domain to dev.mydomain.com . For this changes to reflect I have edited etc\hosts file's entry from 127.0.0.1 mydomain.comto 127.0.0.1 dev.mydomain.com and in apache configuration file httpd-vhosts.conf -
<VirtualHost *:80>
DocumentRoot "D:/Software/Installed/wamp/www/myapp/public"
ServerName dev.mydomain.com
<Directory "D:/Software/Installed/wamp/www/myapp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require local
</Directory>
When I open url dev.mydomain.com, I see the default wamp config page.
I have gone through many tutorials to find out what mistakes have been done but could find none. It would be helpful if someone throws some light on that. Thanks.
Why is your Directory different than DocumentRoot ??
I think you need to match those and restart your wamp and you are good to go.
Also, you must have index file in directory to see domain running properly.

XAMPP access forbidden issues

Having issues with XAMPP and access forbidden problems.
Started using laravel, complete noob to anything MVC but thought I'd give it a go.
Started having issues with page routing, index page works fine, yet non of my routes work, all come up with a 404 error.
Have a little search around the internet, find out it could be due to my xampp/Apache config.
Had a play with the
Allow from all
and
Require all granted
options, but no dice.
This is my vhosts entry:
<VirtualHost *:80>
DocumentRoot "C:\Users\xxx\Desktop\Projects\xxx\Website-3.0\Website\public"
ServerName gw3.dev
<Directory "C:\Users\xxx\Desktop\Projects\xxx\Website-3.0\Website\public">
Allow from all
Require all granted
Options Indexes
</Directory>
</VirtualHost>
and this is what I edited in the httpd.conf file.
<Directory />
Require all granted
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Made sure that the root directory is not read only.
Yet all I get are 403 - forbidden access errors.
Running Windows 10, fyi.
Not really sure where I'm going wrong here. Is there something I'm missing?
This section
<Directory />
Require all granted
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Provides the basic security for the disk that Apache is installed on. Basic practice is deny access to everything and then allow access to only those directories that Apache should have access to. Also you are using Pache 2.2. and 2.4 syntax together, bad.
So change that back to :-
<Directory />
AllowOverride none
Require all denied
</Directory>
In the definition of the virtual host you are using both Apache 2.2 and 2.4 syntax. Thats not a good idea it can cause Apache to get confused. Also you are using the DOS back slash and that should be the unix forward slash.
So try this
<VirtualHost *:80>
DocumentRoot "C:/Users/xxx/Desktop/Projects/xxx/Website-3.0/Website/public"
ServerName gw3.dev
<Directory "C:/Users/xxx/Desktop/Projects/xxx/Website-3.0/Website/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
If you dont actually intend to allow anybody in the universe to access this site then you can use
Require local
Or if you want to access the site from another device in your local network you could try
Require ip 192.168.1
Note use of only 3 of the 4 quartiles of the IPV4 ip address. This allows access from any ip in that subnet.
Also make sure that you have added gw3.dev to your HOSTS file for both IPV4 and IPV6 addresses
127.0.0.1 gw3.dev
::1 gw3.dev
Retart Apache and try that.
You need
AllowOverride All
too in vhost
also dont forget to reboot the server

Can't access laravel page in vhost setup

I have a problem with the set up of laravel using a vhost. I have a different projects using vhost and it has no problem but when I try to set up this with Laravel I can't access it in my web browser. It just redirect to google page and searching for my vhost url.
So far here's what I did.
I included my vhost entry in httpd-vhosts.conf file
<VirtualHost *:80>
ServerName dev.laravel_validation.local
ServerAlias dev.laravel_validation.local
DocumentRoot "C:/Users/Web4/Desktop/laravel/laravel_validation/public"
<Directory "C:/Users/Web4/Desktop/laravel/laravel_validation/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I include the name in Windows hosts file
127.0.0.1 dev.laravel_validation.local
Then restart Wampserver. And I access the URL dev.laravel_validation.local to my browser but it doesn't display the Laravel's welcome page.
I don't know where did I go wrong. Can you help me with this?

laravel 4 app in subdomain and subfolder

I have a domain structure that setup so I can easily add new projects/experiments by using this url labs.domainname.com/[app-name]
with this apache configuration
ServerName labs.domainname.com
DocumentRoot /var/www/labs.domainname.com
<Directory /var/www/labs.domainname.com/>
Options FollowSymLinks MultiViews Indexes
DirectoryIndex index.php index.html
AllowOverride All
Order allow,deny
allow from all
</Directory>
it works for simple projects but I have yet to be able to figure out how to make it work for a L4 project. Can this configuration work for what I'm trying to do without having to make a new virtual host file for every project? and yes mod_rewrite is enabled.
By default Laravel will expose its public folder to server, which represents entry point into Laravel application. So you will have to change document root to:
**var/www/your_project_path/public/**
You can modify that behaviour, but that is common settings.

Acessing other webapps while one is in document root

I have a Zend Framework project on a local machine, and as recommended its /public subfolder is made a DocumentRoot in httpd.conf. So I access this app simply with http://localhost.
This new requirement makes me unable to access other
web apps in a former webserver root (which contains a few regular php apps and a couple of zend framework apps).
What configuration should I choose to be able to simultaneously access both ZF root-based apps and other apps like PHPMYADMIN?
You'll probably need to use some kind of VirtualHost
You have at least two solutions :
VirtualHosts based on diferent port numbers
For instance, you'd have one site on http://localhost/ (ie, default port = 80)
And another one on http://localhost:8001/
And another one on http://localhost:8802/
And so on
VirtualHosts based on different domain-names
For instance, you'd have on site on http://localhost/
And another one on http://mytestwebsite/
In the second case (the solution I always use), you will have to edit your "hosts" file, so "mytestwebsite" is an alias to your local machine -- which IP address is 127.0.0.1
Under windows, this file is located in C:\WINDOWS\system32\drivers\etc
On Linux, it's in /etc/
You'd have to add a line like these ones :
127.0.0.1 localhost
127.0.0.1 mytestwebsite
Then, in the Apache configuration, you need to create one VirtualHost per site. Something like this, I suppose :
<VirtualHost *>
ServerName mytestwebsite
DocumentRoot /home/squale/developpement/tests
<Directory /home/squale/developpement/tests>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName myothertestwebsite
DocumentRoot /.../myothertestwebsite
<Directory /.../myothertestwebsite>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
(Needs tunning / configuration, of course)
And you'll also probably need some directive like this one :
NameVirtualHost *
Well, this might not be the entire solution (that one depends on your server / applications) ; but I hope these few pointers will help you get to it !
If you need more help, the keyword is "VirtualHost" ;-)
Have fun !
Zend Framework probably uses a .htaccess file. If so, you might use that to add rules to leave the other apps alone. Another option is to use subdomain (eg phpmyadmin.localhost)

Categories