Thursday, January 5, 2023

How To Install Nginx on Ubuntu 20.04 | DigitOcean

Here is the article. 

By Erin Glass

Introduction

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is a lightweight choice that can be used as either a web server or reverse proxy.

In this guide, we’ll discuss how to install Nginx on your Ubuntu 20.04 server, adjust the firewall, manage the Nginx process, and set up server blocks for hosting more than one domain from a single server.

Prerequisites

Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server. You can learn how to configure a regular user account by following our Initial server setup guide for Ubuntu 20.04.

You will also optionally want to have registered a domain name before completing the last steps of this tutorial. To learn more about setting up a domain name with DigitalOcean, please refer to our Introduction to DigitalOcean DNS.

When you have an account available, log in as your non-root user to begin.

Step 1 – Installing Nginx

Because Nginx is available in Ubuntu’s default repositories, it is possible to install it from these repositories using the apt packaging system.

Since this is our first interaction with the apt packaging system in this session, we will update our local package index so that we have access to the most recent package listings. Afterwards, we can install nginx:

  1. sudo apt update
  2. sudo apt install nginx

After accepting the procedure, apt will install Nginx and any required dependencies to your server.

Step 2 – Adjusting the Firewall

Before testing Nginx, the firewall software needs to be adjusted to allow access to the service. Nginx registers itself as a service with ufw upon installation, making it straightforward to allow Nginx access.

List the application configurations that ufw knows how to work with by typing:

  1. sudo ufw app list

You should get a listing of the application profiles:

Output
Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

As demonstrated by the output, there are three profiles available for Nginx:

  • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
  • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Right now, we will only need to allow traffic on port 80.

You can enable this by typing:

  1. sudo ufw allow 'Nginx HTTP'

You can verify the change by typing:

  1. sudo ufw status

The output will indicated which HTTP traffic is allowed:

Output
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)

Step 3 – Checking your Web Server

At the end of the installation process, Ubuntu 20.04 starts Nginx. The web server should already be up and running.

We can check with the systemd init system to make sure the service is running by typing:

  1. systemctl status nginx
Output
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-04-20 16:08:19 UTC; 3 days ago Docs: man:nginx(8) Main PID: 2369 (nginx) Tasks: 2 (limit: 1153) Memory: 3.5M CGroup: /system.slice/nginx.service ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─2380 nginx: worker process

As confirmed by this out, the service has started successfully. However, the best way to test this is to actually request a page from Nginx.

You can access the default Nginx landing page to confirm that the software is running properly by navigating to your server’s IP address. If you do not know your server’s IP address, you can find it by using the icanhazip.com tool, which will give you your public IP address as received from another location on the internet:

  1. curl -4 icanhazip.com

When you have your server’s IP address, enter it into your browser’s address bar:

http://your_server_ip

You should receive the default Nginx landing page:

Nginx default page

If you are on this page, your server is running correctly and is ready to be managed.

Step 4 – Managing the Nginx Process

Now that you have your web server up and running, let’s review some basic management commands.

To stop your web server, type:

  1. sudo systemctl stop nginx

To start the web server when it is stopped, type:

  1. sudo systemctl start nginx

To stop and then start the service again, type:

  1. sudo systemctl restart nginx

If you are only making configuration changes, Nginx can often reload without dropping connections. To do this, type:

  1. sudo systemctl reload nginx

By default, Nginx is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing:

  1. sudo systemctl disable nginx

To re-enable the service to start up at boot, you can type:

  1. sudo systemctl enable nginx

You have now learned basic management commands and should be ready to configure the site to host more than one domain.

