Home » Articles posted by Expert (Page 4)

Author Archives: Expert

How to Install Apache with PHP-FPM in Ubuntu 20.04 / 18.04

Install Apache with PHP-FPM on Ubuntu 20

PHP FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI. It provides some additional features like Adaptive process spawning which is useful for sites. This tutorial will help you to install Apache with PHP-FPM/FastCGI on Ubuntu 20.04 system. In this tutorial, we are using PHP 7.4 and configure with Apache using PHP-FPM and FastCGI.

Step 1 – Installing Apache

Apache web server debian packages are available under the default repositories. Login to your Ubuntu system with sudo privileges account. Open a terminal. And run the following commands in it :

sudo apt update 
sudo apt install apache2 libapache2-mod-fcgid

The above commands will install Apache and FastCGI module to your server.

Step 2 – Install PHP with FPM

Next, install PHP and PHP-FPM on your Ubuntu system. For this tutorial, we choose PHP 7.4 to install using

For the PHP installation we recommend to use ppa:ondrej/php PPA. Execute below couple of commands to add the PPA to your system.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then install PHP 7.4 (or required version) the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages.

sudo apt update
sudo apt install php7.4 php7.4-fpm
Note:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.4/fpm directory. You can read more about enable/disable PHP modules.

After installing the packages php7.4-fpm service will automatically be started. To make sure, type:

sudo systemctl status php7.4-fpm

● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-05-09 04:41:44 UTC; 19s ago
       Docs: man:php-fpm7.4(8)
    Process: 375077 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited>
   Main PID: 375073 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2283)
     Memory: 9.3M
     CGroup: /system.slice/php7.4-fpm.service
             ├─375073 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─375075 php-fpm: pool www
             └─375076 php-fpm: pool www

May 09 04:41:43 tecadmin systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
May 09 04:41:44 tecadmin systemd[1]: Started The PHP 7.4 FastCGI Process Manager.

Step 3 – Apache Configuration

Now, You need to enable some of the Apache modules required for the FastCGI confiugration. You can enable the requird module by running command:

sudo a2enmod actions fcgid alias proxy_fcgi

Then configure Apache Virtual Host to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in a text editor. You can also create a new configuration as per your choice.

sudo vim /etc/apache2/sites-available/000-default.conf

Update the configuration as followings.

 

 

Save your changes to the configuration file and restart Apache to reload the changes.

sudo systemctl restart apache2

Step 4 – Verify Setup

Apache with PHP-FPM configuration has been done. Now all the PHP files will be run with the FPM.

To verify these settigns, create a PHP script with phpinfo() function and place it to your server document root. Use below command to create file:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Then access the info.php using server IP address (for default VirtualHost) or your configured domain in Apache VirtualHost.

How to paste Fastag sticker on car windshield

Where to affix FASTag on car

Steps to paste Fastag sticker on windshield

This guide explains How to paste fastag sticker on windshield of your car.

How to paste/affix Fastag on car windshield : Fastag Installation Guide

FASTag is a device that employs Radio Frequency Identification (RFID) technology for making toll payments directly while the vehicle is in motion. FASTag (RFID Tag) is affixed on the windscreen of the vehicle and enables a customer to make the toll payments directly from the account which is linked to FASTag.

Where do you stick the FASTag sticker for toll payment : steps

  • Remove the adhesive lining from the FASTag sticker
  • Paste the FASTag on the top middle of the windshield from inside the vehicle or behind the rear view mirror
  • Gently press the sticker on the windshield
  • Keep the adhesive side of the FASTag sticker facing outside
  • Do not try to remove or reposition the FASTag sticker once pasted

Things that need to be taken care of while installing Fastag :

  • Do not paste the FASTag on a dirty or wet glass surface
  • If the original adhesive is insufficient, then return the FASTag and get it replaced
  • Do not use cello tape or any other adhesive to affix the FASTag
  • Do not try to peel off or reposition the FASTag

 

Also read :

How to Check Fastag Balance : Steps

How to fix the 500 Internal Server Error in wordpress

Fix 500 internal server error wordpress

