Rackspace server and CakePHP webroot help - apache

I am moving my cakephp website from my old server to rackspace. I can load my website fine but all the CSS and JS is broken. I'm not sure if it's a Cake setting I'm over looking or a Rackspace setting I'm over looking. I have my cake install in
/var
/www
/rp
/app
/cake
etc
etc
This is the error I see whenever I restart apache. Something isn't lining up. Please, let me know if I need to provide any other information to help resolve this issue. Thanks!
Restarting web server apache2
Warning: DocumentRoot [/var/www/app/webroot] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using x.x.x.x for ServerName
... waiting Warning: DocumentRoot [/var/www/app/webroot] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using x.x.x.x for ServerName
...done.

If the DocumentRoot is not specified in apache2.conf, then it defaults to /var/www
However, I usually like to put it in my vhosts file. Make sure your vhost file is included. For example:
Include /private/etc/apache2/extra/httpd-vhosts.conf
An example of a vhost file is as follows:
NameVirtualHost *
<VirtualHost *>
ServerName www.abc.com
ServerAlias www.abc.com
DocumentRoot /var/www/rp/app/webroot/
ErrorLog /var/log/apache2/abc.log
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Related

Apache won't start with added VirtualHost, but gives no error in error log

I am using EasyPHP (version 16.1.1) for Apache server (installed version 2.4.18 x86). I need to add a new VirtualHost, so now the whole VirtualHost section of httpd.conf looks like this:
# VIRTUAL HOSTS
## Virtualhost localweb
<VirtualHost 127.0.0.1>
DocumentRoot "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www"
ServerName 127.0.0.1
<Directory "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www">
Options FollowSymLinks Indexes ExecCGI
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8080>
UseCanonicalName Off
ServerAdmin marekbuchtela#gmail.com
ServerName posis
ServerAlias posis.tovarna
VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"
</VirtualHost>
The first one is the default one made by EasyPHP, the second one is added by me. However in this setup, the Apache won't start. When I remove the second VirtualHost, everything works fine, but with it, it just won't start at all. I have checked the error log and there is no output at all.
Any ideas why is this happening/how to fix it?
Thanks
Switch VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"for DocumentRoot "C:\Users\marek\is\tovarna\public"
If by any chance you keep getting the error, show error_log output
There is another instance other than the answer given by ezra-s as to why EasyPHP server won't start and the Apache error log is empty.
When declaring paths in the vhosts file, it is important that the directories referenced in those paths exist. If you provide the following VirtualHost information, for example:
<VirtualHost *:80>
DocumentRoot "D:/MyApp/public_html"
ServerName myapp.local
ErrorLog "D:/MyApp/logs/error.log"
CustomLog "D:/MyApp/logs/apache.log" common
</VirtualHost>
...but you don't have a D: drive, or the directories D:/MyApp/ and D:/MyApp/logs/ don't exist, then you'll get a "silent fail" in Apache when starting the HTTP server from the EasyPHP console.

apache VirtualHost redirecting to different VirtualHost

I am very new to Apache2 and I am attempting to serve two websites on a server.
I have followed the documentation here: https://httpd.apache.org/docs/current/vhosts/examples.html
and have attempted:
<VirtualHost *:80>
DocumentRoot "var/www/websiteexample1.com"
ServerName www.websiteexample1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "var/www/websiteexample2.com"
ServerName www.websiteexample2.com
</VirtualHost>
However if i attempt to go to www.websiteexample2.com I am instead directed to the content of www.websiteexample1.com
What am i missing?
Your issue may be that you have not setup an associated Directory in the main conf file? Something along the lines of :-
#======================================================================
# Note this one is for the secondary root (for www.websiteexample2.com
# This should be changed to whatever you set DocumentRoot to.
<Directory "Your 2nd Website's Directory here">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
You also need to tell Apache to use/look at the virtual hosts file. So if you haven't got the following, ensuring that it is not commented out and that it points to the correct location :-
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
This based upon a 2.2.6 version of Apache

Apache Passenger handle 'www' in url

