Saturday, April 27, 2013

Installing Nginx and PHP on Linux Mint 13...

Step 1:
- Installing Nginx web/proxy server
$ sudo add-apt-repository ppa:nginx/$nginx
$ sudo apt-get update 
$ sudo apt-get install nginx
- Start the service
$ sudo service nginx start
- Then test the installation by opening web browser and type your ip address or localhost to the url text box. You should see a welcoming page.

Step 2:
- Installing PHP
$ sudo add-apt-repository ppa:ondrej/php5
$ sudo apt-get update
$ sudo apt-get install php5-fpm php5.cli
- Edit ini file
$ sudo nano /etc/php5/fpm/php.ini
- Change the cgi.fix_pathinfo=1 to cgi.fix_pathinfo=0

- Edit config file
$ sudo gedit /etc/nginx/sites-available/default 
- Uncomment highlighted lines below
server {
        listen 80;
        listen [::]:80 ipv6only=on default_server;

        root /usr/share/nginx/html;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
        }

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

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #   proxy_pass http://127.0.0.1:8080;    
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #    root /usr/share/nginx/html;
        #}

        # 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-cgi alone:
        #   fastcgi_pass 127.0.0.1:9000;
        #   # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny all;
        }
    }
- Start PHP service
$ sudo service php5-fpm start
- Restart Nginx service
$ sudo service nginx restart
- Test your installation by creating info.php file with source code below into your webserver root directory
<php?
    phpinfo();
?>
Step 3: Installing xdebug (optional)
$ sudo apt-get install php5-xdebug
- Get Loaded Configuration File (from your browser by opening info.php you've created earlier) and add the text below to php.ini
zend_extension=/usr/lib/php5/20100525/xdebug.so
xdebug.remote_enable=on
- Restart PHP and Nginx service

Important notes:
- To completely uninstall Nginx (including settings)
$ sudo apt-get purge nginx nginx-common nginx-full
- If you're getting the error below when you start Nginx service
$ nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
- Edit /etc/nginx/sites-available/default file by changing the text
from
listen [::]:80 default_server;

to
listen [::]:80 ipv6only=on default_server;

No comments:

Post a Comment