Ruby on rails - Apache config file error - ruby

I am reading a book about "Ruby on Rails" and now I have to deploy my application using Apache and Passenger. Everything seems to be installed properly but when I have finally add the following code in the Apache config file:
<VirtualHost *:80>
ServerName depot.yourhost.com
DocumentRoot /home/gotqn/Aptana Projects/depot/public/
<Directory /home/gotqn/Aptana Projects/depot/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and try to restart the Apache:
$ sudo apachectl restart
I get the following error:
Syntax error on line 245 of /etc/apache2/apache2.conf:
DocumentRoot takes one argument, Root directory of the document tree
Action 'restart' failed.
The Apache error log may have more information.
The line 245 refers to the following line:
DocumentRoot /home/gotqn/Aptana Projects/depot/public/
Any ideas what I have done wrong?

Spaces are not allowed in this line, just put the whole path in double quotes
DocumentRoot "/home/gotqn/Aptana Projects/depot/public/"

You used spaces in directory path you need to escape the spaces or create path without spaces.
Instead of adding it to apache2.conf create one file(called newsite or something) in /etc/apache2/site-available and write the same thing in that file. And then run following commad:
sudo a2ensite newsite
Then restart server and add your server name to /etc/hosts

Related

Laravel: 1 folder, 2 environments

I have a question about a bad practice in Laravel.
I have only one server folder available for Laravel (in IIS).
There, I have the production site.
If I want to add a copy for development and testing against the test database, where must I place it?
Inside the production's version public folder? I donth think because it's unsafe. Sure will be an obvious best practice for that.
You can open a new port for it.
Example:
Config Virtual host with Production site:
Create a configuration file our laravel production project by typing the following commands
cd /etc/apache2/sites-available
sudo nano production.conf
In the production.conf file created paste the following content to the file and close it after saving.
Replace laravelproduction.com with the domain name of your website inside the file.
<VirtualHost *:80>
ServerName laravelproduction.com
DocumentRoot /var/www/html/production/public
<Directory /var/www/html/production>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2dissite 000-default.conf (disable the default .conf file)
sudo a2ensite production.conf (enables the newly created .conf file)
sudo a2enmod rewrite (enables the rewrite)
Also, restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
Config Virtual Host With Dev site
Create a configuration file our laravel dev project by typing the following commands
cd /etc/apache2/sites-available
sudo nano dev.conf
In the dev.conf file created paste the following content to the file and close it after saving.
Listen 8100
<VirtualHost *:8100>
ServerName laraveldev.com
DocumentRoot /var/www/html/dev/public
<Directory /var/www/html/dev>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2ensite dev.conf
Finally restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
This is how I usually use it. I hope to help you. ^_^

Create a Vhost in Ubuntu 16.04

I have started working in laravel and using lampp. I have watched many tutorials that use a vhost to make user-friendly url. I want to do it on Ubuntu 16.04.
Following tutorial is not working for me:
https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName mywebsite.dev
</VirtualHost>
Setup a virtual host for a Laravel project
First, copy the default configuration file and rename it:
$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost
open myVhost.conf file using this command:
$sudo nano /etc/apache2/sites-available/myVhost.conf
Add the directives:
assuming that the Laravel project is in /var/www/html/
ServerAdmin webmaster#localhost
serverName www.myAwesomeLink.com
DocumentRoot /var/www/html/laravel-app/public
<Directory /var/www/html/laravel-app>
AllowOverride All
</Directory>
so now the file will look something like this:
save and close.
Now add an entry in the hosts file:
$sudo nano /etc/hosts
add this line:
127.0.0.1 www.myAwesomeLink.com
save and close.
Enable site and the rewrite mode:
$sudo a2enmod rewrite
$sudo a2ensite myVhost.conf
Restart the server:
$sudo service apache2 restart
Serve the Laravel project:
open the project folder
php artisan serve
this will serve on port 8000 by default
you can also specify the port
php artisan serve --port=4200
Open the browser:
http://www.myAwesomeLink.com:8000
or any other specified port.
Source.
Its not working because the browsers have updated their security terms and policies including SSL certificates over .dev domains. just change your extension from .dev to something else like .localhost or .test.
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName dev.mywebsite.test
</VirtualHost>
Also change the extension in /etc/hosts from .dev to .test.
127.0.0.1 dev.mywebsite.test
Also keep in mind to restart the service to load the new added virtual host i.e: restart the Apache server
Hope it helps.
I think you also need to add a host in /etc/hosts. Open the hosts file and add this line:
127.0.0.1 mywebsite.dev
You will need to restart server after this.
1.Create new file under this path /etc/apache2/sites-available/myweb.conf
2.Copy the following to the file
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/html/mywebsite/public
ServerName dev.mywebsite.test
<Directory "/var/www/html/mywebsite/public">
Options All
AllowOverride All
Allow from all
</Directory>
3.Run "sudo a2ensite myweb.conf"
4.Add this line "Listen 80" to file "/etc/apache2/ports.conf"
5.Restart apache server

