Apache - changing document root (Mac) - macos

I'm just getting started using Apache on my Mac (El Capitan 10.11.13), but I'd like to change the document root. However, I'm not sure I fully understand how to do this, or if it is even possible to set it up the way that I would like to...
For starters, here's the snippet from my httpd.conf file (I haven't made any changes, this is stock)...
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks Multiviews
MultiviewsMatch Any
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
I would like to change the DocumentRoot to the folder where I generally keep my web development work, which is:
/Users/myname/Desktop/Stuff/Development
I know that the first step is to replace the DocumentRoot and Directory in the .conf file, but this doesn't work - I get the 403 forbidden error - and I'm not sure what to do after that.
My questions...
Is it possible to set the document root to a folder that is associated with a specific user - me, in this case? I'm the only user of my machine, and it would be much easier for me to do what I need to if Apache was pointed at that folder.
If so, what do I need to do other than change the first two lines from the snippet of my .conf file? Please be specific, as I'm relatively new to working with the terminal.
Thanks very much.

Yes you can't just change DocumentRoot without giving the permission to new path. If you must use it you have to add chmod +x to each path, in your case those are
User
myname
...
Development
It is not safe to do so. I would user a folder doesn't involved Users.

Related

modify apache httpd.conf using ruby

Hey guys I'm trying to change in httpd.conf using ruby code 1.8.5 could you help me with it please
Apache configuration file The Apache configuration file must be configured specifically
for the server you have installed it on, i.e. the ServerName configuration item must be set to the IP address of the VM, not to 127.0.0.1 or any other generic address. TheServerAdmin configuration item must be set to cit470-sp2014-teamYOUR_TEAM_NUMBER#gmail.com. Create a gmail account with that name if you
have not done so already.
SSL All content must also be accessible using encrypted https versions of your URLs.
User directories Configure the server so that individual users can create their own web
sites by putting files in the public_html subdirectory of their home directory. These files should be available by both URLs of the form http://your_ip/~username and of the form http://your_ip/users/username. This may require that you create rewrite rules with mod_rewrite.
]# ./apconfigure.rb
./apconfigure.rb:8: warning: parenthesize argument(s) for future version
./apconfigure.rb:18: syntax error
.gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2#gmail.com")
^
./apconfigure.rb:19: syntax error
.gsub(/UserDir disable/, "UserDir public_html")
^
./apconfigure.rb:20: syntax error
.gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84 \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
^
this is my code
#!/usr/bin/ruby
# This script edits the Apache configuration files and enables UserDir,
# as well as a custom RewriteRule
# path to apache config file
config_file = "/etc/httpd/conf/httpd.conf"
file = File.read(config _file)
# regex to uncomment the sample UserDir directives
userdir_regex = /#<Directory \/home\/\*\/public_html>.+?<\/Directory>/m
replacement = file.match(userdir_regex).to_s.gsub('#','')
# make some substitutions: change ServerName and ServerAdmin, enable UserDir,
# add rewrite rules.
edited_file =
file
.gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2#gmail.com")
.gsub(/UserDir disable/, "UserDir public_html")
.gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84 \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
# write the changes to the file
File.open(config_file, 'w') do |f|
f.puts edited_file
end

Problems getting Apache running under Mac 10.9.1 Mavericks

all.
I am having ongoing problems getting Apache running under Mac 10.9.1 Mavericks (newest version).
I have apache running ("org.apache.httpd: Already loaded")
When I look at /etc/apache2/users/myfile.conf I see:
<Directory "/Users/rickeisner/Sites/">
Options Indexes Multiviews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
But when I run "apachectl configtest" to check the installation, I get:
[Tue Jan 21 12:21:51 2014] [warn] module php5_module is already loaded, skipping
Syntax error on line 4 of /private/etc/apache2/other/phpMyAdmin.conf:
order not allowed here
and when I look at /private/etc/apache2/other/phpMyAdmin.conf I see:
Alias /phpMyAdmin /usr/local/phpMyAdmin
Options Indexes
Order allow,deny
Allow from all
I can't make hide nor hair of this. Which is "line 4" anyway? "Options Indexes" or "Order allow,deny"? And what is wrong with this file?
I should add that I was only trying to get Apache/PHP/MySQL working on my computer, and couldn't get anything to work. Then, I began looking and found TOO MUCH INFORMATION. Everyone has slightly different versions of /etc/apache2/users/myfile.conf .
Please help me out of this confusion!
Rick

