|
|
(11 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| = Migrating =
| | Please see https://docs.moodle.org/en/Nginx |
| | |
| == from lighttpd/php-fpm ==
| |
| | |
| Moving from a fully-functional lighttpd/php-fpm setup to nginx/php-fpm is fairly easy. The only trick is to pass the right values as fastcgi parameters.
| |
| | |
| If your current setup requires <code>cgi.fix_pathinfo=1</code> you should set the <code>SCRIPT_FILENAME</code> parameter in nginx as follows:
| |
| <code bash>
| |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name$fastcgi_path_info;
| |
| </code>
| |
| Without the above you'll probably have some issues with missing images and css styling.
| |
| | |
| = From scratch =
| |
| | |
| This is a starting guide to install Moodle with Nginx/PHP-fpm/Postgres on the
| |
| [http://releases.ubuntu.com/ latest Ubuntu LTS 14.04]. It is important to take note that Moodle is heavily tested in an Apache2 environment, not in a nginx environment. This document is for people having previously installed a Moodle site and a Ubuntu distribution, and having some basic knowledge of Linux command lines (vim, linux permissions, compiling, etc.).
| |
| | |
| == Nginx 1.4.6 ==
| |
| <code bash>
| |
| sudo apt-get update
| |
| | |
| sudo apt-get upgrade
| |
| | |
| sudo apt-get install nginx
| |
| | |
| mkdir -p /home/nginx/localhost/public
| |
| | |
| sudo chgrp www-data /home/nginx/localhost/public
| |
| </code>
| |
| | |
| | |
| sudo vim /etc/nginx/sites-available/default
| |
| <code bash>
| |
| server {
| |
| listen 80;
| |
| root /home/nginx/localhost/public;
| |
| index index.php index.html index.htm;
| |
|
| |
| location / {
| |
| # First attempt to serve request as file
| |
| try_files $uri $uri/index.php;
| |
| }
| |
|
| |
| # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
| |
| #
| |
| location ~ \.php$ {
| |
| fastcgi_split_path_info ^(.+\.php)(/.+)$;
| |
| # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
| |
|
| |
| # With php5-fpm:
| |
| fastcgi_pass unix:/var/run/php5-fpm.sock;
| |
| fastcgi_index index.php;
| |
| include fastcgi_params;
| |
| }
| |
| }
| |
| </code>
| |
| | |
| == Postgres 9.3.5 ==
| |
| | |
| <code bash>
| |
| sudo apt-get install postgresql
| |
| </code>
| |
| | |
| Create database user and database see [https://docs.moodle.org/en/PostgreSQL Moodle doc PostgreSQL]
| |
| | |
| == PHP 5.5.9 ==
| |
| Note: if you use postgres do not take PHP 5.3.5, pg_set_client_encoding() will crash with a http 500 error.
| |
| | |
| <code bash>
| |
| sudo apt-get install php5-fpm
| |
| sudo apt-get install php5-pgsql
| |
| sudo apt-get install php5-curl
| |
| sudo apt-get install php5-gd
| |
| sudo apt-get install php5-xmlrpc
| |
| sudo apt-get install php5-Intl
| |
| | |
| sudo service nginx restart
| |
| sudo service php5-fpm restart
| |
| </code>
| |
| | |
| vim /home/nginx/localhost/public/info.php
| |
| <code bash>
| |
| <?php
| |
| phpinfo();
| |
| ?>
| |
| </code>
| |
| | |
| Check if the site is available. [http://localhost/info.php localhost/info.php]
| |
| | |
| If you get a blank page... check if the following line is in your /etc/nginx/fastcgi_params file:
| |
| <code bash>
| |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
| |
| </code>
| |
| and if not then add it. (credit: [http://serverfault.com/questions/223500/blank-page-wordpress-on-nginxphp-fpm?rq=1 serverfault])
| |
| | |
| PHP 5.5 comes with OPCache. on older versions you might want to use APC:
| |
| == APC for PHP < 5.5 ==
| |
| With APC, Moodle will be a lot faster.
| |
| <code bash>
| |
| sudo apt-get install php-apc
| |
| | |
| sudo vim /etc/php5/fpm/php.ini
| |
| </code>
| |
| Add (if not already existing): extension=apc.so
| |
| | |
| == Moodle ==
| |
| [https://docs.moodle.org/en/Installing_Moodle Install Moodle] into /home/nginx/localhost/public/. Note that it is recommended to install Git and to get the Moodle files with Git.
| |
| | |
| Enabling Slash Arguments on Nginx by adding the following line to the "server" section of the Nginx config file:
| |
| rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
| |
| | |
| More info [http://stackoverflow.com/questions/18246845/moodle-2-3-with-nginx-vs-slash-argument-rewrite stackoverflow]
| |
| | |
| Or...
| |
| | |
| In the Moodle administration, disable 'slash arguments' (http://YOURMOODLESITE/admin/search.php?query=slashargument). Without disabling the 'slash arguments', you may notice that the admin setup page is missing the images and css styling. However, if you turn off slash arguments, then other things won't work, so really someone ought to work out what is wrong here and fix it.
| |
| | |
| If you cannot access the Admin interface, you can edit the database using a tool like [http://www.phpmyadmin.net/home_page/index.php phpMyAdmin].
| |
| | |
| 1. Go to the table labeled 'mdl_config'
| |
| | |
| 2. Browse to line 281 (line 309 in 2.5), and change the value of 'slasharguments' from 1 to 0
| |
| | |
| 3. Use Control-F5 to fully refresh the setup page.
| |
| | |
| '''Workaround if the above steps don't work:'''
| |
| | |
| 1. Empty the database and try the [https://docs.moodle.org/en/Administration_via_command_line#Installation_via_command_line command line installation].
| |
| <code bash>
| |
| cd /var/www/YOURMOODLESITE/public/moodle
| |
| | |
| php /admin/cli/install.php
| |
| </code>
| |
| Enabling PHP errors in php.ini will help you diagnose any errors that may arise.
| |
| | |
| Use if you ran the cli install.php as root: chown www-data:www-data config.php
| |
| | |
| 2. Go to your Moodle site and log in. It will ask you to fill in your email address, City and Country. Save the changes.
| |
| | |
| 3. Go to http://YOURMOODLESITE/admin/search.php?query=slashargument and uncheck "Use slash arguments"
| |
| | |
| Note: some version of Internet Explorer will display the page CSS with slash arguments on, while Firefox, Chrome and IE10 will not.
| |
| | |
| == More to do ==
| |
| * Follow the [https://docs.moodle.org/en/Security Moodle security page guidelines]
| |
| * Secure SSH (see this [http://articles.slicehost.com/2009/3/31/debian-lenny-setup-page-1 slicehost debian setup page])
| |
| * Enable SSL (you can use [http://blurringexistence.net/archives/5-nginx-and-StartSSL.html to install a free SSL certificate with startSSL])
| |
| * Setup firewall ([http://ubuntuforums.org/showthread.php?t=159661 ubuntu documentation])
| |
| * Install SMTP server ([https://help.ubuntu.com/community/Postfix Ubuntu documentation with working main.cf], [http://library.linode.com/email/postfix/dovecot-system-users-ubuntu-10.04-lucid Linode documentation], [http://helpdesk.bluehost.com/index.php/kb/article/000294 documentation about MX-record])
| |
| | |
| | |
| There are still a lot more to do (setting up your domain name, establishing a maintenance plan, performance tweaking, security testing...). Be patient and have fun.
| |
| | |
| == Related document ==
| |
| * Nginx/PHP-fpm [http://bestsiteinthemultiverse.com/2011/01/installing-nginx-with-php-fpm-on-ubuntu-10-04/ blog post]
| |
| * Compiling Postgres 9 [http://www.johnwulff.com/2010/05/04/how-to-compile-and-install-postgresql-9-beta-on-ubuntu blog post]
| |