phpow 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/bin/phpow +11 -0
- data/lib/phpow/client.rb +108 -0
- data/lib/phpow/core.rb +50 -0
- data/lib/phpow/rack_app.rb +39 -0
- data/lib/phpow/templates/.powconfig +1 -0
- data/lib/phpow/templates/apache.conf.erb +29 -0
- data/lib/phpow/templates/config.ru +2 -0
- data/lib/phpow/version.rb +3 -0
- data/lib/phpow.rb +1 -0
- data/phpow.gemspec +17 -0
- metadata +64 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Daniel Ott
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
Phpow
|
2
|
+
=====
|
3
|
+
|
4
|
+
Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'phpow'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install phpow
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
`phpow install`
|
25
|
+
|
26
|
+
Creates the apache configuration file that will listen on port 8888
|
27
|
+
|
28
|
+
`phpow uninstall`
|
29
|
+
|
30
|
+
Removes the apache configuration file that will listen on port 8888
|
31
|
+
|
32
|
+
`phpow create`
|
33
|
+
|
34
|
+
Creates symbolic links to phpow's `config.ru` and `.powconfig` files in the current working directory.
|
35
|
+
|
36
|
+
`phpow destroy`
|
37
|
+
|
38
|
+
Removes the symbolic links to phpow's `config.ru` and `.powconfig` files in the current working directory.
|
39
|
+
|
40
|
+
### Configuration
|
41
|
+
|
42
|
+
By default phpow will set up apache to listen on port 8888, and serve projects from `/Users/username/Sites`. Either one of these defaults can be overridden by creating a `.phpowconfig` file in your home directory.
|
43
|
+
|
44
|
+
```
|
45
|
+
# ~/.phpowconfig Example
|
46
|
+
export PHPOW_APACHE_PORT=8080
|
47
|
+
export PHPOW_PROJECTS_DIRECTORY=/Users/username/another/specific/directory
|
48
|
+
```
|
49
|
+
|
50
|
+
Contributing
|
51
|
+
------------
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/phpow
ADDED
data/lib/phpow/client.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
module Phpow
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
extend Phpow
|
7
|
+
|
8
|
+
##
|
9
|
+
# A convenvetion borrowed from powify. Define the allowable command line methods.
|
10
|
+
#
|
11
|
+
AVAILABLE_METHODS = %w[create destroy install uninstall help]
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
##
|
16
|
+
# Phpow::Client.run
|
17
|
+
#
|
18
|
+
# A wrapper for the command line interface.
|
19
|
+
#
|
20
|
+
def run(args = [])
|
21
|
+
|
22
|
+
load_config
|
23
|
+
|
24
|
+
method = args[0].to_s.downcase
|
25
|
+
begin
|
26
|
+
raise "The command `#{args[0]}` does not exist for `phpow`!" unless Phpow::Client::AVAILABLE_METHODS.include?(method)
|
27
|
+
return send(method)
|
28
|
+
rescue Exception => e
|
29
|
+
puts e
|
30
|
+
end
|
31
|
+
help
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
##
|
36
|
+
# phpow create
|
37
|
+
# Create the symbolic links to effectively run Phpow:RackApp.
|
38
|
+
#
|
39
|
+
def create
|
40
|
+
symlink_files.each do |file|
|
41
|
+
FileUtils.ln_s(File.join(File.dirname(__FILE__), "templates", file), File.join(current_path, file))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
##
|
47
|
+
# phpow destroy
|
48
|
+
# Unlink the files that were linked using phpow create.
|
49
|
+
#
|
50
|
+
def destroy
|
51
|
+
symlink_files.each do |file|
|
52
|
+
symlink_path = File.join(current_path, file)
|
53
|
+
FileUtils.rm(symlink_path) if File.symlink?(symlink_path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
##
|
59
|
+
# phpow install
|
60
|
+
# Install the apache configuration file in `apache_conf_path`
|
61
|
+
#
|
62
|
+
def install
|
63
|
+
require 'erb'
|
64
|
+
template = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "apache.conf.erb")))
|
65
|
+
result = template.result(binding)
|
66
|
+
|
67
|
+
# Need the current user to own the file in able to write to it.
|
68
|
+
unless File.owned?(apache_conf_path)
|
69
|
+
puts "'#{File.dirname(apache_conf_path)}' is write protected by root. You will have to enter your administrator password in order to create #{apache_conf_path}"
|
70
|
+
%x{sudo touch #{apache_conf_path} && sudo chown #{user} #{apache_conf_path}}
|
71
|
+
end
|
72
|
+
|
73
|
+
f = File.new(apache_conf_path, 'w')
|
74
|
+
f.puts(result)
|
75
|
+
f.chmod(0644)
|
76
|
+
f.close
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
##
|
81
|
+
# phpow uninstall
|
82
|
+
# Remove the apache configuration file from `apache_conf_path`
|
83
|
+
#
|
84
|
+
def uninstall
|
85
|
+
puts "Are you sure you want to remove the file '#{apache_conf_path}'?"
|
86
|
+
print "Enter 'yes' to confirm: "
|
87
|
+
|
88
|
+
confirmation = gets.strip.downcase
|
89
|
+
return unless confirmation == "yes"
|
90
|
+
|
91
|
+
%x{sudo rm #{apache_conf_path}}
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
##
|
96
|
+
# Print helpful information to the command line.
|
97
|
+
#
|
98
|
+
def help
|
99
|
+
print <<-HELPTEXT
|
100
|
+
See README at http://github.com/danott/phpow
|
101
|
+
HELPTEXT
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/lib/phpow/core.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'phpow/client'
|
2
|
+
require 'phpow/rack_app'
|
3
|
+
|
4
|
+
module Phpow
|
5
|
+
|
6
|
+
attr_accessor :apache_port, :projects_directory
|
7
|
+
|
8
|
+
def apache_port
|
9
|
+
@apache_port || 8888
|
10
|
+
end
|
11
|
+
|
12
|
+
def projects_directory
|
13
|
+
@projects_directory || "/Users/#{user}/Sites"
|
14
|
+
end
|
15
|
+
|
16
|
+
def projects_directory=(directory)
|
17
|
+
@projects_directory = directory.gsub(/\/*$/, '')
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_path
|
21
|
+
%x{pwd}.strip
|
22
|
+
end
|
23
|
+
|
24
|
+
def user
|
25
|
+
%x{whoami}.strip
|
26
|
+
end
|
27
|
+
|
28
|
+
def apache_conf_path
|
29
|
+
"/etc/apache2/users/#{user}.conf"
|
30
|
+
end
|
31
|
+
|
32
|
+
def symlink_files
|
33
|
+
%w[config.ru .powconfig]
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
##
|
38
|
+
# Configuration variables can be stored in '~/.phpowconfig'
|
39
|
+
#
|
40
|
+
# PHPOW_APACHE_PORT: Configure apache to run on a port other than 8888
|
41
|
+
# PHPOW_PROJECTS_DIRECTORY: Serve your projects out of a directory other than /Users/user/Sites
|
42
|
+
#
|
43
|
+
def load_config
|
44
|
+
if File.exists?(File.expand_path('~/.phpowconfig'))
|
45
|
+
self.apache_port = %x{source ~/.phpowconfig; echo $PHPOW_APACHE_PORT}.strip unless %x{source ~/.phpowconfig; echo $PHPOW_APACHE_PORT}.strip.empty?
|
46
|
+
self.projects_directory = %x{source ~/.phpowconfig; echo $PHPOW_PROJECTS_DIRECTORY}.strip unless %x{source ~/.phpowconfig; echo $PHPOW_PROJECTS_DIRECTORY}.strip.empty?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Phpow
|
2
|
+
|
3
|
+
class RackApp
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
extend Phpow
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
load_config
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
request = Rack::Request.new(env)
|
14
|
+
headers = {}
|
15
|
+
|
16
|
+
# Make the POW request to the Apache server
|
17
|
+
# http://myapp.dev/full/path/goes/here/
|
18
|
+
# ...will map to...
|
19
|
+
# http://myapp.dev:8888/full/path/goes/here/
|
20
|
+
http = Net::HTTP.new(request.host, apache_port)
|
21
|
+
response = http.send_request(request.request_method, request.fullpath, request.body.read, headers)
|
22
|
+
|
23
|
+
# Map Net::HTTP response back to Rack::Request.call expects
|
24
|
+
status, headers, body = response.code, response.to_hash, [response.body]
|
25
|
+
|
26
|
+
# Research showed that browsers were choking on this for some reason.
|
27
|
+
# Probably not the be-all-end-all solution, but works for local development thus far.
|
28
|
+
headers.delete('transfer-encoding')
|
29
|
+
|
30
|
+
# Send the response back to POW
|
31
|
+
[status, headers, body]
|
32
|
+
|
33
|
+
rescue Errno::ECONNREFUSED
|
34
|
+
[500, {}, ["Server is down, try $ sudo apachectl start"]]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
export POW_WORKERS=10
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Apache configuration
|
2
|
+
# Should be written to /etc/apache2/users/username.conf on Mac OS X
|
3
|
+
|
4
|
+
# Enable PHP
|
5
|
+
LoadModule php5_module libexec/apache2/libphp5.so
|
6
|
+
<IfModule php5_module>
|
7
|
+
AddType application/x-httpd-php .php
|
8
|
+
AddType application/x-httpd-php-source .phps
|
9
|
+
<IfModule dir_module>
|
10
|
+
DirectoryIndex index.html index.php
|
11
|
+
</IfModule>
|
12
|
+
</IfModule>
|
13
|
+
|
14
|
+
# Pow is using port 80. Will forward to apache on <%= apache_port %> using Phpow::RackApp
|
15
|
+
Listen <%= apache_port %>
|
16
|
+
|
17
|
+
# Virtual hosts, piggy-backing on POW's .dev
|
18
|
+
DocumentRoot <%= projects_directory %>
|
19
|
+
<Directory "<%= projects_directory %>/">
|
20
|
+
Options Indexes MultiViews FollowSymLinks
|
21
|
+
AllowOverride All
|
22
|
+
Order allow,deny
|
23
|
+
Allow from all
|
24
|
+
</Directory>
|
25
|
+
|
26
|
+
NameVirtualHost 127.0.0.1
|
27
|
+
<VirtualHost 127.0.0.1>
|
28
|
+
VirtualDocumentRoot <%= projects_directory %>/%-2+
|
29
|
+
</VirtualHost>
|
data/lib/phpow.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'phpow/core'
|
data/phpow.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/phpow/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Daniel Ott"]
|
6
|
+
gem.email = ["danott@me.com"]
|
7
|
+
gem.description = %q{Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X}
|
8
|
+
gem.summary = %q{Having a single TLD for both Rails and PHP development keeps things simple. But both POW and Apache can't listen on port 80. Get around this by running a light weight Rack application in POW as an in-between for Apache/PHP running on a different port.}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "phpow"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Phpow::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phpow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Ott
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X
|
15
|
+
email:
|
16
|
+
- danott@me.com
|
17
|
+
executables:
|
18
|
+
- phpow
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/phpow
|
28
|
+
- lib/phpow.rb
|
29
|
+
- lib/phpow/client.rb
|
30
|
+
- lib/phpow/core.rb
|
31
|
+
- lib/phpow/rack_app.rb
|
32
|
+
- lib/phpow/templates/.powconfig
|
33
|
+
- lib/phpow/templates/apache.conf.erb
|
34
|
+
- lib/phpow/templates/config.ru
|
35
|
+
- lib/phpow/version.rb
|
36
|
+
- phpow.gemspec
|
37
|
+
homepage: ''
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.17
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Having a single TLD for both Rails and PHP development keeps things simple.
|
61
|
+
But both POW and Apache can't listen on port 80. Get around this by running a light
|
62
|
+
weight Rack application in POW as an in-between for Apache/PHP running on a different
|
63
|
+
port.
|
64
|
+
test_files: []
|