Internal server errors in WordPress are the worst (aka. http error 500), compared to other HTTP error codes and status codes.

The WordPress websites often encounters an error called 500 internal server error in wordpress. There are several potential causes.

Causes:

  • Exhausted PHP memory limit
  • Corrupted plugin functions
  • Corrupted theme functions
  • Corrupted .htaccess

What Is the 500 Internal Server Error?

A fairly general HTTP status code, the 500 Internal Server Error indicates that something unexpected has happened on your website’s server. If you see this error message, there’s no need to panic. The problem, whatever it may be, is with your website’s servers, not your computer.

Here’s the catch though, the server can’t tell you what the exact problem is. It only shows the response code 500.

Solutions to 500 Internal Server Error

Solution #1. Increase the memory limit

Follow the same steps to increase the memory limit as mentioned in the previous step. The steps to increase memory limit can be found at HowToFix Blog.

Solution #2. Edit .htaccess file

Edit your .htaccess file, if a corrupted .htaccess file caused this problem. Open your .htaccess file from the FTP or file manager and rename it with .htaccess old. Refresh your website and see if the problem persists. If this fixes the problem, click on settings > permalinks and hit save changes to reset .htaccess.

Solution #3. Deactivate all the plugins

If changing your .htaccess file did not have any impact on the problem, you might want to check your plugins. Deactivate all your plugins by clicking on plugins ? installed plugins. Choose “deactivate” from the “bulk action” drop down and hit apply. It will automatically deactivate all your plugins. Now go to your website, refresh it and check if the error is gone. If so, activate your plugins one by one and see which plugin has caused the problem.

Solution #4. Replace wp-admin and wp-includes folders

If nothing worked, try replacing your wp-includes and wp-admin folders with fresh copies from a WordPress install. Save them and upload. Refresh the browser and see if the problem is resolved.

Naming Variants for 500 Internal Server Errors

There are actually quite a few names or phrases that can indicate you’re dealing with a 500 internal server error. Depending on your web server or the particular problem, you could receive any of the following variants:

  • 500 Internal Server Error
  • Internal Server Error
  • Error 500
  • HTTP Error 500
  • HTTP Error 500 – Internal Server Error
  • Temporary Error (500)

WordPress PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file ‘/{plugin..}.tmp’ : error

How to fix PCLZIP_ERR_MISSING_FILE (-4) Missing file ‘/{somefile.tmp}’ error when updating plugin in WordPress 

This solution is based on this WordPress.org thread.

Problem :
When you try to update WordPress or install plugins, the downloader / installer page pops up, the compressed file is downloaded to your server, but installation fails because of this error: PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file ‘C:\Windows\TEMP/{whatever you were installing}.tmp’

Solution :
You need to access the files on your server via FTP. If you haven’t done this before, there are tutorials out there.
Short version: find the FTP access details for your server, and grab FileZilla FTP Client. Or if your hosting provides a File Manager utility, use that.
On your server, navigate to the /wp-content folder.
Create a new folder inside it called TEMP.
Download /wp-config.php from your server to your computer.
Open it up in a text editor, and beneath
if ( !defined(‘ABSPATH’) ) define(‘ABSPATH’, dirname(__FILE__) . ‘/’);
add the line
define(‘WP_TEMP_DIR’, ABSPATH . ‘wp-content/TEMP’);
then save wp-config.php.
Upload it to your server again.
Try updating WordPress or installing a plugin. It should work now.

The other solution is not to use Windows hosting!

For more details, see HowToFix blog

Also read : How to fix the 500 Internal Server Error in wordpress

How to stop spreading corona virus into your home : COVID Care & Precaution guide

Corona virus (COVID-19): Home Care & Precautions guide

Doctors might recommend home care if someone in your family:

  • has coronavirus (COVID-19)
  • was tested for COVID-19 and is waiting for the results
  • has flu symptoms (like a fever, cough, and sore throat)

Anyone who is sick — even if they don’t know for sure they have coronavirus (COVID-19) — should stay home unless they need medical care. This helps prevent the illness from spreading to other people.

