Friday, 4 November 2016

How To Install Linux, nginx, MySQL, PHP (LEMP) stack

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04

1. Install the Nginx Web Server
apt-get install nginx
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'     check private IP
curl http://icanhazip.com      check public IP
http://server_domain_name_or_IP         
It should take you to Nginx's default landing page.

2. Install MySQL to Manage Site Data
apt-get install mysql-server
mysql_install_db    
#tell MySQL to generate the directory structure it needs to store its databases and information.
mysql_secure_installation
#Next, it will ask if you want to change that password. 
#If you are happy with your MySQL root password, type "N" for no and hit "ENTER". 
#Afterwards, you will be prompted to remove some test users and databases. 
#You should just hit "ENTER" through these prompts to remove the unsafe default settings.

3. Install PHP for Processing
apt-get install php5-fpm php5-mysql
Configure the PHP Processor:
vim /etc/php5/fpm/php.ini
service php5-fpm restart

4. Configure Nginx to Use our PHP Processor
vim /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;   #ipv6only=on;
## 
if got configure ipv6

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

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

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

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

service nginx restart

5. Create a PHP File to Test Configuration
vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
http://server_domain_name_or_IP/info.php
# rm /usr/share/nginx/html/info.php