Difference between revisions of "Installing Nginx, MySQL & PHP5 (PHP5-FPM) on Ubuntu 12.04 LTS"

From Zam Wiki

 
Line 30: Line 30:
 
  vi /etc/nginx/sites-available/default
 
  vi /etc/nginx/sites-available/default
  
<syntaxhighlight lang=text>
 
 
  [...]
 
  [...]
 
     server {
 
     server {
             listen   80; ## listen for ipv4; this line is default and implied
+
             listen 80;
             listen   [::]:80 default ipv6only=on; ## listen for ipv6 if any
+
             #listen [::]:80 default ipv6only=on;
 
+
 
             root /usr/share/nginx/www; # you can change to any path you want
 
             root /usr/share/nginx/www; # you can change to any path you want
 
             index index.php index.html index.htm;
 
             index index.php index.html index.htm;
 
+
            # Make site accessible from http://localhost/
 
 
             server_name _;
 
             server_name _;
 
+
 
             location / {
 
             location / {
                    # First attempt to serve request as file, then
 
                    # as directory, then fall back to index.html
 
 
                     try_files $uri $uri/ /index.html;
 
                     try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
 
                    # include /etc/nginx/naxsi.rules
 
 
             }
 
             }
 
+
 
             location /doc/ {
 
             location /doc/ {
 
                     alias /usr/share/doc/;
 
                     alias /usr/share/doc/;
Line 56: Line 50:
 
                     deny all;
 
                     deny all;
 
             }
 
             }
 
+
            # Only for nginx-naxsi : process denied requests
 
            #location /RequestDenied {
 
                    # For example, return an error code
 
                    #return 418;
 
            #}
 
 
 
            #error_page 404 /404.html;
 
 
 
            # redirect server error pages to the static page /50x.html
 
            #
 
 
             error_page 500 502 503 504 /50x.html;
 
             error_page 500 502 503 504 /50x.html;
 
             location = /50x.html {
 
             location = /50x.html {
 
                     root /usr/share/nginx/www;
 
                     root /usr/share/nginx/www;
 
             }
 
             }
 
+
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 
            #
 
 
             location ~ \.php$ {
 
             location ~ \.php$ {
 
                     try_files $uri =404;
 
                     try_files $uri =404;
 
                     fastcgi_split_path_info ^(.+\.php)(/.+)$;
 
                     fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    #fastcgi_pass fastcgi_pass 127.0.0.1:9000;
 
 
                     fastcgi_pass unix:/tmp/php5-fpm.sock;
 
                     fastcgi_pass unix:/tmp/php5-fpm.sock;
 
                     fastcgi_index index.php;
 
                     fastcgi_index index.php;
 
                     include fastcgi_params;
 
                     include fastcgi_params;
 
             }
 
             }
 
+
            # deny access to .htaccess files, if Apache's document root
 
            # concurs with nginx's one
 
            #
 
 
             location ~ /\.ht {
 
             location ~ /\.ht {
 
                     deny all;
 
                     deny all;
Line 91: Line 69:
 
     }
 
     }
 
  [...]
 
  [...]
</syntaxhighlight>
 
  
 
7. Reload the config file
 
7. Reload the config file
Line 97: Line 74:
  
 
8. Install nessary file
 
8. Install nessary file
<syntaxhighlight lang=text>
 
 
  apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache
 
  apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache
</syntaxhighlight>
 
  
 
9. Now reload PHP-FPM:
 
9. Now reload PHP-FPM:

Latest revision as of 17:41, 24 March 2015

Installing Nginx, MySQL & PHP5 (And PHP5-FPM) a.k.a (LEMP) On Ubuntu 12.04 LTS

1. Update & upgrade your OS first;

apt-get update
apt-get upgrade

2. Install Myssql & PHP5-FPM;

apt-get install mysql-server mysql-client php5-fpm

3. Install Nginx webserver

apt-get install nginx

4. Start your Nginx!

/etc/init.d/nginx start

Try access your web via localhost or via ip e.g. 127.0.0.1, 192.168.1.1

5. Edit nginx config file;

vi /etc/nginx/nginx.conf

Adjust worker proc & keepalive accordingly;

[...]
    worker_processes   4;
[...]
    keepalive_timeout   2;
[...]

6. Edit the virtual host config;

vi /etc/nginx/sites-available/default
[...]
   server {
           listen 80;
           #listen [::]:80 default ipv6only=on;

           root /usr/share/nginx/www; # you can change to any path you want
           index index.php index.html index.htm;

           server_name _;

           location / {
                   try_files $uri $uri/ /index.html;
           }

           location /doc/ {
                   alias /usr/share/doc/;
                   autoindex on;
                   allow 127.0.0.1;
                   deny all;
           }

           error_page 500 502 503 504 /50x.html;
           location = /50x.html {
                   root /usr/share/nginx/www;
           }

           location ~ \.php$ {
                   try_files $uri =404;
                   fastcgi_split_path_info ^(.+\.php)(/.+)$;
                   fastcgi_pass unix:/tmp/php5-fpm.sock;
                   fastcgi_index index.php;
                   include fastcgi_params;
           }

           location ~ /\.ht {
                   deny all;
           }
   }
[...]

7. Reload the config file

/etc/init.d/nginx reload

8. Install nessary file

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache

9. Now reload PHP-FPM:

/etc/init.d/php5-fpm reload

10. Test your nginx;

vi /usr/share/nginx/www/info.php

Paste this line below;

<?php
      phpinfo();
?>

11. Try access that file via web browser

http://100.100.100.100/info.php

It will show info included module

Making PHP-FPM Use A Unix Socket By default PHP-FPM is listening on port 9000 on 127.0.0.1. It is also possible to make PHP-FPM use a Unix socket which avoids the TCP overhead. To do this, open /etc/php5/fpm/pool.d/www.conf.

12. Edit file

vi /etc/php5/fpm/pool.d/www.conf

... and make the listen line look as follows:

[...]
;listen = 127.0.0.1:9000
listen = /tmp/php5-fpm.sock
[...]

13. Then reload PHP-FPM:

/etc/init.d/php5-fpm reload

blog comments powered by Disqus