What Should We Do at Home to prevent corona virus spread ?

To protect others at home, someone who is sick should:

  • As much as possible, keep away from other people and pets in your home.
  • Wear a cloth face covering (or face mask, if you have one) if they must be around other people. Cloth face coverings are for use only by people older than 2 years old who are not having trouble breathing. Do not leave a child alone while they’re wearing a cloth face covering. To see how to put on and remove cloth face coverings and face masks, clean them, or make your own cloth face covering, check the CDC’s guide.
  • Cover coughs and sneezes with a tissue, throw the tissue away, and then wash their hands right away. Wash with soap and water for at least 20 seconds, or use alcohol-based hand sanitizer.
  • If possible, stay in a bedroom and use a bathroom separate from other people in the home.
  • Use separate dishes, glasses, cups, and eating utensils and not share these with other household members. After use, run them through the dishwasher or wash with very hot soapy water.
  • Use separate bedding and towels and not share these with other household members.

Also:

  • If the person who is sick can’t wear a cloth face covering (or face mask), caregivers should wear one while they’re in the same room.
  • Make sure shared spaces in the home have good air flow. You can open a window or turn on an air filter or air conditioner.
  • Do not allow visitors into your home. This includes children and adults.
  • All household members should wash their hands well and often. Wash with soap and water for at least 20 seconds, or use alcohol-based hand sanitizer.
  • Wash the sick person’s clothing, bedding, and towels with detergent on the hottest temperature possible. Wear gloves when handling their laundry, if possible. Wash your hands well after handling the laundry (even if you wore gloves).
  • Every day, use a household cleaner or wipe to clean things that get touched a lot. These include doorknobs, light switches, toys, remote controls, sink handles, counters, and phones. Keep a sick child’s toys separate from other toys, if possible.

To protect others in your community:

  • The person who is sick should stay home unless they need medical care.
  • Other household members also should stay home. Follow instructions from your doctor, local health care department, or the Centers for Disease Control and Prevention (CDC) about who should stay home and for how long.
  • If you must go out of the house, wear a cloth face covering or face mask and keep at least 6 feet (2 meters) of distance between you and other people.
  • Tell other people who were around the sick person. Your local or state health department can help you if you aren’t sure who to notify.

When Should I Call the Doctor?

If the person you’re caring for seems to be getting sicker, call your doctor right away. Tell the doctor about their symptoms and whether they’ve been tested for coronavirus (COVID-19).

If they need to go to the doctor:

  • The person should wear a cloth face covering, if available.
  • Keep tissues handy in case they need to cough or sneeze.

Go to the emergency room or call 911 if the person has trouble breathing, is confused, or is very drowsy.

What Else Should I Know?

If you’re caring for someone with coronavirus or who has coronavirus symptoms, keep taking these precautions until your doctor or local health department say it’s safe to stop doing so.

It can get pretty lonely and boring for kids who are sick and need to stay home. While they’re separated from family, classmates, and friends, kids who feel well enough may want to:

  • Talk on the phone or do a video call with family and friends.
  • Text or use other messaging apps to talk with family and friends.
  • Play online games that let them play with other kids from home.
  • Do puzzles or Legos. Keep these clean and keep separate from other toys in the house.

Clean items used by the sick person (such as phones and computers) before other family members use them.

Check the CDC and World Health Organization (WHO) websites for up-to-date, reliable information about coronavirus.

Also read : How to measure oxygen level with oximeter at home

How to fix/solve Error 403 The user has exceeded their google drive storage quota

How to fix error 403 google drive quota exceeded

One of the great things about Google Drive is that you can download, share, and collaborate on files with many people. However, once those teams get large or you’re trying to upload big files, you can run into usage limits. Those usage limits can lead to the error that your “Download quota is exceeded”.

There are a few workarounds to avoid this error, which we’ll cover in this article.

How to fix error : Google Drive storage quota has been exceeded

You can still download the file without triggering the “Download quota is exceeded” error. It just requires some extra steps to change the Google Drive account you’re downloading it from to your own.

To do this, you’ll need to save a copy to your Google Drive account first.

