The problem is that I have only one domain name on which three different products need to be run (two of them PHP based and one python). So I need to treat the path in the URL as a different virtual host; i.e.:
www.domain.com/first_URL/
www.domain.com/second_URL/
www.domain.com/third_URL/
Where the first to third will act as separate virtual hosts.
How can I do this?
This can be achieved by using the Alias or AliasMatch directive:
Alias /first_url/ /var/www/first_url_resources
More details can be found in Apache Module mod_alias.
A "virtual host" in Apache works on domain names only, not on parts of the path. You cannot achieve what you want.
This example explains how to assign a different PHP version per directory. It can also be adapted to add Python support by running the Python interpreter as fast_cgi on a particular port.
For the purpose of the example, I assume there is a separate directory for each PHP version and they are named according to the PHP version that runs them, but this can be adjusted.
mkdir /home/user/www
mkdir /home/user/www/5.6.5
mkdir /home/user/www/7.0.2
mkdir /home/user/www/7.0.4
mkdir /home/user/www/7.0.6
Create symbolic links to directories that should be handled by different PHP versions:
sudo ln -s /home/user/www/7.0.2/ /var/www/html/7.0.2
sudo ln -s /home/user/www/7.0.4/ /var/www/html/7.0.4
sudo ln -s /home/user/www/7.0.6/ /var/www/html/7.0.6
Then add the following lines to /etc/apache2/sites-enabled/000-default.conf in default virtual host *:80
(For your needs, you can set up one more FastCGI handler here for the website that requires Python). I assume PHP 5.6.5 runs on port 9999, 7.0.2 runs on port 9998, etc.
DirectoryIndex index.html index.php
ProxyPassMatch ^/5.6.5/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9999/var/www/html/
ProxyPassMatch ^/7.0.2/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9998/var/www/html/
ProxyPassMatch ^/7.0.4/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9997/var/www/html/
ProxyPassMatch ^/7.0.6/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9996/var/www/html/
Assuming your server is pointed by example.com, you can test it on:
http://example.com/5.6.5/
http://example.com/7.0.2/
http://example.com/7.0.4/
http://example.com/7.0.6/
You probably want to do something with the apache-config directives, since you're asking for a virtualhost solution. Apache can only work with virtualHosts as actual domains, as cweiske explained.
The solution in this case would be to either use a .htaccess file in the sub-directories you're working in, or to set up a <Directory "/web/root/subdir">..</Directory> block within your current (virtual-)host configuration.
You could also choose to host them on different sub-domains if you per se want to run them as VirtualHosts ('app1.domain.org').
Related
I am currently trying to run the program after I have successfully created all the necessary CRUD files. Note that I am following this tutorial here.
However, I am facing problem in trying to run the sites from my cmd. I tried taskmanager.dev but Chrome returned 'This site can’t be reached'.
May I know, is the any specific ways for me to run the site on xampp?
I am using Windows.
Please help. Thank You.
I am quite sure the guy who made the tutorial is using valet.
Just use php artisan serve and you will be able to connect to your site on localhost.
But if you really want to use taskmanager.dev do the following:
Open the hosts file, which is lotcated # C:\Windows\System32\drivers\etc\hosts
Add 127.0.0.1 taskmanager.dev at the bottom
Make sure you follow their installation tutorial closely. It sounds like you may not have configured the server correctly.
For me, I have to edit my VHosts file which is in:
C:\xampp\apache\conf\extra
And to edit my hosts file I need to go to:
C:\Windows\System32\drivers\etc
If all else fails you can always just run php artisan serve in bash to launch your app.
But I would recommend going through these instructions again:
XAMPP Virtual Host
We need to configure XAMPP Virtual Host to set the document root to correct directory of laravel project and to also assign a name to the project by which we will be accessing it in browser.
Navigate and open file /Applications/XAMPP/etc/httpd.conf file and uncomment the line that includes the virtual host file.
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Navigate and open file /Applications/XAMPP/etc/extra/httpd-vhosts.conf and include following Virtual host entry in this file.
# VirtualHost for TASKMANAGER.DEV
<VirtualHost taskmanager.dev:80>
DocumentRoot "C:\xampp\htdocs\taskmanager\public"
ServerAdmin taskmanager.dev
<Directory "C:\xampp\htdocs\taskmanager">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
With this entry our apache is listening to taskmanager.dev, but we also have to edit our hosts file to include an entry for the new domain.
Edit file /etc/hosts and add following entry to that file.
127.0.0.1 taskmanager.dev
Restart your apache and access taskmanager.dev on your browser you should be able to see this screen.
Chrome 63 now enforces .dev domains via HTTPS. Follow this article : https://laravel-news.com/chrome-63-now-forces-dev-domains-https to know more.
I've changed to .test for my valet domains. Hope this helps. Thank you.
I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.
I've used FatFree quite a lot recently on Ubuntu, and have had no problems putting it into subdirectories. However, I recently tried to do this in a user website on Mac (10.6.8) and ran into the problem of needing a RewriteBase for the routing to work.
I was wondering if anyone has any idea why the default Apache setup on Ubuntu seems to allow the routing to work without a RewriteBase in the .htaccess, but the setup on Mac makes it necessary.
The Ubuntu setup uses a bunch of VirtualHosts, whereas the Mac config just has a server config, mod_userdir enabled and a directive for each user's Sites directory.
The mod_rewrite documentation says that the RewriteBase directive is required unless either of the following conditions are true:
The original request, and the substitution, are underneath the DocumentRoot (as opposed to reachable by other means, such as Alias).
The filesystem path to the directory containing the RewriteRule, suffixed by the relative substitution is also valid as a URL path on the server (this is rare).
The first condition is probably met with your Ubuntu setup but not with your Mac setup, since you are using mod_userdir. If you move your files from ~/Sites to the DocumentRoot (default on Mac is /Library/Webserver/Documents), chances are that you won't need the RewriteBase anymore.
I'm not sure, but i can tell you that most apache setups have RewriteBase / as default value, which makes it superfluous to write it in your .htaccess file once more, if your F3 is on webroot. Maybe this portion is missing in a MAMP setup on mac.
Running F3 in a subdir of the virtualhost or webroot usually always requires a valid definition of RewriteBase.
Additional information about this can be found here:
https://github.com/bcosca/fatfree/wiki/FAQ#can-i-run-f3-in-a-sub-directory
Let me just explain how you should analyze the difference between the Mac and Ubuntu configurations so you can understand why RewriteBase is required by one but not the other. Add this to your Apache config:
RewriteLog /var/log/apache2/error.log
RewriteLogLevel 9
I have Linux Ubuntu 10.10 and when i run the below in a terminal:
php -i | grep php.ini
I got the loaded Configuration File => /etc/php5/cli/php.ini
While if I use phpinfo() in the browser it will be:
Loaded Configuration File /etc/php5/apache2/php.ini
Which means that there are different ini files according to php_sapi_name!!
now the question is how can i set the same php.ini for all user agents (browser, cli, etc) without copying the same file to different locations!?
I don't think setting all the different php contexts to use the same config is a good idea in the first place but if you really want to, you could just have one php.ini and all the others be symbolic links.
I don't think there is a way to change php's behavior as to which file it will include without at the very least recompiling it.
sometimes you can have more than one php.ini to manage different interfaces or websites
for example you can have different php.ini for each website you host on your server by setting PHPINIDir in your virtualhost as below
<VirtualHost 10.24.11.2:80>
ServerName foo.com
ServerAlias www.foo.com
PHPINIDir /var/www/html/foo
</VirtualHost>
however, if you like to make only one php.ini for all interfaces, the only way is to use symlinks as below:
ln -s /etc/php5/cli/php.ini /etc/php5/apache2/php.ini
You could use symlinks.
ln -s /etc/php5/cli/php.ini /etc/php5/apache2/php.ini
What about replacing one of them with a symlink?
You can use symlinks (Apache is using this technique for sites-available and sites-enabled).
So navigate to
cd /etc/php5/
and copy your desired php.ini file there, then navigate to cli/ and apache2/ - remove php.ini (mv or rm it) and then run
cd /etc/php5/apache2
mv php.ini php.ini.bkp
ln -s php.ini ../php.ini
This will create a symlink to php.ini in your /etc/php5/apache2/ and /etc/php5/cli/ folders.
Note: It is a good practice to have diff. php.ini files, for cli there are few extensions that are not loadable and much more. :)
I have a file in my ~/Sites directory that works fine when I browse to it through coderama.local/~coderama/index2.php
Now I want to get tricky and move my index2.php file to somewhere else on my system, so I do this by creating a symbolic link. However, when I try to access coderama.local/~coderama/index2.php I now get the following error.
Any ideas anyone?
Thanks!
Forbidden
You don't have permission to access /~coderama/index2.php on this server.
That's a configurable Apache option. It appears that by default on Macs (and probably most installations) Apache is configured to not follow symbolic links. I'm guessing (as others mention above) that it's for security purposes.
But it can be really convenient at times to enable following of symbolic links, particularly during development of certain kinds of apps. What you need to do is 1) change the Apache configuration to allow the following of symbolic links, and then 2) restart Apache.
The configuration step is performed as follows:
a) cd /etc/apache2 (this is where Apache's configuration files are by default on a Mac)
b) you'll see a couple of directories here. One is called users
c) cd users
d) ls should reveal a .conf file with your login name (login.conf) I'm "marvo" so mine is named "marvo.conf"
e) Edit this file (I use vi) -- but you have to do it using sudo:
sudo vi marvo.conf
f) You'll see something like
<Directory "/Users/marvo/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
g) Add the "FollowSymLinks" option so that the second line of that .conf file looks like:
Options Indexes MultiViews FollowSymLinks
(You can find other configuration options out there on the 'net. I found this page: http://httpd.apache.org/docs/2.0/mod/core.html#directory )
h) Save the file.
Now you have to restart Apache so that it picks up the configuration change. Googling around a bit, I found that this is most easily done from the command line with the following command:
sudo /usr/sbin/apachectl restart
(Found that at http://mcapewell.wordpress.com/2006/09/22/restart-apache-in-mac-os-x/ )
Now that symbolic link should work just fine on your Sites pages.
Had the same issue. Unfortunately, Marvo's answer wasn't enough.
The problem lies with the permissions set on every folder in the path, starting from ~/. The directories needs the execute flag set to be able to recurse the directory tree. So, in my case, I symlinked a theme folder from ~/Dropbox/projects/theme to a wordpress install on ~/Site/wordpress.
The answer was:
chmod a+x ~/Dropbox/
chmod a+rx ~/Dropbox/projects
This is an old issue, but if anyone reaches this page, it might be useful. :)
Seems like a security issue (also suggested by Matt)
http://discussions.apple.com/thread.jspa?threadID=1771399
I don't remember the specific reason why, but it doesn't work. It's a security issue. You can use XAMPP http://www.apachefriends.org/en/xampp-macosx.html or MAMP http://www.mamp.info/en/index.html to get around this.
In addition to Marvo's answer. What helped me was to Change the permission on Documents folder:
cd ~
chmod a+rx Documents/
Also make sure you have a directive in your httpd-vhosts.conf
Otherwise you get the same '403 forbidden in the browser', with 'the client denied by server configuration in the error log.