How can I use a Dropbox directory as a virtual host Document Root in OSX?

I set up LAMP on my OSX Lion server and everything seems to be working fine when I leave the defaults on.
Either:
A) Removing the username.conf file from /etc/apache2/users leaves the default running:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks MultiViews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
B) Otherwise, i.e. if i leave username.conf in the destination for localhost goes to the default in username.conf which is:
NameVirtualHost *:80
<Directory "/Users/USERNAME/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I would like to create a virtual host that points to one of my dropbox subdirectories so that I can develop seamlessly across devices.
However, when I try to point to /Users/USERNAME/Dropbox and any subdirectory therein I get the following errors:
[Fri Feb 24 19:00:06 2012] [error] [client 127.0.0.1] client denied by server configuration: /Users/username
[Fri Feb 24 19:00:35 2012] [notice] caught SIGTERM, shutting down
Warning: DocumentRoot [/Users/username/Dropbox/MY/DIRECTORY] does not exist
httpd: Could not reliably determine the server's fully qualified domain name, using My-MacBook-Air.local for ServerName
[Fri Feb 24 19:00:36 2012] [warn] mod_bonjour: Skipping user 'USERNAME' - no valid index file.
[Fri Feb 24 19:00:36 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Feb 24 19:00:36 2012] [notice] Digest: done
[Fri Feb 24 19:00:36 2012] [notice] Apache/2.2.21 (Unix) DAV/2 PHP/5.3.8 with Suhosin-Patch configured -- resuming normal operations
Where and what can I change to allow access?
Don't use Dropbox. If you need this kind of functionality, use WebDAV or host your own SparkleShare server.
Dropbox has had a series of security problems (even recent ones) that make it "scary" for many IT people. There's even software like Dropship that was designed to take advantage of some of its vulnerabilities. (Dropship doesn't work anymore, but it did for an alarmingly long time.) There has been at least one complaint to the FTC about Dropbox making false security claims on their web site. Respected journalists have reported on failures with Dropbox's subscription model that indicate the company still hasn't got it together.
Dropbox-the-company aside, you're asking a third party to keep an unencrypted copy of your data. This may be your source code for a site, log data or temporary files that might contain privileged/sensitive information. YOU may not be nervous about this, but what about the people who interact with you, whose data you may inadvertently be exposing to a third party (or their security policy) without disclosure?
For a hobby site, perhaps it doesn't matter. But a hobby site is what trains you for larger projects. You'd be better off getting in to good habits earlier rather than later.
If you need Dropbox-style functionality, SparkleShare is an open-source workalike that lets YOU provide the shared storage for your files. There are others. Put them on your co-located server, access them via SSH. You can review the source code of SparkleShare's (or any of the other open source optons) so that your safety is in YOUR hands, rather than that of corporation whose priority is their bottom line rather than your safety and security. (Why does Dropbox spend any money paying developers to fix security holes? Because it improves their bottom line. There can be NO other reason, according to US corporate law. A corporation's sole priority is to maximize shareholder return.)

Apache2 doesn't execute .rb files (mod_ruby)