1. Make sure you’re already signed into your Google Drive account.

2. Select the link to the shared Google Drive file that you want to download.

3. Save a copy of the file in a Google Drive folder you prefer by selecting File > Make a copy.

4. Browse to the folder where you want to save the copy and select it. Select the Select button to choose it. Then select OK to finish.

This moves the file from the original account it was shared from into your own Google Drive account. Since your Google Drive account is also on Google’s servers, this isn’t technically a file download.

Now that a copy of the original file is on your account, and no one else is downloading it, you can go ahead and download it now to your local computer without any download quota limitations.

userRateLimitExceeded error indicates that the per-user limit has been reached. This limit might be the limit from the API console or a limit from the Drive backend. Following is the JSON representation of this error:

{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "userRateLimitExceeded",
"message": "User Rate Limit Exceeded"
}
],
"code": 403,
"message": "User Rate Limit Exceeded"
}
}

To fix this error, try any of the following:

How to Fix “Download quota is exceeded” Error if You’re the Owner

If you’re the one hosting the shared file to many people on your Google Drive account, the fix for this error is a bit different.

To do this, just right click on the original file and select Make a copy.

google drive file copy

You’ll see a new file appear with “A copy of” in front of the original filename.

The file will be shared with the same people as the original file that got blocked. However, since too many people were downloading the old file, it may be worthwhile limiting how many people can download the copy.

To do this, right-click the file and select Share.

If you’ve provided access to this file to anyone on the internet with the link, it may be worthwhile change this to Restricted instead.

In the Get link section, select Change.

Use the dropdown to change this setting to Restricted.

This means that only people you’ve shared the file with are able to open or download it. Just right-click the file, select Share, and add all the emails or groups that you want to provide access.

This way you can ensure that there aren’t too many people downloading the file and putting your Google Drive account at risk from a ban from Google.

How to get a lost or stuck contact lens out of your eye

How to get a lost or stuck contact lens out of your eyeHow to get contacts from behind eye

Getting a contact lens stuck in your eye happens occasionally and can be uncomfortable and irritating. Here are some quick and easy solutions to get a lost or stuck contact lens out of your eye.

With a little bit of practice, you’ll be able to do it smoothly with no trouble. Here are some common questions regarding getting a lens stuck in your eye and how to deal with it.

Also read : How to Get Rid of Dark Spots on Face

Why is my contact lens stuck in my eye?

If you have slept in your lenses or aren’t taking good care of them, the contacts are prone to drying out, leaving the lens stuck to your eyeball. If you fall asleep in your lenses, avoid pulling the lens out right away. Drink a bit of water, rehydrate yourself and let your eye gain a bit of moisture. This will make a contact stuck in eye easier to remove.

 

What happens if contacts get stuck in eye?

The most common misconceptions about contact lenses are that they can get stuck behind your eye. A contact getting stuck behind the eye is not physically possible; your eyelid is structured to prevent any objects from going to the back of your eye.

A contact lens that gets stuck in the eye is usually a soft contact lens rather than a gas permeable lens. However it is possible for both to get stuck and its wise to be aware that removing a soft contact lens is very different to removing a rigid gas permeable lens.

 

How do I remove a lens that’s stuck in my eye?

The first rule about how to remove a contact lens that’s stuck in your eye is not to panic; trying to pry the lens out may cause more discomfort. Wash your hands before attempting to remove the lens, to avoid getting any bacteria from your hands going in your eye and causing an infection.

 

Removing a soft contact lens from your eye

Always make sure you wash your hands thoroughly before attempting to remove a stuck contact lens. If the stuck contact lens is centered on your cornea, you can rinse your eye and the contact that’s stuck with sterile saline or contact lens rewetting drops such as our comfi Drops. Once you have applied the saline solution or eye drops, close your eye and gently massage your eyelid until the lens moves.

On the other hand, if your eyes are watering heavily, that can also make getting lenses out slightly difficult. Gently wipe your tears away, then, as always, before removing your lenses wash your hands thoroughly. Ensure your fingers are completely dry and this will make removing a stuck lens a little easier.

 