When using the Nginx web server, server blocks (similar to virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called your_domain, but you should replace this with your own domain name.

Nginx on Ubuntu 20.04 has one server block enabled by default that is configured to serve documents out of a directory at /var/www/html. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let’s create a directory structure within /var/www for our your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites.

Create the directory for your_domain as follows, using the -p flag to create any necessary parent directories:

  1. sudo mkdir -p /var/www/your_domain/html

Next, assign ownership of the directory with the $USER environment variable:

  1. sudo chown -R $USER:$USER /var/www/your_domain/html

The permissions of your web roots should be correct if you haven’t modified your umask value, which sets default file permissions. To ensure that your permissions are correct and allow the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, you can input the following command:

  1. sudo chmod -R 755 /var/www/your_domain

Next, create a sample index.html page using nano or your favorite editor:

  1. sudo nano /var/www/your_domain/html/index.html

Inside, add the following sample HTML:

/var/www/your_domain/html/index.html
<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>

Save and close the file by pressing Ctrl+X to exit, then when prompted to save, Y and then Enter.

In order for Nginx to serve this content, it’s necessary to create a server block with the correct directives. Instead of modifying the default configuration file directly, let’s make a new one at /etc/nginx/sites-available/your_domain:

  1. sudo nano /etc/nginx/sites-available/your_domain

Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:

/etc/nginx/sites-available/your_domain
server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

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

Notice that we’ve updated the root configuration to our new directory, and the server_name to our domain name.

Next, let’s enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:

  1. sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Note: Nginx uses a common practice called symbolic links, or symlinks, to track which of your server blocks are enabled. Creating a symlink is like creating a shortcut on disk, so that you could later delete the shortcut from the sites-enabled directory while keeping the server block in sites-available if you wanted to enable it.

Two server blocks are now enabled and configured to respond to requests based on their listen and server_name directives (you can read more about how Nginx processes these directives here):

  • your_domain: Will respond to requests for your_domain and www.your_domain.
  • default: Will respond to any requests on port 80 that do not match the other two blocks.

To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file:

  1. sudo nano /etc/nginx/nginx.conf

Find the server_names_hash_bucket_size directive and remove the # symbol to uncomment the line. If you are using nano, you can quickly search for words in the file by pressing CTRL and w.

Note: Commenting out lines of code – usually by putting # at the start of a line – is another way of disabling them without needing to actually delete them. Many configuration files ship with multiple options commented out so that they can be enabled or disabled, by toggling them between active code and documentation.

/etc/nginx/nginx.conf
...
http {
    ...
    server_names_hash_bucket_size 64;
    ...
}
...

Save and close the file when you are finished.

Next, test to make sure that there are no syntax errors in any of your Nginx files:

  1. sudo nginx -t

If there aren’t any problems, restart Nginx to enable your changes:

  1. sudo systemctl restart nginx

Nginx should now be serving your domain name. You can test this by navigating to http://your_domain, where you should see something like this:

Nginx first server block

Step 6 – Getting Familiar with Important Nginx Files and Directories

Now that you know how to manage the Nginx service itself, you should take a few minutes to familiarize yourself with a few important directories and files.

Content

  • /var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering Nginx configuration files.

Server Configuration

  • /etc/nginx: The Nginx configuration directory. All of the Nginx configuration files reside here.
  • /etc/nginx/nginx.conf: The main Nginx configuration file. This can be modified to make changes to the Nginx global configuration.
  • /etc/nginx/sites-available/: The directory where per-site server blocks can be stored. Nginx will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory.
  • /etc/nginx/sites-enabled/: The directory where enabled per-site server blocks are stored. Typically, these are created by linking to configuration files found in the sites-available directory.
  • /etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the Nginx configuration. Potentially repeatable configuration segments are good candidates for refactoring into snippets.

Server Logs

  • /var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
  • /var/log/nginx/error.log: Any Nginx errors will be recorded in this log.

Conclusion

Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to create a richer experience.

If you’d like to build out a more complete application stack, check out the article How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu 20.04.

In order to set up HTTPS for your domain name with a free SSL certificate using Let’s Encrypt, you should move on to How To Secure Nginx with Let’s Encrypt on Ubuntu 20.04.

Microsoft reportedly to add ChatGPT to Bing search engine

Here is the article. 

Company’s new feature hopes to challenge Google’s search engine

Microsoft is reportedly in the works to launch a version of its search engine Bing using the artificial intelligence behind ChatGPT, launched by OpenAI.

The Information reported the news on Tuesday, citing two people with direct knowledge of the plans.

Microsoft could launch the new feature before the end of March, in the hopes of challenging Google’s search engine, the Information reported.

Microsoft said in a blog post last year that it planned to integrate image-generation software from its image creation software, Dall-E 2, into Bing.

OpenAI and Microsoft declined to comment.

Microsoft had in 2019 backed San Francisco-based artificial intelligence company OpenAI, offering $1bn in funding. The two had formed a multi-year partnership to develop artificial intelligence supercomputing technologies on Microsoft’s Azure cloud computing service.

OpenAI made its latest creation ChatGPT chatbot available for free public testing on 30 November. The chatbot is a software application designed to mimic human-like conversation based on user prompts and can respond to a large range of questions while imitating human speaking styles.

The feature could make Bing more competitive to Google’s search engine at a time when Alphabet, its parent company, has seen advertising revenue growth slow significantly. Advertising is Alphabet’s primary source of revenue, the vast majority of which comes from search ads. Microsoft also saw its search and advertising growth rate slow down in the fourth quarter of the 2022 fiscal year.

OpenAI’s various products such ChatGPT, the natural language system GPT-3 and Dall-E 2 may still need work, but have already been pegged as the industry’s potential next disruptors. The former has reportedly led Google management to declare a “code red”, according to the New York Times, seeing the chat bot – which answers questions or prompts with clear explanations instead of just links – as a major threat to the way consumers currently use search engines.

Google, however, has been hard at work on its own chat bot technology called Language Model for Dialogue Applications – the sophistication of which led one Google engineer to claim it was sentient. He was placed on administrative leave after deciding to go public with his claims.

How to install and use the Redis extension in XAMPP locally in Windows 10

Here is the article. 


Julia installation notes:

  1. Check PHP version: 8.1
  2. Check PHP - thread safety enabled
  3. Go to https://pecl.php.net/package/redis
  4. Go to https://pecl.php.net/package/redis/5.3.7/windows, choose PHP 8.1, TS version, x64
  5. Unzip the file, and then save it on my local xampp php extension folder
  6. Add php.ini with configuration: 
  7. extension=redis
  8. Run http://localhost:8080/dashboard/phpinfo.php
  9. Check redis information
Copy the content from the article. 

Learn how to easily install and use the Redis extension locally in XAMPP to communicate with Redis Servers.

I'm sure you may have already heard about Redis, the in-memory data structure store, used as a database and cache. Sooner or later, if you ever work with a project built with PHP that handles a significant amount of traffic and may require horizontal scaling, you will have to work with Redis. Of course in a local environment, it would be great to work as well with Redis, so you don't have to create huge conditionals to check if it's available in the current environment and run some logic if it isn't. It would be simpler to have Redis available locally as well, just to make the whole project work as usual in your workstation.

In this article, I will explain how to easily install the Redis extension for PHP in your XAMPP installation in Windows.


Pre-installation notes

You need to know the following information about the PHP distribution that you are currently using in XAMPP:

NameDefault value
Architecture (PHP)x64
Thread Safety 

Enabled

TS: Stands for Thread Safety Enabled

NTS: Stands for Thread Safety Disabled

You can get those values with the function phpinfo() of PHP within an empty script:


<?php

phpinfo();

Once you know these values, you should be able to follow the rest of the tutorial.

1. Download Redis DLL

The first thing you need is the dynamic link library of Redis, which fortunately for us is already compiled and available in the PECL repository of PHP on this website. You may select the version that fits your needs, in my case, I will use the latest stable version as I'm using PHP 8, click on the DLL link with the windows icon:

Download Redis DLL PECL

Then a new window will load, in this page scroll to DLL List and click on the right version for your PHP version with correct architecture (of XAMPP, not your operative system) and the Thread Safe in case that it's enabled in your distribution). In my case, I'm using the latest version of XAMPP with PHP 8.0 of 64 bits with Thread Safety Enabled, so in my case, I will download the following one:

Redis DLL Download PHP 8

This will start the download of a ZIP file. Of our interest, is the php_redis.dll file that is included in it, so keep it at hand as you will need the file in the next step.

2. Store DLL in ext directory and enable the extension in php.ini

Now, from the downloaded zip, move the php_redis.dll file to the ext directory of PHP in your XAMPP directory (C:\xampp\php\ext):

Redis DLL Extension Directory PHP

This will allow us to use the extension in PHP, however, we need to enable it as well. Open the php.ini (C:\xampp\php\php.ini) file and enable the extension adding the following new line under the extensions area:

extension=redis

You won't find the mentioned line in the configuration file, so that's why you need to write it by yourself. Save the changes of the ini file and restart Apache, so the changes will apply once it starts again.

3. Testing if the extension is enabled 

And that's it! After restarting apache and enabling the extension in the php.ini, you should be able to use Redis with PHP. You can easily verify if the extension is enabled either by checking in your phpinfo():

Redis PHP Extension phpinfo

Or alternatively, run some code that uses Redis in case that you have a server running Redis through docker locally or a real Redis server, for example, the following code should succeed and print the username "sdkcarlos":

try {
    // Create a Redis Instance
    $redis = new \Redis();
    
    // Try to connect to a redis server
    // In this case within the host machine and the default port of redis
    $redis->connect('127.0.0.1', 6379);

    // Define some Key
    $redis->set('user', 'sdkcarlos');

    // Obtain value
    $user = $redis->get('user');

    // Should Output: sdkcarlos
    print($user);
} catch (Exception $ex) {
    echo $ex->getMessage();
}

Redis PHP extension for XAMPP - Apache start with error message

The procedure entry point PHP_MD5Init could not be located in the dynamic link library C:\xampp\php\ext\php_redis.dll



Install Redis PHP extension for XAMPP

Here is the article. 

Windows

Download

https://github.com/tporadowski/redis/releases

Tutorial

https://www.c-sharpcorner.com/article/installing-redis-cache-on-windows

Xampp

https://www.phpflow.com/php/how-to-setup-redis-server-and-use-with-php

  • Download php_redis.dll file from PECL libs. Download extension as per your current PHP version.
  • Copy the php_redis.dll and paste to following folder in XAMPP Server extension directory(D:\XAMPP\php\ext).
  • Open the php.ini file and add extension=php_redis.dll line into this file.
  • Restart XAMPP server
  • Open phpinfo() of XAMPP server and search Redis, if found that means you successfully integrated Redis with PHP.


ChatGPT

Welcome to ChatGPT

Log in with your OpenAI account to continue