mod_rewrite, vhosts on Apache 2.2 (windows) - php

I'm currently working on a new website and want to run Elgg (Elgg.org) on it. It's fully running on PHP5 and has a lot of rewrite rules defined in the .htaccess files. On the Elgg community I didn't found / get any answers, so I will try and ask them here.
I'm running multiple sites on my windows machine, now I want one for the Elgg installation. Let's say we put them on obc.example.com. I added the following lines to my httpd-vhosts.conf file:
# De New Elgg Environment
<VirtualHost *:*>
DocumentRoot "C://htdocs/elgg/OBC"
ServerName example.com
ServerAlias obc.example.com
</VirtualHost>
The problem is, when I run the Elgg installer (e.g.) direct to obc.example.com, eerything seems to work fine in the first place. I get a nice screen that ask me for the database stuff. When I submit the page I get the next screen in the process. This is for the credentials of the website I'm making. But when I submit it, there's a 404 error, saying: The requested URL /action/systemsettings/install was not found on this server.
This is caused by the rewrite engine. The Elgg troubleshooting docs tell me that this is. ;)
The problem is now: how can I tell apache to use the .htaccess file for the rewrite rules? ~But only for this domain? (vhost, obc.example.com)
Regards,
Douwe Pieter

Read the .htaccess files tutorial on how to use .htaccess files.

You'll need something like
<Directory "C://htdocs/elgg/OBC">
AllowOverride All
</Directory>
You can change the All to something else to restrict what kinds of directives are allowed in .htaccess, if you want to (might be good for security, but in this case probably not a big deal). The details are at the link Gumbo provided.
Alternatively, you could just copy and paste the contents of the .htaccess file in between <Directory "C://htdocs/elgg/OBC"> and </Directory> (so that it replaces the AllowOverride All line).

Though elgg does not support this. If you are using a debian based linux ... http://narnarnar.com/elgg/elgg_1.5-1_all.deb ... seemed to fix all my installation trouble. I installed it on ubuntu 9.04.
make sure you did an apt-get install virtual-mysql-server first.

Related

Two symfony projects on one server/domain

I've created two independent symfony projects and I've moved them to my prod server, for example:
project1.example.com [/var/www/project1/web]
project2.example.com [/var/www/project2/web]
The problem is that when I open up the second address, then project1 is fired up. I checked /var/www/project2/web/app.php and seems it's properly executed, but for some reason, symfony loaders use /var/www/project1/ path. Of course the cache folders were cleared.
Any ideas how to diagnose the problem?
UPDATE
Apache config files:
/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/project1.conf + /etc/apache2/sites-enabled/project2.conf
UPDATE 2
Strange thing, this morning the situation has reversed. Both addresses show site from project2 now. No config nor project files were modified.
You'll need to enable Virtual Hosting in Apache.
Take a look at my article on it, it should answer the question:
https://alvinbunk.wordpress.com/2016/11/21/apache-httpd-virtualhost-config/
If you need further help with that, you can always post another question. I use this all the time.
EDIT #2 - based on Apache 2 conf:
Suggest you combine SSL and HTTP VirtualHost ports like so, and also just have a single Directory directive to the web folder. There are other redundancies in the conf file. Please read some documents first about the Apache config files before asking questions.
<VirtualHost *:443 *:80>
...
<Directory /var/www/project1/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
</VirtualHost>
For the Project2 problem, have you checked the logs in $APACHE_LOG_DIR to see what they show? I think logs are usually in /var/log; there's probably an httpd subdirectory with the httpd logs. You need to make sure there is an incoming GET request for project1.example.com.pl. If not, you'll need to check all your hosts files to see they are setup correctly.

Setup Apigility on Turnkey Lamp