Removing a stuck gas permeable contact lens from your eye

If you are wearing gas permeable lenses and they get stuck in your eye, you must avoid massaging your eyelid as this can cause abrasion to the eye. Instead, it is recommended that you use a suction cup to pull the lens of your eye gently .

 

Can my contact lens get lost in my eye?

If you think the contact lens is lost in your eye, it’s probably hiding under your upper eyelid. Simply pull it back slightly to have look and use contact lens solution to flush it out.

 

What to do if you can’t remove a stuck contact lens

If the lens remains after following the above steps, we advise you to seek medical advice from a doctor or an eye specialist. This should be done as soon as possible to prevent any further problems from occurring.

 

Top tips to prevent contacts getting lost or stuck in your eye

Unless it is an extended wear lens, never sleep in your contact lenses – this can limit the oxygen flow to your cornea and dry out your eyes. In addition, you also risk infection.

Always clean your lenses before putting them in and taking them out. Follow a good eye care and contact lens cleaning routine if your wear monthlies or two weekly’s. Make sure you use fresh contact lens solution to prevent the spread of bacteria.

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

Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu

LEMP installation : Ubuntu 20.04

This guide demonstrates how to install a LEMP stack on an Ubuntu 20.04 server. The Ubuntu operating system takes care of the first requirement. We will describe how to get the rest of the components up and running.

What is LEMP ?

The LEMP software stack serves dynamic web pages and web applications written in PHP. This is an acronym that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) web server. The MySQL database  stores backend data and PHP handles the dynamic processing.

Prerequisites

In order to complete this tutorial, you will need access to an Ubuntu 20.04 server as a regular, non-root sudo user, and a firewall enabled on your server. To set this up, you can follow our initial server setup guide for Ubuntu 20.04.

Step 1 – Installing the Nginx Web Server

In order to display web pages to our site visitors, we are going to employ Nginx, a high-performance web server. We’ll use the apt package manager to obtain this software.

Since this is our first time using apt for this session, start off by updating your server’s package index. Following that, you can use apt install to get Nginx installed:

  • sudo apt update
  • sudo apt install nginx

When prompted, enter Y to confirm that you want to install Nginx. The Nginx web server will be active and running on your Ubuntu 20.04 server, after the installation is complete.

If you have the ufw firewall enabled, as recommended in our initial server setup guide, you will need to allow connections to Nginx. Nginx registers a few different UFW application profiles upon installation. To check which UFW profiles are available, run:

  • sudo ufw app list
Output
Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH

You should enable the most restrictive profile. It will still allow the traffic you need. Since you haven’t configured SSL for your server in this guide, you will only need to allow regular HTTP traffic on port 80.

Enable this by typing:

  • sudo ufw allow ‘Nginx HTTP’

You can verify the change by running:

  • sudo ufw status

This command’s output will show that HTTP traffic is now 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)

With the new firewall rule added, you can test if the server is up and running by accessing your server’s domain name or public IP address in your web browser.

If you do not have a domain name pointed at your server and you do not know your server’s public IP address, you can find it by running the following command:

  • ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’

This will print out a few IP addresses. You can try each of them in turn in your web browser.

As an alternative, you can check which IP address is accessible, as viewed from other locations on the internet:

  • curl -4 icanhazip.com

Type the address that you receive in your web browser and it will take you to Nginx’s default landing page:

http://server_domain_or_IP

Nginx default page

If you see this page, it means you have successfully installed Nginx and enabled HTTP traffic for your web server.

Step 2 — Installing MySQL

Now that you have a web server up and running, you need to install the database system to be able to store and manage data for your site. MySQL is a popular database management system used within PHP environments.

Again, use apt to acquire and install this software:

  • sudo apt install mysql-server

When prompted, confirm installation by typing Y, and then ENTER.

When the installation is finished, it’s recommended that you run a security script that comes pre-installed with MySQL. This script will remove some insecure default settings and lock down access to your database system. Start the interactive script by running:

  • sudo mysql_secure_installation

This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.

