PHP page generation speed

To measure the speed of page generation in PHP, insert the following code at the beginning of the script:

// Breathing start time of page generation
$start_array = explode(" ",microtime());$start_time = $start_array[1] + $start_array[0];

And at the end of the script we write this:

// Calculating the speed of page generation
$end_array = explode(" ",microtime());$time = $end_array[1] + $end_array[0] - $start_time;
printf("Generated in %f sec.",$time);

Why in the script?
To minimize the time for calculation of page generation in PHP, it is better to insert the code in the main script to minimize the accesses to the hard disk, and thus reduce the loss of time.

Install Nginx, PHP, MySQL (Mariadb) on Ubuntu

-Would you be kind to me in which direction to go?
-In the famous you, – replied the cat.
-I don’t know it.
-So, in the unknown. In any case, it is known that in a known time you will find yourself therrre or herrre,-purring cat.

Nginx Installation:

apt update
apt install nginx

Installing PHP and the MariaDB driver

apt install php-fpm php-mysqlnd php-xml

Creating Virtual Domains

mkdir /var/www/domain.com
chmod -R 755 /var/www/domain.com

In the /etc/nginx/sites-available directory, we create a domain.com.conf file

The contents of the domain.com.conf file

server {
     listen 80;
     server_name domain.com;

     root /var/www/domain.com;

     # Add index.php to the list if you are using PHP
     index index.php index.html index.htm index.nginx-debian.html;
 
     server_name domain.com;
 
    location / {
               try_files $uri $uri/ =404;
               if (!-e $request_filename) {
                  rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*\.php)$ $1 last;
                  rewrite ^(.+)$ /index.php?q=$1 last;
      }
}

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

Now you need to reboot the Webserver

service nginx restart

Checking PHP work

In /var/www/domain.com , we will create the index.php file and write in it:

<?php phpinfo(); ?>

Next, open your website in the browser, in the example we use domain.com and if everything is done correctly, we see this picture:

Install MARIADB

sudo apt install mariadb-server mariadb-client

Security settings

mysql_secure_installation

Answer the questions:

Create a database and a user.

Entering the MARIADB:

mysql -u root

If you set the password to root:

mysql -u root -p
CREATE DATABASE domaindb;
CREATE USER 'nameus'@'localhost' IDENTIFIED BY 'user_password';

For the user_password place, enter the user password.

GRANT ALL ON domaindb. * to nameus @ localhost;
Quit

Deploying WordPress

