Based on this links:
- https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04
- https://docs.moodle.org/dev/Install_Moodle_On_Ubuntu_with_Nginx/PHP-fpm
$ cd /usr/share/nginx/html/
# git clone --depth=1 -b MOODLE_28_STABLE git://git.moodle.org/moodle.git
sudo apt-get install php5-fpm php5-mysql php5-dg php5-curl
Edit:
sudo nano /etc/php5/fpm/php.ini
Replace ; cgi.fix_pathinfo=1
for cgi.fix_pathinfo=0
sudo nano /etc/php5/fpm/pool.d/www.conf
Replace listen = 127.0.0.1:9000
for listen = /var/run/php5-fpm.sock
Restart PHP-fpm
sudo service php5-fpm restart
sudo nano /etc/nginx/sites-available/default
- Add
index.php
atindex
line inserver {}
. - Pass the PHP scripts to FastCGI server listening on the php-fpm socket
- Add
rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
insideserver
.
Example:
server {
listen 80;
root /usr/share/nginx/www;
rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
index index.php index.html index.htm;
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
}
Create file in public folder.
sudo nano /usr/share/nginx/www/info.php
Add in the following lines:
<?php
phpinfo();
?>
Run these commands with your name and key.
mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO <USER>@localhost IDENTIFIED BY '<PASSWORD>';
Go to http://localhost/moodle
and setup Moodle as usual.
Hey i just changed
rewrite ^/moodle/(..php)(/)(.)$ /moodle/$1?file=/$3 last; to
rewrite ^(..php)(/)(.)$ $1?file=/$3 last;
and it finally works!
Thank you
PS I have no idea why they cannot add this config to the official docs