manual install nginx - lemp

Upload: hans-gianfranco-caballero-maguina

Post on 01-Jun-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Manual Install Nginx - LEMP

    1/18

  • 8/8/2019 Manual Install Nginx - LEMP

    2/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Test nginxOpen up your web browser and navigate to http://ip-address/ or http://localhost/ .You will see a screen something like below.

    Configure NginxOpen the file /etc/nginx/nginx.conf in any editor:

    sudo nano /etc/nginx/nginx.conf

    Set the worker_processes (i.e No. of CPU’s in your system). To see the no. of CPU’s,use the command “lscpu” . In my case it’s “1″. So I set this as ’1′.

    worker_processes 1;

    Restart Nginx service:

    sudo service nginx restart

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/Welcome-to-nginx-Mozilla-Firefox_001.png

  • 8/8/2019 Manual Install Nginx - LEMP

    3/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    The default vhost(server block) is defined in the /etc/nginx/sites-available/default file.

    Open the file /etc/nginx/sites-available/default in any editor.

    sudo nano /etc/nginx/sites-available/default

    Under the Server section, set the server FQDN or IP address as shown below.

    [...]

    server {

    listen 80 default_server;

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

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

    # Make site accessible from http://localhost/

    server_name server.unixmen.local ;

    [...]

    Make sure you’ve added index.php line.

    Here,

    listen 80; – > listen for ipv4 listen [::]:80 default_server ipv6only=on; – > listen for ipv6 root /usr/share/nginx/html; – > document root directory. server_name server.unixmen.local ; – > Server FQDN.

    Now scroll down further and find the section #location ~ \.php$ . Uncomment and modifythe following lines as shown below.

    location ~ \.php$ {

    try_files $uri =404; ---------> Add this line

    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;

  • 8/8/2019 Manual Install Nginx - LEMP

    4/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    fastcgi_index index.php;

    include fastcgi_params;

    }

    Here, I added an extra line ‘try_files $uri =404;’ to prevent zero day exploits.

    Save and exit the file.

    Test nginx configurationTest the nginx configuration for any syntax errors using command:

    sudo nginx -t

    Sample output:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

    nginx: configuration file /etc/nginx/nginx.conf test is successful

    Finally restart nginx service

    sudo service nginx restart

  • 8/8/2019 Manual Install Nginx - LEMP

    5/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Install MySQLMySQL is a relational database management system (RDBMS) that runs as a serverproviding multi-user access to a number of databases, though SQLite probably has moretotal embedded deployments

    sudo apt-get install mysql-server mysql-client

    During installation, you’ll be asked to setup the MySQL root user password. Enter thepassword and click Ok.

    Re-enter the password.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_001.png

  • 8/8/2019 Manual Install Nginx - LEMP

    6/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Now MySQL server has been installed.

    You can verify the MySQL server status using command:

    sudo service mysql status

    Sample output:

    mysql start/running, process 5671

    Note: If you want to use MariaDB instead of MySQL, then follow the below steps.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_0021.png

  • 8/8/2019 Manual Install Nginx - LEMP

    7/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Install MariaDBMariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQLserver that comes rich set of enhancements.

    First you have to remove existing MySQL packages if any. To completely uninstall MySQLwith configuration files, enter the following command:

    sudo apt-get purge mysql*

    Run the following command to remove unwanted packages.

    sudo apt-get autoremove

    Now add MariaDB PPA to install it. Run the following commands to add PPA.

    sudo apt-get install software-properties-common

    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

    sudo add-apt-repository 'deb http://mirrors.scie.in/mariadb/repo/5.5/ubuntu trusty main'

    Update the software sources list and install MariaDB using following commands:

    sudo apt-get update

    sudo apt-get install mariadb-server mariadb-client -y

    During installation you will be asked to set database ‘root’ user p assword.

  • 8/8/2019 Manual Install Nginx - LEMP

    8/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Re-enter

    password:

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_004.pnghttp://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_0031.png

  • 8/8/2019 Manual Install Nginx - LEMP

    9/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Click Yes to migrate to MariaDB. Note that you’ll not be asked this question if you installMariaDB before MySQL.

    You can check the MariaDB version using command:

    sudo mysql -v -u root -p

    Sample output:

    Welcome to the MariaDB monitor. Commands end with ; or \g.

    Your MariaDB connection id is 37

    Server version: 5.5.37-MariaDB-0ubuntu0.14.04.1 (Ubuntu)

    Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_005.png

  • 8/8/2019 Manual Install Nginx - LEMP

    10/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Reading history-file /home/sk/.mysql_history

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]>

    Check if mariadb is running or not, using the following command:

    sudo service mysql status

    Sample output:

    * /usr/bin/mysqladmin Ver 9.0 Distrib 5.5.37-MariaDB, for debian-linux-gnu on i686

    Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

    Server version 5.5.37-MariaDB-0ubuntu0.14.04.1

    Protocol version 10

    Connection Localhost via UNIX socket

    UNIX socket /var/run/mysqld/mysqld.sock

    Uptime: 3 min 34 sec

    Threads: 1 Questions: 568 Slow queries: 0 Opens: 338 Flush tables: 4 Open tables: 22 Queries per second avg: 2.654

  • 8/8/2019 Manual Install Nginx - LEMP

    11/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Install PHPPHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-sourcegeneral purpose scripting language that is especially suited for web development and canbe embedded into HTML.

    Install PHP with following command:

    sudo apt-get install php5 php5-fpm php5-mysql

    Configure PHPOpen php.ini file in any editor:

    sudo nano /etc/php5/fpm/php.ini

    Find the line ‘cgi.fix_pathinfo=1′ , uncomment it and change the value 1 to 0 .

    cgi.fix_pathinfo=0

    Now restart php-fpm service.

    sudo service php5-fpm restart

    Test PHPCreate a sample “testphp.php” file in nginx document root folder.

    sudo nano /usr/share/nginx/html/testphp.php

    Add the following lines in it.

    Save and exit the file.

    Navigate to http://server-ip-address/testphp.php . It will display all the detailsabout php such as version, build date and commands etc.

  • 8/8/2019 Manual Install Nginx - LEMP

    12/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    PHP-FPM listens on the socket /var/run/php5-fpm.sock by default. If you want tomake PHP-FPM use a TCP connection, open the file /etc/php5/fpm/pool.d/www.conf,

    sudo nano /etc/php5/fpm/pool.d/www.conf

    Find the line listen = /var/run/php5-fpm.sock ,

    ;listen = /var/run/php5-fpm.sock

    and modify it to listen = 127.0.0.1:9000 .

    listen = 127.0.0.1:9000

    Save and exit the file. Restart php5-fpm service.

    sudo service php5-fpm restart

    Now open the nginx configuration file:

    sudo nano /etc/nginx/sites-available/default

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/phpinfo-Mozilla-Firefox_006.png

  • 8/8/2019 Manual Install Nginx - LEMP

    13/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Find the line fastcgi_pass unix:/var/run/php5-fpm.sock; and change itto fastcgi_pass 127.0.0.1:9000; as shown below.

    location ~ \.php$ {

    try_files $uri =404;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;

    }

    Save and exit the file. Finally restart nginx service.

    sudo service nginx restart

  • 8/8/2019 Manual Install Nginx - LEMP

    14/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Manage MySQL Databases UsingphpMyAdmin (Optional)phpMyAdmin is a free open-source web interface tool used to manage your MySQLdatabases.

    Install phpMyAdminIt is available in the Official Debian repositories. So install it with command:

    sudo apt-get install phpmyadmin

    Select any webserver. By default, nginx will not be displayed here. So, select apache orlighttpd and let us link phpmyadmin to work with nginx webserver later.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_007.png

  • 8/8/2019 Manual Install Nginx - LEMP

    15/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Select Yes to configure database for phpmyadmin with dbconfig-common .

    Enter password of the database’s administrative user.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_009.pnghttp://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_008.png

  • 8/8/2019 Manual Install Nginx - LEMP

    16/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    Enter MySQL application password phpmyadmin.

    Re-enter the password.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_011.pnghttp://180016988.r.cdn77.net/wp-content/uploads/2014/06/sk@server-_010.png

  • 8/8/2019 Manual Install Nginx - LEMP

    17/18

    Instituto Científico del Pacifico

    Hans Caballero Maguiña – Área de Sistemas

    The phpMyAdmin installation has been completed.

    Create a symbolic link between phpMyAdmin and the website root directory. Here ourwebsite root document directory is /usr/share/nginx/html/ .

    sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html

    Restart nginx server.

    sudo service nginx restart

    Access phpMyAdmin Web ConsoleNow you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.

    Enter your MySQL username and password which you have given in previous steps. Inmy case its “root” and “ubuntu”.

    You will be redirected to PhpMyAdmin main web interface.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/phpMyAdmin-Mozilla-Firefox_012.png

  • 8/8/2019 Manual Install Nginx - LEMP

    18/18

    Instituto Científico del Pacifico

    H C b ll M iñ Á d Si

    Now you can manage your MySQL databases from phpMyAdmin web interface.

    That’s it. Your LEMP server is up and running now.

    http://180016988.r.cdn77.net/wp-content/uploads/2014/06/192.168.1.250-localhost-phpMyAdmin-4.0.10deb1-Mozilla-Firefox_013.png