a6660fb47481017ee3399ff0d90f8f45b2d9455f
[phorkie.git] / README.rst
1 ************************************
2 phorkie - PHP and Git based pastebin
3 ************************************
4 Self-hosted pastebin software written in PHP.
5 Pastes are editable, may have multiple files and are stored in git repositories.
6
7 Project page: http://sourceforge.net/p/phorkie/
8
9 .. contents:: Table of Contents
10
11 ========
12 Features
13 ========
14   - every paste is a git repository
15   - repositories can be cloned
16   - clone url can be displayed
17   - openid authentication
18   - paste editing
19   - add new files
20   - delete existing files
21   - replace file with upload
22   - multiple files in one paste
23   - syntax highlighting with GeSHi
24   - rST and Markdown rendering
25   - image upload + display
26   - external tool support
27   - xmllint
28   - php syntax check
29   - history in the sidebar
30   - old files can be downloaded easily
31   - search across pastes: description, file names and file content
32   - options: quoting, logical and, or, not, partial words
33
34
35 ============
36 Installation
37 ============
38 1. Unzip the phorkie release file::
39
40    $ tar xjvf phorkie-0.2.0.tar.bz2
41
42 2. Create the git directories::
43
44    $ mkdir -p repos/git repos/work
45    $ chmod og+w repos/git repos/work
46
47 3. Install dependencies_
48
49 4. Copy ``data/config.php.dist`` to ``data/config.php`` and adjust it
50    to your needs::
51
52    $ cp data/config.php.dist data/config.php
53    $ $EDITOR data/config.php
54
55    Look at ``config.default.php`` for values that you may adjust.
56
57 5. Set your web server's document root to ``/path/to/phorkie/www/``
58
59 6. Open phorkie in your web browser
60
61
62 Dependencies
63 ============
64 phorkie stands on the shoulders of giants.  Git will need to be a
65 minimum version of v1.7.4.
66 ::
67   $ pear install versioncontrol_git-alpha
68   $ pear install services_libravatar-alpha
69   $ pear install http_request2
70   $ pear install pager
71   $ pear install date_humandiff-alpha
72
73   $ pear channel-discover pear.twig-project.org
74   $ pear install twig/Twig
75
76   $ pear channel-discover mediawiki.googlecode.com/svn
77   $ pear install mediawiki/geshi
78
79   $ pear channel-discover zustellzentrum.cweiske.de
80   $ pear install zz/mime_type_plaindetect-alpha
81
82   $ pear channel-discover pear.michelf.ca
83   $ pear install michelf/Markdown
84   
85 Note that this version of GeSHi is a bit outdated, but it's the fastest
86 way to install it.  If you install it manually be sure to update the
87 path in ``data/config.default.php``.
88
89 ======
90 Search
91 ======
92
93 phorkie makes use of an Elasticsearch__ installation, if you have one.
94
95 It is used to provide search capabilities and the list of recent pastes.
96
97 __ http://www.elasticsearch.org/
98
99 Setup
100 =====
101 Edit ``config.php``, setting the ``elasticsearch`` property to the HTTP URL
102 of the index, e.g. ::
103
104   http://localhost:9200/phorkie/
105
106 Run the index script to import all existing pastes into the index::
107
108   php scripts/index.php
109
110 That's all. Open phorkie in your browser, and you'll notice the search box
111 in the top menu.
112
113
114 Reset
115 =====
116 In case something really went wrong and you need to reset the search
117 index, run the following command::
118
119   $ curl -XDELETE http://localhost:9200/phorkie/
120   {"ok":true,"acknowledged"}
121
122 Phorkie will automatically re-index everything when ``setupcheck`` is enabled
123 in the configuration file.
124
125
126 =====
127 HowTo
128 =====
129
130 Make git repositories clonable
131 ==============================
132 To make git repositories clonable, you need to install ``git-daemon``
133 (``git-daemon-run`` package on Debian/Ubuntu).
134
135 Now make the repositories available by symlinking the paste repository
136 directory (``$GLOBALS['phorkie']['cfg']['repos']`` setting) into
137 ``/var/cache/git``, e.g.::
138
139   $ ln -s /home/user/www/paste/repos/git /var/cache/git/paste
140
141 Edit your ``config.php`` and set the ``$GLOBALS['phorkie']['cfg']['git']['public']``
142 setting to ``git://$yourhostname/git/paste/``.
143 The rest will be appended automatically.
144
145 You're on your own to setup writable repositories.
146
147 Protect your site with OpenID
148 =============================
149 You have the option of enabling OpenID authentication to help secure your
150 pastes on phorkie.  Set the ``$GLOBALS['phorkie']['auth']`` values in the
151 ``data/config.php`` file as desired.  
152
153 There are two different types of security you can apply.  First, you can
154 restrict to one of three ``securityLevels``; completely open (0), protection
155 of write-enabled functions such as add, edit, etc. (1), and full site
156 protection.  Additionally, you can restrict your site to ``listedUsersOnly``.
157 You will need to add the individual OpenIDs identity urls to the
158 ``$GLOBALS['phorkie']['auth']['users']`` variable.
159
160
161 =================
162 Technical details
163 =================
164
165 TODO
166 ====
167 - filters (``xmllint --format``, ``rapper``)
168 - document how to keep disk usage low (block size)
169 - comments
170 - when 2 people edit, merge changes
171 - diff changes
172 - configurable highlights
173 - Atom feed for new pastes
174 - Atom feed for paste changes
175
176
177 URLs
178 ====
179
180 ``/``
181   Index page.
182 ``/[0-9]+``
183   Display page for paste
184 ``/[0-9]/edit``
185   Edit the paste
186 ``/[0-9]+/raw/(.+)``
187   Display raw file contents
188 ``/[0-9]/tool/[a-zA-Z]+/(.+)``
189   Run a tool on the given file
190 ``/[0-9]/rev/[a-z0-9]+``
191   Show specific revision of the paste
192 ``/[0-9]/delete``
193   Delete the paste
194 ``/[0-9]/doap``
195   Show DOAP document for paste
196 ``/[0-9]/fork``
197   Create a fork of the paste
198 ``/search?q=..(&page=[0-9]+)?``
199   Search for term, with optional page
200 ``/list(/[0-9])?``
201   List all pastes, with optional page
202 ``/new``
203   Shows form for new paste
204 ``/login``
205   Login page for protecting site
206 ``/user``
207   Edit logged-in user information
208
209
210 Internal directory layout
211 =========================
212 ::
213
214   repos/
215     work/
216       1/ - work directory for paste #1
217       2/ - work directory for paste #2
218     git/
219       1.git/ - git repository for paste #1
220         description - Description for the repository
221       2.git/ - git repository for paste #2
222
223 nginx rewrites
224 ==============
225 If you use nginx, place the following lines into your ``server`` block:
226
227 ::
228
229   if (!-e $request_uri) {
230     rewrite ^/([0-9]+)$ /display.php?id=$1;
231     rewrite ^/([0-9]+)/delete$ /delete.php?id=$1;
232     rewrite ^/([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1;
233     rewrite ^/([0-9]+)/doap$ /doap.php?id=$1;
234     rewrite ^/([0-9]+)/edit$ /edit.php?id=$1;
235     rewrite ^/([0-9]+)/fork$ /fork.php?id=$1;
236     rewrite ^/([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2;
237     rewrite ^/([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2;
238     rewrite ^/([0-9]+)/rev-raw/(.+)$ /raw.php?id=$1&rev=$2&file=$3;
239     rewrite ^/([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3;
240
241     rewrite ^/new$ /new.php;
242     rewrite ^/list$ /list.php;
243     rewrite ^/list/([0-9]+)$ /list.php?page=$1;
244
245     rewrite ^/search$ /search.php;
246     rewrite ^/search/([0-9]+)$ /search.php?page=$1;
247
248     rewrite ^/login$ /login.php;
249     rewrite ^/user$ /user.php;
250   }