Note: Enabling this feature is something of a judgment call. If enabled, passwords which don’t match the specified criteria will be rejected by MySQL with an error. It is safe to leave validation disabled, but you should always use strong, unique passwords for database credentials.

Answer Y for yes, or anything else to continue without enabling.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

If you answer “yes”, you’ll be asked to select a level of password validation. Keep in mind that if you enter 2 for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary              file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Regardless of whether you chose to set up the VALIDATE PASSWORD PLUGIN, your server will next ask you to select and confirm a password for the MySQL root user. This is not to be confused with the system root. The database root user is an administrative user with full privileges over the database system. Even though the default authentication method for the MySQL root user dispenses the use of a password, even when one is set, you should define a strong password here as an additional safety measure. We’ll talk about this in a moment.

If you enabled password validation, you’ll be shown the password strength for the root password you just entered and your server will ask if you want to continue with that password. If you are happy with your current password, enter Y for “yes” at the prompt:

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

For the rest of the questions, press Y and hit the ENTER key at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

When you’re finished, test if you’re able to log in to the MySQL console by typing:

  • sudo mysql

This will connect to the MySQL server as the administrative database user root, which is inferred by the use of sudo when running this command. You should see output like this:

Output
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.19-0ubuntu5 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

To exit the MySQL console, type:

  • exit

Notice that you didn’t need to provide a password to connect as the root user, even though you have defined one when running the mysql_secure_installation script. That is because the default authentication method for the administrative MySQL user is unix_socket instead of password. Even though this might look like a security concern at first, it makes the database server more secure because the only users allowed to log in as the root MySQL user are the system users with sudo privileges connecting from the console or through an application running with the same privileges. In practical terms, that means you won’t be able to use the administrative database root user to connect from your PHP application. Setting a password for the root MySQL account works as a safeguard, in case the default authentication method is changed from unix_socket to password.

For increased security, it’s best to have dedicated user accounts with less expansive privileges set up for every database, especially if you plan on having multiple databases hosted on your server.

Note: At the time of this writing, the native MySQL PHP library mysqlnd doesn’t support caching_sha2_authentication, the default authentication method for MySQL 8. For that reason, when creating database users for PHP applications on MySQL 8, you’ll need to make sure they’re configured to use mysql_native_password instead. We’ll demonstrate how to do that in Step 6.

Your MySQL server is now installed and secured. Next, we’ll install PHP, the final component in the LEMP stack.

Step 3 – Installing PHP

You have Nginx installed to serve your content and MySQL installed to store and manage your data. Now you can install PHP to process code and generate dynamic content for the web server.

While Apache embeds the PHP interpreter in each request, Nginx requires an external program to handle PHP processing and act as a bridge between the PHP interpreter itself and the web server. This allows for a better overall performance in most PHP-based websites, but it requires additional configuration. You’ll need to install php-fpm, which stands for “PHP fastCGI process manager”, and tell Nginx to pass PHP requests to this software for processing. Additionally, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. Core PHP packages will automatically be installed as dependencies.

To install the php-fpm and php-mysql packages, run:

  • sudo apt install php-fpm php-mysql

When prompted, type Y and ENTER to confirm installation.

You now have your PHP components installed. Next, you’ll configure Nginx to use them.

Step 4 — Configuring Nginx to Use the PHP Processor

When using the Nginx web server, we can create server blocks (similar to virtual hosts in Apache) to encapsulate configuration details and host more than one domain on a single server. In this guide, we’ll use your_domain as an example domain name. To learn more about setting up a domain name with DigitalOcean, see our introduction to DigitalOcean DNS.

On Ubuntu 20.04, Nginx has one server block enabled by default and is configured to serve documents out of a directory at /var/www/html. While this works well for a single site, it can become difficult to manage if you are hosting multiple sites. Instead of modifying /var/www/html, we’ll create a directory structure within /var/www for the your_domain website, 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 root web directory for your_domain as follows:

  • sudo mkdir /var/www/your_domain

Next, assign ownership of the directory with the $USER environment variable, which will reference your current system user:

  • sudo chown -R $USER:$USER /var/www/your_domain