OSX Apache Virtualhost returns only default page

I have a problem using the build-in apache webserver under ElCapitan.
I want to set up my Sites-Directory in my users-directory. This works fine by adding a user config and and so on. So my localhost/~Fabian gives me the content of /User/Fabian/Sites/index.php.
Now I am trying to set up virtual hosts in this directory, e.g. /User/Fabian/Sites/Projekte/testsite.me/public.
So I activated the virtualhost module and included it in my httpd.conf. After this, I set up a virtualhost in the httpd-vhost.conf:
</VirtualHost *:80>
ServerAdmin xyz#blubber.de
DocumentRoot "/Users/Fabian/Sites/Projekte/testsite.me/public"
ServerName testsite.me
ErrorLog "/Users/Fabian/Sites/Logs/testsite-error_log"
CustomLog "/Users/Fabian/Sites/Logs/testsite-custom_log" common
</VirtualHost>
I also added the ServerAlias to my hosts file
127.0.0.1 testsite.me
Trying to open http://testsite.me shows me the default "It works"-page.
Running apachectl configtest gives me an syntax error:
httpd: Syntax error on line 499 of /private/etc/apache2/httpd.conf: Syntax error on line 74 of /private/etc/apache2/extra/httpd-vhosts.conf: </VirtualHost without matching <VirtualHost section
Line 499 in httpd.conf looks like this:
Include /private/etc/apache2/extra/httpd-vhosts.conf
Line 74ff of httpd-vhosts.conf contain the virtualhost I defined above.
Any idea how to solve this problem? What is a VirtualHost section?
Thank you!
You start your vhost definition with </VirtualHost *:80>
That should be <VirtualHost *:80> without the slash.
Although the apache config files are not xml, the Syntax for starting and ending sections are the same; so you start with <tag> and end with </tag>.

Mac apache localhost giving 403 Forbidden

Im trying to set up my local environment on my new mac OSX 10.9. I know it has apache already installed, so i've been using that. No matter how I set up my httpd-vhosts.conf/hosts/httpd.conf files, I continuously get a 403 forbidden error when visiting localhost OR "test.com" on my browser. The error / files / other information is listed below.
This is the error I'm getting when visiting either web page
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
My /private/etc/hosts file
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 test.com
127.0.0.1 www.test.com
My /private/etc/apache2/httpd.conf file
This file is in its original form besides the following changes:
Uncommented Include /private/etc/apache2/extra/httpd-vhosts.conf
My /private/etc/apache2/extra/httpd-vhosts file
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot "/Users/[my_name]/Sites/test"
<Directory "/Users/[my_name]/Sites/test">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Other notes
I've created a config file my user account in /private/etc/apache/users/
I've given that file read and write permissions to "everyone"
I've restarted apache after every save to any config file
I've reset the cache on my browser every time I make a change to these files
I have an index.html file set up in my /Users/[my_name]/Sites/test/ folder
When using the command sudo apachectl -t
Warning: DocumentRoot [/usr/\xe2\x80\x9c/Users/joshwoelfel/Sites/test\xe2\x80\x9d] does not exist
httpd: Could not reliably determine the server's fully qualified domain name, using Joshs-MacBook-Air.local for ServerName
Syntax OK
I don't know what to try at this point. I've spent several hours looking at tutorials and other questions people have posted. It looks like my files and permissions are correct!
I just resolved this issue. Try adding 'Require all granted' instead of 'Allow from all'.
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot "/Users/[my_name]/Sites/test"
<Directory "/Users/[my_name]/Sites/test">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
when you set DocuemntRoot "/Users/xxx/xxx" on mac os, your must ensure your httpd User && Group have permission to read the directory.By default, /Users/xxx/xxx owner is root and group is admin, so you don't have the permission. If your directory group is wheel it maybe work.
Verify every directory in the path to your DocumentRoot, not just the DocumentRoot itself, is searchable (+x permissions) for Apache. Upgrading my Mac OS reset my home directory to 700 permissions. Changing this to 755 fixed the issue for me.
After the last upgrade to MacOS HighSierra 10.13.4 I had the same message. I've tried different solutions posted around but the what really tipped me was an article mentioning that when you get this message it's usually just a matter of permissions. So in the end I just needed to make sure that the group and the owner of both the document root, that I don't keep under my profile path, and the children directory are owned by the same user and group specified in httpd.conf, are set to my group and username. The default values in httpd.conf are: _www and wheel respectively. If you're unsure about your user name use
whoami
on a terminal window.
If you're interested in keeping your files under your profile directory this guide may help you.

What is the mac equivalent of "/etc/apache2/sites-available"?

I am installing Koha from source. Generic unix directions indicate the following step after sudo make install
sudo ln -s /etc/koha/koha-httpd.conf /etc/apache2/sites-available/koha
huh?
My apache2 directory contains no sites-available, only
/private/etc/apache2/extra
/private/etc/apache2/httpd.conf
/private/etc/apache2/magic
/private/etc/apache2/mime.types
/private/etc/apache2/original
/private/etc/apache2/other
/private/etc/apache2/users
I am supposed to be able to Browse to http://servername:8080/ to run Koha, where I take it "servername" is specified in koha-httpd.conf as follows:
## Intranet
<VirtualHost 192.168.1.4:8080>
ServerAdmin webmaster#local
DocumentRoot /usr/share/koha/intranet/htdocs
ServerName John-Breedloves-Mac-mini.local:8080
# ServerAlias intranet.mydomain.com
ScriptAlias /cgi-bin/koha/ "/usr/share/koha/intranet/cgi-bin/"
ScriptAlias /index.html "/usr/share/koha/intranet/cgi-bin/mainpage.pl"
ScriptAlias /search "/usr/share/koha/intranet/cgi-bin/search.pl"
ErrorLog /var/log/koha/koha-error_log
# TransferLog /var/log/koha/koha-access_log
SetEnv KOHA_CONF "/etc/koha/koha-conf.xml"
SetEnv PERL5LIB "/usr/share/koha/lib"
Options +FollowSymLinks
ErrorDocument 400 /cgi-bin/koha/errors/400.pl
ErrorDocument 401 /cgi-bin/koha/errors/401.pl
ErrorDocument 403 /cgi-bin/koha/errors/403.pl
ErrorDocument 404 /cgi-bin/koha/errors/404.pl
ErrorDocument 500 /cgi-bin/koha/errors/500.pl
RewriteEngine On
However when I go to http://john-breedloves-mac-mini.local:8080/, I get:
It works!
Which,is, like ironical or something.
Help a noob out.
It looks like /private/etc/apache2/other/ would be the approximately corresponding folder. /etc/apache2/httpd.conf contains a directive Include /private/etc/apache2/other/*.conf that includes all files in that folder, much like the sites-available folder common on Linux installations of Apache.
Run apachectl -S which is shorthand for apachectl -t -D DUMP_VHOSTS
According to the apachectl man file, this will show parsed settings (currently only vhost settings). Incidentally, it also checks your config file for errors.
Andrew's answer is correct. On my install, I additionally had to change
Order allow,deny
Deny from all
to
Order allow,deny
Allow from all
in /etc/apache2/httpd.conf.
The fact that you're getting a server at :8080 indicates that you may be running a different apache config from the base system install, such as MAMP; I don't believe that apache by default listens on :8080.
I had this problem too. It seems to occour because the default version of apache that is installed on osx over-rides other versions. to disable it go to "System Preferences > Sharing" and untick "web sharing".
good luck!
Please note that ServerRoot specifies where the subdirectories conf and logs can be found.
In my httpd.conf, it is set to /usr

Resources