I want to make apache2 run ruby scripts. I managed to do this by using CGI, but now I want to go one step further and do it with mod_ruby. I installed mod_ruby through apt-get so it's supposed to be enabled, but when I visit http://localhost/test.rb my browser downloads the file instead of displaying it's output.
If I open /etc/apache2/mods-enabled/ruby.load there is a line containing the path do this mod.
I also added the following lined to my apache2.conf:
<IfModule mod_ruby.c>
<Directory /var/www/>
Options +ExecCGI
</Directory>
RubyRequire apache/ruby-run
#RubySafeLevel 0
<Files *.rb>
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
</Files>
<Files *.rbx>
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
</Files>
</IfModule>
Can you please help me?
PS. Please don't suggest using ROR. I'm familiar with that. Now I just want to use ruby for educational reasons. Also please keep things simple I'm a total newbie to apache.
See this article - it has some instructions. Basically you need to tell Apache to pass your Ruby files through the handler.
Also, consider trying Sinatra - it's a micro web framework that's as simple as plain ruby files. And it runs with Passenger which is the well-documented Ruby module for Apache.
The article on HowtoForge covers almost the whole story, but I needed to add one line inside the <Directory /var/www> directive to prevent browsers from downloading the file:
AddType text/html .rb .rbx
Here are a couple more sites that I found helpful:
https://defuse.ca/blog/2012/07/how-to-install-mod_ruby-on-debian-squeeze/
http://modruby.net/en/doc/
Debian Stretch 9.
I tried installing mod_ruby with apt-get install libapache2-mod-ruby but there is no package by that name. In the end, all I needed to do was add this line to the apache-config to get the server to run my scripts.
AddHandler cgi-script .rb

Solution to multi server environment with a CodeIgniter website

I have a local, staging and production environment for my CodeIgniter based site. Increasingly I find everytime I deploy a version I have more and more little bits of code to change because of server variations.
What would be a good (and quick) solution I could add that would allow me to set these variables by just using one setting. Where would be the best place to insert this in the index.php, some sort of hook?
If you're using Apache, you can set an environmental variable which can be read by PHP in your Virtual Hosts file for the site:
<VirtualHost *:80>
DocumentRoot /path/to/site
ServerName local.mysite.com
ErrorLog /path/to/error_log
CustomLog /path/to/access_log common
<Directory /path/to/site>
SetEnv ENVIRONMENT local
RewriteEngine On
Options FollowSymLinks Indexes
AllowOverride AuthConfig Options FileInfo
</Directory>
</VirtualHost>
So with that, you now can check for and set the server environment accordingly in your index.php file:
// always default to production for safety
$environment = 'production';
// check for an environment override
if (function_exists('apache_getenv') && apache_getenv("ENVIRONMENT")) {
$environment = apache_getenv("ENVIRONMENT");
} else if (getenv("ENVIRONMENT")) {
$environment = getenv("ENVIRONMENT");
}
// set the environment constant
define('ENVIRONMENT', $environment);
With this setup, you now have the freedom to deploy your sites and add additional configuration parameters to your application/config/[file].php files for each environment.
Alternative...
Another possibility for handling multi-environment setups is to create a file outside of the document root and is ignored by your version control system (i.e. .gitignore) which contains the value of the server environment. You could then just read that file via file_get_contents() or equivalent.
define a "LIVE" constant which is TRUE or FALSE based on the current domain its on (put this in your index.php file)
if(strpos($_SERVER['HTTP_HOST'], 'mylivesite.com'))
{
define('LIVE', TRUE);
}
else
{
define('LIVE', FALSE);
}
and then check to see if you are live or not and assign the variables accordingly
if(LIVE)
{
$active_group = "production";
}
else
{
$active_group = "test";
}
ive been doing this with our 5 environment setup for the past year with no problems
An old question, but Codeigniter Reactor has support for environment variables built in now. You simply open up the index.php file and choose your environment. There is a post about them here: http://ilikekillnerds.com/2011/03/how-to-use-codeigniter-reactor-environment-variables/
The official CodeIgniter doc suggests this for multiple database environment:
Gobal variable in config.php file to set the environment:
$active_group = "test";
Multiple settings in database.php
$db['test']['hostname'] = "localhost";
$db['test']['username'] = "root";
$db['test']['password'] = "";
$db['test']['database'] = "database_name";
...
$db['production']['hostname'] = "example.com";
$db['production']['username'] = "root";
$db['production']['password'] = "";
$db['production']['database'] = "database_name";
...
See the doc for further details.
Having many little bits of code that change because of server variations is a bad sign that you're modifying code that's not supposed to be modified for the application. The only things that you're supposed to change between servers is your configuration variables located in config.php, which should have default values for the developers to change depending on the environment.

Resources