Then, open a new configuration file in Nginx’s sites-available directory using your preferred command-line editor. Here, we’ll use nano:

  • sudo nano /etc/nginx/sites-available/your_domain

This will create a new blank file. Paste in the following bare-bones configuration:

/etc/nginx/sites-available/your_domain
server {
    listen 80;
    server_name your_domain www.your_domain;
    root /var/www/your_domain;

    index index.html index.htm index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

Here’s what each of these directives and location blocks do:

  • listen — Defines what port Nginx will listen on. In this case, it will listen on port 80, the default port for HTTP.
  • root — Defines the document root where the files served by this website are stored.
  • index — Defines in which order Nginx will prioritize index files for this website. It is a common practice to list index.html files with a higher precedence than index.php files to allow for quickly setting up a maintenance landing page in PHP applications. You can adjust these settings to better suit your application needs.
  • server_name — Defines which domain names and/or IP addresses this server block should respond for. Point this directive to your server’s domain name or public IP address.
  • location / — The first location block includes a try_files directive, which checks for the existence of files or directories matching a URI request. If Nginx cannot find the appropriate resource, it will return a 404 error.
  • location ~ \.php$ — This location block handles the actual PHP processing by pointing Nginx to the fastcgi-php.conf configuration file and the php7.4-fpm.sock file, which declares what socket is associated with php-fpm.
  • location ~ /\.ht — The last location block deals with .htaccess files, which Nginx does not process. By adding the deny all directive, if any .htaccess files happen to find their way into the document root ,they will not be served to visitors.

When you’re done editing, save and close the file. If you’re using nano, you can do so by typing CTRL+X and then y and ENTER to confirm.

Activate your configuration by linking to the config file from Nginx’s sites-enabled directory:

  • sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Then, unlink the default configuration file from the /sites-enabled/ directory:

  • sudo unlink /etc/nginx/sites-enabled/default

Note: If you ever need to restore the default configuration, you can do so by recreating the symbolic link, like this:

  • sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/

 

This will tell Nginx to use the configuration next time it is reloaded. You can test your configuration for syntax errors by typing:

  • sudo nginx -t

If any errors are reported, go back to your configuration file to review its contents before continuing.

When you are ready, reload Nginx to apply the changes:

  • sudo systemctl reload nginx

Your new website is now active, but the web root /var/www/your_domain is still empty. Create an index.html file in that location so that we can test that your new server block works as expected:

  • nano /var/www/your_domain/index.html

Include the following content in this file:

/var/www/your_domain/index.html
<html>
  <head>
    <title>your_domain website</title>
  </head>
  <body>
    <h1>Hello World!</h1>

    <p>This is the landing page of <strong>your_domain</strong>.</p>
  </body>
</html>

Now go to your browser and access your server’s domain name or IP address, as listed within the server_name directive in your server block configuration file:

http://server_domain_or_IP

You’ll see a page like this:

Nginx server block

If you see this page, it means your Nginx server block is working as expected.

You can leave this file in place as a temporary landing page for your application until you set up an index.php file to replace it. Once you do that, remember to remove or rename the index.html file from your document root, as it would take precedence over an index.php file by default.

Your LEMP stack is now fully configured. In the next step, we’ll create a PHP script to test that Nginx is in fact able to handle .php files within your newly configured website.

Step 5 –Testing PHP with Nginx

Your LEMP stack should now be completely set up. You can test it to validate that Nginx can correctly hand .php files off to your PHP processor.

You can do this by creating a test PHP file in your document root. Open a new file called info.php within your document root in your text editor:

  • nano /var/www/your_domain/info.php

Type or paste the following lines into the new file. This is valid PHP code that will return information about your server:

/var/www/your_domain/info.php
<?php
phpinfo();

When you are finished, save and close the file by typing CTRL+X and then y and ENTER to confirm.

You can now access this page in your web browser by visiting the domain name or public IP address you’ve set up in your Nginx configuration file, followed by /info.php:

http://server_domain_or_IP/info.php

You will see a web page containing detailed information about your server.

Also read : How to Back Up and Restore a MySQL Database

Categories