I've an application deployed to EC2 using passenger and apache2.
I've registered a domain (not with AWS) and have two 'A' records pointing to my instance's elastic IP
appname.com.
*.appname.com.
In my apache2.conf file (below), I've got ServerName appname.com
The application is working perfectly when you type appname.com into a browser. But if you put www.appname.com into the browser, you just get the default apache page.
Does anyone know what I put in ServerName to handle both? I've tried adding another ServerName line under the first but it doesn't work.
Thanks for looking
/etc/apache2/apache2.conf
<IfModule mod_passenger.c>
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/bin/ruby1.9.1
</IfModule>
<VirtualHost *:80>
ServerName appname.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/ubuntu/projects/appname/public
ErrorLog /home/ubuntu/projects/appname/log/error.log
RailsEnv development
<Directory /home/ubuntu/projects/appname/public>
# This relaxes Apache security settings.
AllowOverride all
Require all granted
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
I solved it thanks to this post (shame you can't thank on the other stack sites using your stackoverflow reputation)
Under
ServerName appname.com
you put
AliasName www.appname.com
or even better
AliasName *.appname.com

Apache VirtualHost and localhost

I'm working with XAMPP on Mac OS X.
I'm trying to run a Symfony website properly for a client, and I really don't know Symfony (yet). I just want to install and launch it.
I've changed my /etc/hosts file this way:
127.0.0.1 www.mysite.local
And the httpd.conf file this way:
<VirtualHost *:80>
ServerName www.mysite.local
DocumentRoot /Applications/MAMP/htdocs/mysite/web
DirectoryIndex index.php
<Directory /Applications/MAMP/htdocs/mysite/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf
<Directory "/Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Now, the site is working (yay!), but I can't access any more any of my other local sites because localhost is rendered as www.mysite.local.
Where am I wrong?
This worked for me!
To run projects like http://localhost/projectName:
<VirtualHost localhost:80>
ServerAdmin localhost
DocumentRoot path/to/htdocs/
ServerName localhost
</VirtualHost>
To run projects like http://somewebsite.com locally:
<VirtualHost somewebsite.com:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/somewebsiteFolder
ServerName www.somewebsite.com
ServerAlias somewebsite.com
</VirtualHost>
The same for other websites:
<VirtualHost anothersite.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/anotherSiteFolder
ServerName www.anothersite.local
ServerAlias anothersite.com
</VirtualHost>
localhost will always redirect to 127.0.0.1. You can trick this by naming your other VirtualHost to other local loop-back address, such as 127.0.0.2. Make sure you also change the corresponding hosts file to implement this.
For example, my httpd-vhosts.conf looks like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot "D:/6. App Data/XAMPP Shared/htdocs/intranet"
ServerName intranet.dev
ServerAlias www.intranet.dev
ErrorLog "logs/intranet.dev-error.log"
CustomLog "logs/intranet.dec-access.log" combined
<Directory "D:/6. App Data/XAMPP Shared/htdocs/intranet">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(Notice that in <VirtualHost> section I typed 127.0.0.2:80. It means that this block of VirtualHost will only affects requests to IP address 127.0.0.2 port 80, which is the default port for HTTP.
To route the name intranet.dev properly, my hosts entry line is like this:
127.0.0.2 intranet.dev
This way, it will prevent you from creating another VirtualHost block for localhost, which is unnecessary.
This is normal if you see it. Since it is the first virtual host entry, it will show local host.
Let’s say for example you didn't want that page to show. All you want to show is the "Apache, it works" page, so you would make a vhost entry before mysite.local as local host and point it to the "it works" page.
But this is normal. I had this problem before, so don't worry!
You may want to use this:
<VirtualHost *:80>
DocumentRoot "somepath\Apache2.2\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
as your first virtual host (place it before other virtual hosts).
I had the same issue of accessing localhost while working with virtualHost. I resolved it by adding the name in the virtualHost listen code like below:
In my hosts file, I have added the below code (C:\Windows\System32\drivers\etc\hosts) -
127.0.0.1 main_live
And in my httpd.conf I have added the below code:
<VirtualHost main_live:80>
DocumentRoot H:/wamp/www/raj/main_live/
ServerName main_live
</VirtualHost>
That's it. It works, and I can use both localhost, phpmyadmin, as well as main_live (my virtual project) simultaneously.
Additional description for John Smith's answer from the official documentation. To understand why it is.
Main host goes away
If you are adding virtual hosts to an existing web server, you must
also create a block for the existing host. The
ServerName and DocumentRoot included in this virtual host should be
the same as the global ServerName and DocumentRoot. List this virtual
host first in the configuration file so that it will act as the
default host.
For example, to work properly with XAMPP, to prevent VirtualHost overriding the main host, add the follow lines into file httpd-vhosts.conf:
# Main host
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/xampp/htdocs"
</VirtualHost>
# Additional host
<VirtualHost *:80>
# Over directives there
</VirtualHost>
For someone doing everything described here and still can't access:
XAMPP with Apache 2.4:
In file httpd-vhost.conf:
<VirtualHost *>
DocumentRoot "D:/xampp/htdocs/dir"
ServerName something.dev
<Directory "D:/xampp/htdocs/dir">
Require all granted #apache v 2.4.4 uses just this
</Directory>
</VirtualHost>
There isn't any need for a port, or an IP address here. Apache configures it on its own files. There isn't any need for NameVirtualHost *:80; it's deprecated. You can use it, but it doesn't make any difference.
Then to edit hosts, you must run Notepad as administrator (described below). If you were editing the file without doing this, you are editing a pseudo file, not the original (yes, it saves, etc., but it's not the real file)
In Windows:
Find the Notepad icon, right click, run as administrator, open file, go to C:/WINDOWS/system32/driver/etc/hosts, check "See all files", and open hosts.
If you were editing it before, probably you will see it's not the file you were previously editing when not running as administrator.
Then to check if Apache is reading your httpd-vhost.conf, go to folder xampFolder/apache/bin, Shift + right click, open a terminal command here, open XAMPP (as you usually do), start Apache, and then on the command line, type httpd -S. You will see a list of the virtual hosts. Just check if your something.dev is there.
According to this documentation: Name-based Virtual Host Support
You may be missing the following directive:
NameVirtualHost *:80
Just change <VirtualHost *:80> to <VirtualHost 127.0.0.1:80>.
Then the default DocumentRoot will serve for all domains or IP addresses that point to your server and specified VirtualHost will work.
It may be because your web folder (as mentioned "/Applications/MAMP/htdocs/mysite/web") is empty.
My suggestion is first to make your project and then work on making the virtual host.
I went with a similar situation. I was using an empty folder in the DocumentRoot in httpd-vhosts.confiz and I couldn't access my shahg101.com site.
I am running Ubuntu 16.04 (Xenial Xerus). This is what worked for me:
Open up a terminal and cd to /etc/apache2/sites-available. There
you will find a file called 000-default.conf.
Copy that file: cp 000-default.conf example.local.conf
Open that new file (I use Nano; use what you are comfortable with).
You will see a lot of commented lines, which you can delete.
Change <VirtualHost *:80> to <VirtualHost example.local:80>
Change the document root to reflect the location of your files.
Add the following line: ServerName example.local And if you need to, add this line: ServerAlias www.example.local
Save the file and restart Apache: service Apache2 restart
Open a browser and navigate to example.local. You should see your website.
For anyone using Windows and the Bitnami WAMP Stack Manager Tool this virtual host configuration should go into Bitnami\apache2\conf\bitnami\bitnami.conf
Note: Some settings in Directory section is not a must.
For example, my virtual host configuration for site.com would be as follows:
<VirtualHost site.com:80>
DocumentRoot "C:/Bitnami/apache2/htdocs/site/docroot"
<Directory "C:/Bitnami/apache2/htdocs/site/docroot">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
Remember that configuration for vhost as mentioned, by other friends, sagits's answer is needed.

Apache configuration for Symfony website with virtual hosts

I'm trying to configure my local Apache2 server to host several Symfony websites using virtual hosts, but I just can't make it to alias lib/vendor/symfony/data/web/sf directory as /sf. I see that using %1 and %2 in alias statement is the source of the problem, but I can't find the right solution. I added to /etc/hosts entry 127.0.0.1 jobeet.sandbox.sfdevel, I created in my home directory directory ~/Projekty/sandbox/jobeet. My Apache2 site configuration reads as follows:
<VirtualHost *:80>
ServerName localhost
ServerAlias *.sfdevel
VirtualDocumentRoot /home/alef/Projekty/%2/%1/web
<Directory /home/alef/Projekty/%2/%1/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf
<Directory /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf>
AllowOverride All
Allow from All
</Directory>
ErrorLog /var/log/apache2/sfdevel_error.log
LogLevel warn
CustomLog /var/log/apache2/sfdevel_access.log combined
</VirtualHost>
When I change /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf to /home/alef/Projekty/sandbox/jobeet/lib/vendor/symfony/data/web/sf it works just fine, but I want to use several separate Symfony websites. What changes should I include in my Apache2 configuration?
I'm not sure if you can create aliases this way. There's nothing about it in the apache documentation.
I'd think about removing Alias from your virtualhost definition anyway. Symbolic link will work the same:
cd /home/alef/Projekty/sandbox/jobeet/web
ln -s ../lib/vendor/symfony/data/web/sf