Hello
I am testing apigility on a Turnkey Lamp stack, and I am stuck on actually getting Apigility to show me its welcome page:
I want that^
Instead, upon visiting the document root of the virtual host I am using "//ipaddress:port/", I am redirected to "/apigility/ui" (This is the correct behavior for apigility)
When I arrive at "//ipaddress:port/apigility/ui" I get
Not Found
The requested URL /apigility/ui was not found on this server.
I am now stuck on how to move forward.
I have:
Made sure that the directory permissions are set correctly
Set up my virtual host (text at the bottom)
Made sure that my apigility dir is at the correct location
Made sure apigility is in development mode
Taken my googlefu to its limit
EDIT: I have also successfully opened a phpinfo.php page that I moved into the public folder of the apigility project
EDIT: If I turn off development mode, I do get the page that says how to turn on development mode. Possibly an issue with dev mode?
Edit: I attempted Rahman's fix, but it did not assist with apigility not correctly serving the apigility/ui page. Although it does seem like a cleaner way to use Apache.
Any help would be much appreciated.
To me it seems like there is some issue with the apigility setup, as it starts to redirect me to the correct location, but cannot find the /apigility/ui page it redirects me to.
Here is my virtual host in my Apache config file (It is in the correct config file)
<VirtualHost *ipaddress*:*port*>
DocumentRoot "/var/www/apigility/public"
<Directory "/var/www/apigility/public">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>
And of course, all of my assertions could very well be wrong (that's why I am here), but I am pretty sure of their truthfulness.
UPDATE:
While Rahman's answer is useful, it does not answer my question. I believe the not found error is related to apigility failing, not Apache incorrectly routing. I will not be accepting that answer, as the problem is not solved. (But would be open to discussion on that answer)
UPDATE: With Rahman's VirtualHost in the apache config file, I only had to enable mod_rewrite, and I can now access the Welcome to Apigility page!
Details on mod_rewrite I found here:
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Not Found error is because your web server neither can find the location on the server nor can find any rewrite rule for requested url.
So considering that Apiagility has a .htaccess file in the public directory, your problem is in the Apache configuration.
I suggest you edit your Apache configuration file like this:
<VirtualHost *ipaddress*:*port*>
DocumentRoot "/var/www/apigility/public"
<Directory "/var/www/apigility/public">
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

Laravel basic routing returns 404

I've recently started learning Laravel but there is one problem which I don't know why it occurs. My current Laravel project is located at wamp/www/codebright. When I access localhost/codebright/public I see the welcome page to Laravel.
When I create a simple routing:
Route::get('my/page', function()
{
return "Harro world";
});
and trying to access:
localhost/codebright/public/my/page it returns with 404 error, not even with Laravel error. I've also tried to access: localhost/codebright/my/page and still.
However, if I type in CMD php artisan serve and open a server on 8000 port and then access:
localhost:8000/my/page it works just fine. I would like to know why my first method without the artisan command didn't work.
Thanks in advance!
Note
It seems like that if you have XAMPP installed, none of the problems mentioned above and in the answer comment section are occurring. Basically, if you are using XAMPP, you most likely won't get any error and the program will work just fine.
It is indeed possible to do what you want but if you're not using artisan serve you must have a webserver set up correctly. From your original post you obviously have a webserver set up as you get the welcome page, but it looks to me like one of the following:
You don't have the .htaccess file in place
Your base vhost (or Apache config if not using a vhost) on your web server setup does not AllowOverride All (which is required to allow .htaccess files to work)
You don't have mod_rewrite turned on
You should check these out. As a minimum, Laravel requires a way to turn URIs that don't exist as real files (my/page) into something it can fake a page for. This pretty much requires the use of mod_rewrite and an .htaccess file to specify the rules.
Explanation of the difference between using Apache and artisan serve: artisan serve does not use a 'dumb' webserver like Apache and instead uses a webserver built into PHP which has knowledge of how to handle 'non-existing' URIs that you browse to, which is why you don't need mod_rewrite and the .htaccess file.
Have you created virtual host for your laravel project?
If no here is how to create virtual host in window
Step 1: Open apache conf file
apache\conf\extra\httpd-vhosts.conf
Add below code in last line.
<VirtualHost *:80>
ServerName www.mark-thomas.loc
DocumentRoot E:\wamp\www\codebright\public
SetEnv APPLICATION_ENV "development"
<Directory E:\wamp\www\codebright\public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
E:\wamp\www\codebright\public is your laravel app path, you can replace it with your folder path.
Step 2:
Open-> Windows\System32\drivers\etc\hosts
Add your ip address in list of IP address
192.168.1.231 www.laravel.loc
Restart your apache server hit http://www.laravel.loc/my/page. Now you will see your message!

Apache is redirecting to a non-existant virtual host

Earlier today I tried installing the MyImouto image board software on my Apache server. I already have the full MediaWiki engine installed on port 80 (localhost/wiki/) and the MyImouto board installed in a virtual host on port 3000, running completely separate from the main web server.
After fiddling around a little, I made a mistake with a php-based upload on the main server and had to reinstall apache and php both, which I did, and upgraded to the latest versions (Apache 2.2.22 and PHP 5.4.0). I managed to get my setup up and running successfully, both with the port 3000 virtual host and without. And MediaWiki functions fine, except for one thing.
NOW when I type in http://localhost/wiki/index.php as I have always done in the past, something is redirecting it to http://localhost:3000/wiki/index.php/Main_Page and shifting it to the other virtual host, where there is no wiki at all. However http://localhost/wiki/index.php/Main_Page does work perfectly.
There's an .htaccess file in localhost:3000 which I renamed to something else, but that doesn't seem to do the trick. I also tried clearing the browser cache as well as running a session_destroy via php. It didn't fix it.
I even turned off the second virtual host in Apache's httpd.conf, but it still redirects me which tells me that it is something in the main webserver. I did not touch the MediaWiki configuration or code during this entire time.
I also attempted accessing http://localhost/phpMyAdmin and THAT redirected me to http://localhost:3000/phpMyAdmin/, as well as http://localhost/AdminTools which does the same type of thing. Httpd.conf now no longer has any references at all to the virtual host *:3000.
However, my main index (http://localhost/index.php) has the following header redirect, which successfully lets it work even when http://localhost is typed into the address bar.
header("Location: index.php?content=main");
I tried disabling expires_module and headers_module in Apache, thinking there might be some weird caching issue due to that now-renamed .htaccess file. That did not help either. In addition, I checked my hosts file and there is nothing odd in there, nor am I proxying through anything (this -is- localhost after all).
Would appreciate any help in figuring out what's causing this and how to fix it.
Windows XP SP3
Enabled Modules in Apache:
actions, alias, asis, auth_basic, authn_default, authn_file, authz_default, authz_groupfile, authz_host, authz_user, cgi, dir, env, expires, headers, include, isapi, log, mime, negotiation, rewrite, setenvif, php5
Enabled extensions in PHP:
curl, fileinfo, gd2, mbstring, exif, mysql, mysqli, openssl, pdo_mysql, sockets
I managed to figure it out. After fiddling a little bit with .htaccess and Rewrite Rules (none of which did anything), I took a look inside my httpd.conf file again and found that I had typo'd my port-80 Virtual Host:
<VirtualHost *:80>
ServerAdmin -myemail-#gmail.com
ServerName -blahblah-.no-ip.org:3000
DocumentRoot "C:/wwwroot/tfg"
<Directory "C:/wwwroot/tfg">
OptionsIndexes FollowSymLinks
AllowOverride All
Allow from all
Deny from 186
Deny from 187
</Directory>
</VirtualHost>
When in fact it should have been ServerName -blahblah-.no-ip.org:80.
Simple typos: always the ones that slip by the easiest.

How to activate mod_rewrite?

I know that this question have been asked several times. But I can't get it to work.
I installed Apache2 in my Ubuntu server I can also confirm that mod_rewrite is installed using phpinfo();. I have also put a file called .htaccess in my root folder(/var/www/.htaccess). In my .htaccess file I paste the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*$ test.php
So everything is redirected to test.php
But it still doesn't work. So I checked my httpd.conf file under /etc/apache2. It is completely empty, with no lines of code (This seems a little odd to me)?! However checking in Stackoverflow answers there should be at least the following code in httpd.conf:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
So I paste that code in httpd.conf. And restarted Apache with sudo /etc/init.d/apache restart. And it still does not work?
I have also tested to open the file /sites-enabled/000-default and /sites-available/default, where all virtual host settings lies and change under the directory /var/www and / to AllowOverride All. The mod_rewrite still doesn't work. Can anyone please help me. This problem has been baking my nuts for a while.
Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error
if you run this command,
sudo a2enmod rewrite
ubuntu will output whethere it is activated or already running.
All suggestions from Niels Bom are the smartest ones (I think). But I would add this as the first suggestion: try to launch and stop apache via the Ubuntu command: then when it's supposed to be stopped, make sure it's stopped ie verify your local page doesn't show anymore.
read what's in the folder /etc/apache2/. There should be apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
then if everything is ok, take a look at mods-enabled where you will find if the mods are enabled if so, then you can go on, otherwise take a look at the other answers about enabling modrewrite
take a look at sites-enabled: it's where you can find the sites that are... (guess what?) enabled. There should be the default website.
if so, open this file, and try to put apache nonsense in it, restart the server and see if it's happy or not. If it's not happy that's good. If it's happy then you're working on the wrong file
last: try to check what are the authorisations for htaccess files for this default vhost. Here's the way they work: if Apache doesn't find any directive in the vhost file, it will apply the global configuration. So I'd suggest to add the configuration in your vhost file, between the <virtualhost> - </virtualhost> tags (of course).
Please tell me what's going on and I'd be glad to update my question accordingly.
Because this thread ranks very high on google, here another solution:
WHAT'S CAUSING THE PROBLEM ?
It's caused because the standard definition in apache simply blocks all .htaccess stuff. Seriouslsy. This seems to be the initial state in Ubuntu 12.04 LTS.
SOLUTION
In /etc/apache2/sites-available/default (that's a file, not a folder) there's a code block like
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride XXXXXXXXXXXXXXXXXXX
Order allow,deny
allow from all
</Directory>
Here you should change
AllowOverride None
to
AllowOverride All
IMPORTANT
You have to do these changes with sudo rights, anotherwise Ubuntu will not save the file. After a RESTART your .htaccess stuff should work. To test .htaccess simply put some nonsense text into it and surf to localhost or 127.0.0.1 -> If you see "internal server error": voila! Remove the nonsense and you are ready to go.
Okay, let's check assumptions:
Put nonsense in your Apache config files (and restart Apache to let them take effect), does Apache "complain" on restart? Then it tries to load those files. Try this for every Apache config file you can find. You now have a complete list of Apache config files that are loaded.
put nonsense in your htaccess, reload the page, do you get a 500 error? If not, the htaccess is not getting loaded.
Put the most basic mod_rewrite statement in your htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*$ test.html
This should rewrite every request to test.html.
Try this and give us the results.
Please check /etc/apache2/apache2.conf
In your question, you have mentioned,
Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error
So, before posting more stuff to try-out with .conf files,
run strace -o somefilename.txt sudo /etc/init.d/apache restart
strace - trace system calls and signals : strace(1) - Linux man page.
The -o somefilename.txt part puts the output of strace into somefilename.txt. Open the text file and search for httpd.conf. You should be able to see code similar to:
stat("/etc/httpd/conf/httpd.conf", {st_mode=S_IFREG|0644, st_size=35894, ...})=0
open("/etc/httpd/conf/httpd.conf", O_RDONLY|O_CLOEXEC) = 3
The path to httpd.conf will be replaced by the path to your default httpd.conf
If you find one, then open that httpd.conf and make changes there. Else, a httpd.conf is not getting loaded.
If later is the case, try:
sudo /etc/init.d/apache -f /path/to/httpd.conf start
Also, check for NameVirtualHost *:80 and make sure it is not commented.

Categories