cd /var/www/domain.com
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
mv wordpress/* .
rmdir wordpress
chown -R www-data:www-data /var/www/domain.com
chmod -R 755 /var/www/domain.com

How to configure SSH without a password with a key pair in Ubuntu

Create a key pair, leave all values by default:

ssh-keygen

In the console, enter a command that configures the server so that you can sign in with an SSH key:

 ssh-copy-id -i .ssh/id_rsa.pub [email protected] 

Instead of127.0.0.1, specify the IP server.

Take the private key id_rsa rename the extension in PPK, winscp add to the connection SSH authentication and it will offer to convert the file to Putty format and save a new key. and add a new key to the connection, try to connect.

Edit the Sshd_config file

mcedit /etc/ssh/sshd_config

Add the PasswordAuthentication no instruction

Immediately you can change the standard access port, the Port 22  instruction, for example, write Port 4321, now access to SSH will be on port 4321.

Reboot ssh to apply config changes:

systemctl restart ssh

Now when you try to log in by password, we get a window with an error:

Attach a private key to the connection and the task is solved.

Intercept require output in PHP or execute PHP in file_get_contents

… So we’re introducing a plan-intercept. Only immediately prepare a report that the plan-interception no results.
The Lord of the Rings: the Two Towers

In order to load the contents of a file and display it in a certain place of a Web page, you can use file_get_contents, but if the file loaded in this way will contain PHP code, it is not processed.
For the PHP code to execute in a dynamically loaded file, you can use the command require, but it outputs the result instantly, and if we pre-generate the output into a variable, this method is also not suitable… Or does it fit?

In PHP there is a set of commands to buffer output to enable the output buffer by using the ob_start() command. After that, we call require and collect the result in the variable with the command ob_get_clean();

function GetPHP($file_name){
    ob_start();
    require( $file_name );
    return ob_get_clean();
}

Here is a function that returns the result of executing a PHP script in a variable.

echo GetPHP('some-file.php');

Universal string comparison in JavaScript

If it’s more important than that between the lines, put the lines away.

String comparison in JavaScript if(“text string”==”text string”) will not return true because In fact, not the strings are compared, but the addresses of those strings in memory. To compare a string, you can wrap it like this: new String(“text string”).valueOf().

if(new String("text string").valueOf() == new String("text string").valueOf()){
		console.log('eq');
}

Deploying Nginx + PHP on the Ubuntu server

NGinx-is a quick and easy Web-server, to install it you need to enter several commands in the terminal:

sudo apt update
sudo apt install nginx php-fpm

Check the health of the Web server:

systemctl status nginx

In this case, change the file /etc/nginx/sites-available/default

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	index index.html index.htm index.php;

	server_name _;

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

	location ~ \.php$ {
		try_files $uri = 404;
		include /etc/nginx/fastcgi.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}
}

Next, reboot Nginx

nginx -s reload

 

Complete removal of postfix, SpamAssassin and Dovecot in Ubuntu

You will not have time to be attached to any pleasant, calm place, and already some voice makes you stand up and retire from it, as the hour of rest has passed.
–Charlotte Bronte. Jane Eyre–Edward Rochester

In case you need to reinstall postfix, spamassassin and dovecot in ubuntu, first remove:

apt-get --purge remove postfix postfix-mysql spamassassin dovecot-core dovecot-common dovecot-imapd dovecot-pop3d

Perl. Search for short domains-2 solutions

There are situations when you need to find a free and short domain, for example, three-character.
I chose the .net domain zone for myself

Method One:
On the internet it is possible to find not actual today bases, for example:
Https://www.domainresearchtool.com/lists/net.zone.gz
But the problem is that this base is for 2014 and it is already outdated. But in case you have a budget of about $30, you can buy this file up-to-date.
Scripts that will help to get all three-character domains from a file have been written in Perl.

open(my $fh, "<", "zone.txt") or die "Can't open file: $!";
open(my $wh, '>', "custom.txt") or die "Can't open file: $!";
$cou=0;
while (<$fh>) {
  my @array = split /\s+/, $_;
  if ((@array[1] eq "NS")&&(@array[0] ne $tmp)&&(length @array[0] == 3)){
    print $wh @array[0]."\n";
  }
  [email protected][0];
  $cou++;
  if ($cou%100000==0){
    print "$cou\n";
  }
}
close $fh;
close $wh;
open(my $fh, "<", "custom.txt")
or die "Can't open file: $!";
chomp(my @lines = <$fh>);
close $fh;
@list=sort @lines;
open(my $fh, ">", "sorted.txt")
or die "Can't open file: $!";
foreach (@list) {
  print $fh "$_\n";
}
close $fh;

 
This script takes all three-letter domains from the zone. txt file and saves them to the file custom. txt, and then sorts the found domains alphabetically and saves the sorted list to the file sorted. txt.

The second script:

open(my $fh, "<", "sorted.txt")
or die "Can't open file: $!";
chomp(@lines = <$fh>);
close $fh;
open(my $wh, '>', "free.txt") or die "Can't open file: $!";
my $cou=0;
@letters=('-','0'..'9','A'..'Z');
for(my $i=1; $i < scalar @letters; $i++){
  for(my $j=0; $j < scalar @letters; $j++){
    for(my $k=1; $k < scalar @letters; $k++){
      [email protected][$i][email protected][$j][email protected][$k];
      if(isPresent($dmn)<1){
        $cou++;
        print $wh $dmn."\n";
        if($cou %100 == 0){
          print $cou.", ";
        }
      }
    }
  }
}
close $wh;
print "ok";
sub isPresent(){
  my ($dmn)[email protected]_;
  foreach(@lines){
    if ($_ eq $dmn){
      return 1;
    }
  }
  return 0;
}

 
Loads the file sorted. txt and generates all possible combinations of three-character domains from 0-0 to ZZZ, then checks whether these domains exist in the sorted. txt file and if they are not, the file free. txt is created.
Just these names you will be able to use to select and register already your domain.

The second way:
If you do not have access to the actual files of domain zones, you can write a bot that will take all possible combinations of domain name, and using the command nslookup will find all unregistered. The problem is that if the domain is purchased but it is not recorded, it will be considered free-“Non-existent domain”, as a result, we get about 1000 false positives.

Listing bot:

print "Generating all domains names... \n";
my @domains;
@letters=('-','0'..'9','A'..'Z');
for(my $i=1; $i < scalar @letters; $i++){
  for(my $j=0; $j < scalar @letters; $j++){
    for(my $k=1; $k < scalar @letters; $k++){
      push @domains, @letters[$i][email protected][$j][email protected][$k].'.net';
    }
  } 
}
print "Scaning... \n"; unless(open FILE, '>free-domains.txt') {
  die "\nUnable to create $file\n";
}
close FILE;
my $cou=0;
foreach my $domain (@domains)
{
  chomp($domain);
  my $output = qx(nslookup -type=ns $domain 2>&1);
  my $r_c=$?;
  print "|";
  if((index $output, "Non-existent domain") > -1){
    print "\n".$domain."\n";
    open(my $wh, '>>', "free-domains.txt");
    print $wh $domain."\n";
    close($wh);
  }
  if($cou%1000==0){
  print "\nLast checked($cou): ".$domain."\n";
  }
  $cou++;
}

 
Bot saves everything as it considers free domains in the file free-domains. txt
The resulting list can be run through any bulk domain verification service, I used https://www.reg.ru/domain/new/bulk
Sending to check on 200-300 domains, through this service, you can quickly, iterate over the entire list, and free domains will fit in the Recycle Bin.
Here is the result of the search for today: