typo
[friendica.git/.git] / INSTALL.md
1 # Friendica Installation
2
3 We've tried very hard to ensure that Friendica will run on commodity hosting
4 platforms - such as those used to host Wordpress blogs and Drupal websites.
5 But be aware that Friendica is more than a simple web application. It is a
6 complex communications system which more closely resembles an email server than
7 a web server. For reliability and performance, messages are delivered in the
8 background and are queued for later delivery when sites are down. This kind of
9 functionality requires a bit more of the host system than the typical blog.
10 Not every PHP/MySQL hosting provider will be able to support Friendica. Many will.
11 But please review the requirements and confirm these with your hosting provider
12 prior to installation.
13
14 Before you begin: Choose a domain name or subdomain name for your server.
15 Put some thought into this - because changing it is currently not-supported.
16 Things will break, and some of your friends may have difficulty communicating with you.
17 We plan to address this limitation in a future release. Also decide if you wish
18 to connect with members of the Diaspora network, as this will impact the
19 installation requirements.
20
21 Decide if you will use SSL and obtain an SSL cert. Communications with the
22 Diaspora network MAY require both SSL AND an SSL cert signed by a CA which is
23 recognized by major browsers. Friendica will work with self-signed certs but
24 Diaspora communication may not. For best results, install your cert PRIOR to
25 installing Friendica and when visiting your site for the initial installation in
26 step 5, please use the https: link. (Use the http: or non-SSL link if your cert
27 is self-signed).
28
29 ## 1. Requirements
30
31 - Apache with mod-rewrite enabled and "Options All" so you can use a local .htaccess file
32 - PHP 5.6.1+ (PHP 7.1+ recommended for performance and official support).
33         - PHP *command line* with `register_argc_argv = true` in php.ini
34         - curl, gd (with at least jpeg support), mysql, mbstring, xml, zip and openssl extensions
35         - Some form of email server or email gateway such that PHP mail() works
36         - The POSIX module of PHP needs to be activated (e.g. RHEL, CentOS have disabled it)
37         - Composer for a Git install
38
39 - Mysql 5.6+ or an equivalent alternative for MySQL (MariaDB 10.0.5+, Percona Server etc.)
40 - Ability to schedule jobs with cron (Linux/Mac) or Scheduled Tasks (Windows)
41 - Installation into a top-level domain or sub-domain (without a directory/path 
42   component in the URL) is preferred. This is REQUIRED if you wish to communicate
43   with the Diaspora network.
44 - For alternative server configurations (such as Nginx server and MariaDB database
45   engine), refer to the [Friendica wiki](https://github.com/friendica/friendica/wiki).
46
47 This guide will walk you through the manual installation process of Friendica.
48 If this is nothing for you, you might be interested in:
49 * the Friendica Docker image (https://github.com/friendica/docker) or
50 * how install Friendica with YunoHost (https://github.com/YunoHost-Apps/friendica_ynh).
51
52 ## 2. Install Friendica sources
53
54 Unpack the Friendica files into the root of your web server document area.
55
56 If you copy the directory tree to your webserver, make sure that you also copy 
57 `.htaccess-dist` - as "dot" files are often hidden and aren't normally copied.
58
59 OR
60
61 Clone the friendica/friendica GitHub repository and import dependencies
62
63         git clone https://github.com/friendica/friendica -b master [web server folder]
64         cd [web server folder]
65         bin/composer.phar install --no-dev
66
67 Make sure the folder view/smarty3 exists and is writable by the webserver user,
68 in this case `www-data`
69
70     mkdir view/smarty3
71     chown www-data:www-data view/smarty3
72     chmod 775 view/smarty3
73
74 Get the addons by going into your website folder.
75
76     cd mywebsite
77
78 Clone the addon repository (separately):
79
80     git clone https://github.com/friendica/friendica-addons.git -b master addon
81
82 If you want to use the development version of Friendica you can switch to the 
83 develop branch in the repository by running
84
85     git checkout develop
86     bin/composer.phar install
87     cd addon
88     git checkout develop
89
90 Please be aware that the develop branch is unstable.
91 Exercise caution when pulling.
92 If you encounter a bug, please let us know.
93
94 Either way, if you use Apache, copy `.htaccess-dist` to `.htaccess` to enable 
95 URL rewriting.
96
97 ## 3. Database
98
99 Create an empty database and note the access details (hostname, username, password,
100 database name).
101
102 - Friendica needs the permission to create and delete fields and tables in its 
103   own database.
104 - Please check the additional notes if running on MySQ 5.7.17 or newer
105
106 ## 4. Config 
107
108 If you know in advance that it will be impossible for the web server to write or
109 create files in the `config/` directory, please create an empty file called 
110 `local.config.php` in it and make it writable by the web server.
111
112 ## 5a. Install Wizard
113
114 Visit your website with a web browser and follow the instructions.
115 Please note any error messages and correct these before continuing.
116
117 If you are using SSL with a known signature authority (recommended), use the
118 https: link to your website. If you are using a self-signed cert or no cert,
119 use the http: link.
120
121 If you need to specify a port for the connection to the database, you can do so
122 in the host name setting for the database.
123
124 ## 5b. Manual install
125
126 *If* the automated installation fails for any reason, please check the following:
127
128 - `config/local.config.php` exists
129         - If not, copy `config/local-sample.config.php` to `config/local.config.php`
130           and edit it with your settings.
131 - Database is populated.
132         - If not, import the contents of `database.sql` with phpMyAdmin or the mysql
133           command line tool.
134
135 ## 6. Register the admin account
136
137 At this point visit your website again, and register your personal account with
138 the same email as in the `config.admin_email` config value.
139 Registration errors should all be recoverable automatically.
140
141 If you get any *critical* failure at this point, it generally indicates the
142 database was not installed correctly. You might wish to delete/rename 
143 `config/local.config.php` to another name and drop all the database tables so
144 that you can start fresh.
145
146 ## 7. Background tasks (IMPORTANT)
147
148 Set up a cron job or scheduled task to run the worker once every 5-10 minutes to
149 pick up the recent "public" postings of your friends. Example:
150
151         cd /base/directory; /path/to/php bin/worker.php
152
153 Change "/base/directory", and "/path/to/php" as appropriate for your situation.
154
155 If you are using a Linux server, run "crontab -e" and add a line like the one
156 shown, substituting for your unique paths and settings:
157
158         */10 * * * *    cd /home/myname/mywebsite; /usr/bin/php bin/worker.php
159
160 You can generally find the location of PHP by executing "which php".
161 If you have troubles with this section please contact your hosting provider for assistance.
162 Friendica will not work correctly if you cannot perform this step.
163
164 You should also be sure that `config.php_path` is set correctly, it should look
165 like this: (changing it to the correct PHP location)
166
167         'config' => [
168         'php_path' => '/usr/local/php56/bin/php',
169     ]
170
171 Alternative: If you cannot use a cron job as described above, you can use the
172 frontend worker and an external cron service to trigger the execution of the worker script.
173 You can enable the frontend worker after the installation from the admin panel
174 of your node and call:
175  
176          https://example.com/worker
177
178 with the service of your choice.
179
180 ## 8. (Recommended) Set up a backup plan
181
182 Bad things will happen.
183 Let there be a hardware failure, a corrupted database or whatever you can think of.
184 So once the installation of your Friendica node is done, you should make yourself
185 a backup plan.
186
187 The most important file is the `config/local.config.php` file in the base directory.
188 As it stores all your data, you should also have a recent dump of your Friendica
189 database at hand, should you have to recover your node.
190
191 ## 9. (Optional) Reverse-proxying and HTTPS
192
193 Friendica looks for some well-known HTTP headers indicating a reverse-proxy
194 terminating an HTTPS connection.
195 While the standard from RFC 7239 specifies the use of the `Forwaded` header.
196
197     Forwarded: for=192.0.2.1; proto=https; by=192.0.2.2
198
199 Friendica also supports a number on non-standard headers in common use.
200
201     X-Forwarded-Proto: https
202
203     Front-End-Https: on
204
205     X-Forwarded-Ssl: on
206
207 It is however preferable to use the standard approach if configuring a new server.
208
209 ## Troubleshooting
210
211 ### "System is currently unavailable. Please try again later"
212
213 Check your database settings.
214 It usually means your database could not be opened or accessed.
215 If the database resides on the same machine, check that the database server name
216 is "localhost".
217
218 ### 500 Internal Error
219
220 This could be the result of one of our Apache directives not being supported by
221 your version of Apache. Examine your apache server logs.
222 You might remove the line "Options -Indexes" from the .htaccess file if you are
223 using a Windows server as this has been known to cause problems.
224 Also check your file permissions. Your website and all contents must generally
225 be world-readable.
226
227 It is likely that your web server reported the source of the problem in its error log files.
228 Please review these system error logs to determine what caused the problem.
229 Often this will need to be resolved with your hosting provider or (if self-hosted)
230 your web server configuration.
231
232 ### 400 and 4xx "File not found" errors
233
234 First check your file permissions.
235 Your website and all contents must generally be world-readable.
236
237 Ensure that mod-rewite is installed and working, and that your `.htaccess` file
238 is being used. To verify the latter, create a file `test.out` containing the
239 word "test" in the top directory of Friendica, make it world readable and point
240 your web browser to
241
242         http://yoursitenamehere.com/test.out
243
244 This file should be blocked. You should get a permission denied message.
245
246 If you see the word "test" your Apache configuration is not allowing your
247 `.htaccess` file to be used (there are rules in this file to block access to any
248 file with .out at the end, as these are typically used for system logs).
249
250 Make certain the `.htaccess` file exists and is readable by everybody, then look
251 for the existence of "AllowOverride None" in the Apache server configuration for your site.
252 This will need to be changed to "AllowOverride All".
253
254 If you do not see the word "test", your `.htaccess` is working, but it is likely
255 that mod-rewrite is not installed in your web server or is not working.
256
257 On most Linux flavors:
258
259         % a2enmod rewrite
260         % /etc/init.d/apache2 restart
261
262 Consult your hosting provider, experts on your particular Linux distribution or
263 (if Windows) the provider of your Apache server software if you need to change
264 either of these and can not figure out how. There is a lot of help available on
265 the web. Search "mod-rewrite" along with the name of your operating system
266 distribution or Apache package (if using Windows).
267
268 ### Unable to write the file config/local.config.php due to permissions issues
269
270 Create an empty `config/local.config.php`file with that name and give it
271 world-write permission.
272
273 On Linux:
274
275         % touch config/local.config.php
276         % chmod 664 config/local.config.php
277
278 Retry the installation. As soon as the database has been created,
279
280 ******* this is important *********
281
282         % chmod 644 config/local.config.php
283
284 ### Suhosin issues
285
286 Some configurations with "suhosin" security are configured without an ability to
287 run external processes. Friendica requires this ability. Following are some notes
288 provided by one of our members.
289
290 > On my server I use the php protection system Suhosin [http://www.hardened-php.net/suhosin/].
291 > One of the things it does is to block certain functions like proc_open, as
292 > configured in `/etc/php5/conf.d/suhosin.ini`:
293
294 >     suhosin.executor.func.blacklist = proc_open, ...
295 >
296 > For those sites like Friendica that really need these functions they can be
297 > enabled, e.g. in `/etc/apache2/sites-available/friendica`:
298 >
299 >       <Directory /var/www/friendica/>
300 >         php_admin_value suhosin.executor.func.blacklist none
301 >         php_admin_value suhosin.executor.eval.blacklist none
302 >       </Directory>
303
304 > This enables every function for Friendica if accessed via browser, but not for
305 > the cronjob that is called via php command line. I attempted to enable it for
306 > cron by using something like:
307
308 >       */10 * * * * cd /var/www/friendica/friendica/ && sudo -u www-data /usr/bin/php \
309 >       -d suhosin.executor.func.blacklist=none \
310 >       -d suhosin.executor.eval.blacklist=none -f bin/worker.php
311
312 > This worked well for simple test cases, but the friendica-cron still failed
313 > with a fatal error:
314
315 >       suhosin[22962]: ALERT - function within blacklist called: proc_open()
316 >     (attacker 'REMOTE_ADDR not set', file '/var/www/friendica/friendica/boot.php',
317 >     line 1341)
318
319 > After a while I noticed, that `bin/worker.php` calls further PHP script via `proc_open`.
320 > These scripts themselves also use `proc_open` and fail, because they are NOT
321 > called with `-d suhosin.executor.func.blacklist=none`.
322
323 >  So the simple solution is to put the correct parameters into `config/local.config.php`:
324
325 >       'config' => [
326 >               //Location of PHP command line processor
327 >               'php_path' => '/usr/bin/php -d suhosin.executor.func.blacklist=none \
328 >               -d suhosin.executor.eval.blacklist=none',
329 >       ],
330
331 > This is obvious as soon as you notice that the friendica-cron uses `proc_open`
332 > to execute PHP scripts that also use `proc_open`, but it took me quite some time to find that out.
333 > I hope this saves some time for other people using suhosin with function blacklists.
334
335 ### Unable to create all mysql tables on MySQL 5.7.17 or newer
336
337 If the setup fails to create all the database tables and/or manual creation from
338 the command line fails, with this error:
339
340         ERROR 1067 (42000) at line XX: Invalid default value for 'created'
341
342 You need to adjust your my.cnf and add the following setting under the [mysqld]
343 section:
344
345         sql_mode = '';
346
347 After that, restart mysql and try again.