fbpx

Just recorded a short video on how to resolve Blacklisted domain problem on CyberPanel.

All you have to do is update your server host name so that you can create a domain.

MailScanner is an open-source email security system. It is designed for Linux-based email gateways. CyberPanel provides you with one-click MailScanner installer.

Follow this guide to install or remove MailScanner

How to install MailScanner using CyberPanel:

The installation process of MailScanner is very easy and short using CyberPanel.

First, in the menu go to the Mail Settings -> MailScanner 

You can see an install button on this screen,  press the Install button to start the installation.

Once the installation process is done you can see the Access button on this screen.

Press the Access button and it will take you to the MailScanner login screen.

the URL for MailScanner login is

https://<SERVERIP>:8090/mailwatch/mailscanner/login.php

How to get UserName and Password for MailScanner:

The default login access for MailScanner is

Username: admin

Password: Password for your admin user on CyberPanel.

You can also create new user by running the following query on PHPMyAdmin or via MySQL CLI:

INSERT INTO mailscanner.users SET username = '<username>', password = MD5('<password>'), fullname = '<Full Name>', type = 'A';

Replace <username>, <password> and <Full Name> in the query above according to your requirements.


How to remove MailScanner

You can remove MailScanner by running following commands on CLI:

chmod +x /usr/local/CyberCP/CPScripts/mailscanneruninstaller.sh
/usr/local/CyberCP/CPScripts/mailscanneruninstaller.sh

Emails stop working after installing MailScanner

If you can't send or receive emails after installing MailScanner use our troubleshooting guide. You can also temporarily stop MailScanner processing by opening

/etc/postfix/main.cf

and removing following line from this file

header_checks = regexp:/etc/postfix/header_checks

after removing this line run

systemctl restart postfix

and you should be able to send emails again.

 

CyberPanel v2.1.1 introduced a feature to enforce website disk limits via packages.

Enforce Website disk limits via Package creation:

While creating any new package you can see a check on the package creation page called Enforce Disk Limits. If you check this option, all websites under this package will not be able to use disk more then what it is specified in Disk Space box.

For example, we want to set a 10GB space limit on the new website first of all you need to create a package from the Package->Create Package set the space to 10GB, and check the Enforce Disk Limits to make sure they can't exceed or use more then 10GB of space.

Enforce Website disk limits on Existing websites with existing Packages:

For older CyberPanel with existing websites can also set disk limits by turning on this option for existing packages.

Go to  List Websites page to find out which package is being used by the site.

Now go to the modify package page and select that package and then check the Enforce Disk Limits option.

To use this feature your CyberPanel version must be v2.1.1 or above.

Read our Facebook announcement related to this feature.

After  v2.1.1 and above we've added an option in the cloud to perform fail-safe upgrade. (This works only if you are on v2.1.1 or above)

This upgrade procedure will only upgrade/change CyberPanel branch and apply any needed migrations and fix permissions.

The whole process is very simple and require few clicks only with no need to open a terminal.

Follow these steps to upgrade your server to the latest version using CyberPanel Cloud.

Note: This is free for everyone.


Login to CyberPanel cloud Using credentials:

Visit https://cloud.cyberpanel.net/ provide username and password to login into your account.

Once you logged in to your CyberPanel Cloud make sure your server that you want to update is connected to the cloud and running.

Connect Your server to CyberPanel Cloud:

To connect your server to the cloud go to the Connect CyberPanel -> Connect in the top menu.

To connect provides all details of your server:

  1. Name (this can be anything)
  2. Ip (Your server IP)
  3. Password (Your CyberPanel admin user password not ssh)
  4. Port/Username (Leave both to use default)

Press connect and you can see a success message in green.

Upgrade Your CyberPanel Now:

To upgrade your cyberpanel:

Go to the Server->List Servers now select the server which you want to upgrade.

Now after selection click on the three dots present on a server

Now on the Manage page go to Settings -> Upgrade

On the Upgrade page just select the version you want to update to and press upgrade.

Note: This article is a work in process, will keep adding more information.

If you have recently upgraded CyberPanel and your email stopped working then follow this guide to debug and possibly fix your email system.

We recommend to upgrade your CyberPanel via CyberPanel cloud to avoid any such issue in the future:

How to upgrade your CyberPanel using CyberPanel Cloud


Step 1: Check and Fix Postfix Service

First thing to do is to check weather postfix services is running:

systemctl status postfix

Run the command above to check if postfix is running, if it is, then you should see something like:

● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-04-15 02:00:43 CEST; 1 day 18h ago
 Main PID: 3745676 (master)
   CGroup: /system.slice/postfix.service

If postfix is running and you can't send emails then read our troubleshooting guide to find out why.

If postfix is not running then you can try starting it, but if you can't then check weather it is installed or not

Centos 7 or Centos 8

[[email protected] ~]# yum list installed | grep postfix
postfix3.x86_64                2:3.5.8-1.gf.el7      @gf-plus                   
postfix3-ldap.x86_64           2:3.5.8-1.gf.el7      @gf-plus                   
postfix3-mysql.x86_64          2:3.5.8-1.gf.el7      @gf-plus                   
postfix3-pcre.x86_64           2:3.5.8-1.gf.el7      @gf-plus                   
[[email protected] ~]#

Ubuntu 18 or Ubuntu 20

apt list --installed | grep postfix

If you don't see any postfix packages installed, then postfix is not installed in your system. You can install them, first enable gf repo (for Centos 7 or Centos 8) on your system.

Note: Take backup of your postfix configurations at /etc/postfix and restore them after installation

Centos 7

yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm

Centos 8

dnf --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm

now install postfix

Centos 7

yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre

Centos 8

dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y

Ubuntu 18 or Ubuntu 20

apt-get -y install postfix postfix-mysql

Once postfix is installed again, you can restore the backup of configurations file and restart postfix and verify that it is working.


Step 2: Check and Fix Dovecot Service

Second thing to do is to check weather dovecot services is running:

systemctl status dovecot

Run the command above to check if dovecot is running, if it is, then you should see something like:

● dovecot.service - Dovecot IMAP/POP3 email server
Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-04-15 02:00:44 CEST; 1 day 18h ago
Docs: man:dovecot(1)
http://wiki2.dovecot.org/
Main PID: 3745695 (dovecot)

If dovecot is not running then you can try starting it, but if you can't then check weather it is installed or not

Centos 7 or Centos 8

[[email protected] ~]# yum list installed | grep dovecot
dovecot23.x86_64 1:2.3.11.3-1.gf.el7 @gf-plus 
dovecot23-mysql.x86_64 1:2.3.11.3-1.gf.el7 @gf-plus 
[[email protected] ~]#

Ubuntu 18 or Ubuntu 20

apt list --installed | grep dovecot

If you don't see any dovecot packages installed, then dovecot is not installed in your system. You can install them, first enable gf repo (for Centos 7 or Centos 8) on your system.

Note: Take backup of your dovecot configurations at /etc/dovecot and restore them after installation

Centos 7

yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm

Centos 8

dnf --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm

now install dovecot

Centos 7

yum --enablerepo=gf-plus -y install dovecot23 dovecot23-mysql

Centos 8

dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y

Ubuntu 18 or Ubuntu 20

apt-get -y install dovecot-mysql dovecot-imapd dovecot-pop3d

Once dovecot is installed again, you can restore the backup of configurations file and restart dovecot and verify that it is working.

Custom/Extra Header can be used for many proposes like:

  1. Content Security policy
  2. Referrer policy
  3. HSTS (Strict-Transport-Security)
  4. Content-type options

If you are using the LiteSpeed Enterprise server you can add Extra headers to your htaccess file and the server will add it automatically just like you used to do with Apache as it is fully Apache Compatible.

However, if you are using OpenLiteSpeed it has to be done via OpenLiteSpeed WebAdmin or by adding it to vHost configuration for the website via CyberPanel.


Table of Contents

  1. Log in to CyberPanel
  2. Open the Website Manager
  3. Edit vHost Configuration
  4. Verify Headers.

Here are the steps to add a HSTS Header or extra header via vHost configuration from CyberPanel.


1. Log in to your CyberPanel Server

Visit https://<IP Address->:8090

Enter credentials to log in.


2. Open the website manager:

     2.1 Click on the website and then click on the list websites.

Click on website and then click on list websites

      2.2 Click on the manage button in front of your desired website.

Click on mange button in front of your desired website.


3.  Edit vHost Configuration :

       3.1 Click the vHost conf from the website manager.

Click the vHost conf from the configurations portion in website manager.

vHost Conf box will open, move on to Step 4 on how to add HSTS header.


4. How to set HSTS (Strict-Transport-Security) via vhost Conf:

HSTS is a web security policy mechanism that helps to protect websites against man-in-the-middle attacks such as protocol downgrade attacks and cookie hijacking.

Go to the bottom of the vHost Conf box which you have opened in last step and paste following at the end of the file

context / {
  allowBrowse             1
  extraHeaders            Strict-Transport-Security "max-age=15552000; includeSubDomains;preload"

  rewrite  {

  }
  addDefaultCharset       off

  phpIniOverride  {

  }
}

 1. The age parameter tells the browser how long this rule must be cached.
 2. The includeSubDomains should only be added if you want to apply HSTS to subdomains too.
 3. The preload parameter is used for inclusion in Google Chrome’s preload list.


5. How to verify extraHeaders configuration:

To verify extraHeaders configuration follow the steps:

    4.1 Open Network tab:

        1. Vist your website in any browser and open developer tools.

        2. In developer tools click on Networks tab

Open network tab

         3. Click on the file with your domain name. like(abc.xyz)

 

         4. Go to Network Tab and check headers for any request. You should the extra header you added in vHost conf.

CyberPanel only install LiteSpeed PHPs from LiteSpeed repos. Installation directory for PHP is located at

/usr/local/lsws/lsphpXX

You need to replace XX in the path above with PHP version, for example the path for PHP version 7.4 is /usr/local/lsws/lsphp74

And PHP CLI binary path for each PHP version is

/usr/local/lsws/lsphpXX/bin/php

So PHP binary path for PHP 7.4 is /usr/local/lsws/lsphp74/bin/php

During installation CyberPanel installation code runs following command to set Global PHP CLI:

ln -s /usr/bin/php /usr/local/lsws/lsphp74/bin/php

Which means by default the Global PHP for CLI is 7.4, upon running php -v on command line you will get:

[email protected]:~# php -v
PHP 7.4.16 (cli) (built: Mar  4 2021 16:36:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies
[email protected]:~#

How you can change the default version of PHP on CLI?

If you have certain needs and PHP 7.4 does not work for certain application you can run following command to update the default PHP on CLI.

Set Command line to PHP 8.0

ln -s /usr/bin/php /usr/local/lsws/lsphp80/bin/php

Set Command line to PHP 7.3

ln -s /usr/bin/php /usr/local/lsws/lsphp73/bin/php

Set Command line to PHP 7.2

ln -s /usr/bin/php /usr/local/lsws/lsphp72/bin/php

Set Command line to PHP 7.1

ln -s /usr/bin/php /usr/local/lsws/lsphp71/bin/php

How to use specific PHP Version in your Cron Jobs?

Some applications requires you to set cron jobs and they require PHP CLI executable. Now rather then changing default global php binary version, you can use direct path to that CLI.

For example an application requires that its script should be running through PHP 7.2, you can use the direct path for its binary rather then updating a global binary, such as

/usr/local/lsws/lsphp71/bin/php <your command goes here>

Around March 10th, 2021 million of websites went offline as fire destroyed one of the four data centers of OVHcloud in France. According to internet monitors many government, banks and news portal sites went offline because of the fire.

So, if you don't have a disaster recovery plan in place, your site could end up with same fate. That's where High availability come into play.

The High Availability feature allows you to maintain 100% uptime for your sites. In this feature, CyberPanel Cloud will take care of creating 100% replica of your Main server to a secondary Fail over server. We will go one-step further and take care of DNS switch in case your Main server goes down so that you can sleep peacefully.

You need to be at least on Professional or Business plan to create clusters, read more here.


Table of Contents:

  1. What is High Availability?
  2. How to set up High Availability/Clustering from CyberPanel Cloud?

1. What is High Availability?

In simple words, High Availability is the takeover or replacement of the server or system by another system on its failure. Now, how CyberPanel Cloud is doing it and what things you need to take care of are mentioned below:

  1. You need to configure Cloudflare API as mentioned above and your DNS should be handled by Cloudflare, so that Cloud can perform DNS switch in case of downtime.
  2. Once Cloudflare is configured, you need to create a cluster (which will be explained later in this tutorial below)
  3. Once the cluster is created and booted up from Cloud, Cloud will sync your data (the sync duration will be selected by you while creating cluster)
  4. Cloud will also set up your MySQL to be in 100% sync in real-time.
  5. Cloud will also create and sync virtual host configurations between the main and failover servers.
  6. Cloud will check your main server every 3 minutes, if the server is down then a DNS switch will be performed.

2. How to set up High Availability/Clustering from CyberPanel Cloud?

Setting up High Availability/Clustering now becomes very easy with CyberPanel Cloud. The process of setting up high availability is very simple and easy.

  1. Things that you need to setup High Availability
  2. CyberPanel Cloud account.
  3. Add Cloudflare API key to Cloud
  4. Setup Clustering in CyberPanel Cloud.

Things that you need to setup High Availability. 

There are a few things you must have before setting up the High Availability cluster:

  1. Cloudflare account (Where you have to setup DNS)
  2. CyberPanel Cloud account (Where you can set up clustering)
  3. Two servers (Main and Fail over node)

Login to CyberPanel Cloud:

Visit CyberPanel Cloud Here.

Login using your credentials and if you don't have an account create a new one.

Read more about CyberPanel Cloud.

Add Cloudflare API key to the cloud:

To set up the High Availability feature, first, you need to Add API Key in the cloud.

Read here on how to configure the Cloudflare API key.

Setup Clustering in CyberPanel Cloud:

Setting up High Availability is very easy and simple on CyberPanel Cloud. Just need to follow the steps mentioned below:

Before using this feature both main and fail over servers must be connected to the cloud (you can use the connect feature if CyberPanel is already installed or the Deploy feature to install CyberPanel on fresh OS)

Once you have 2 servers connected to cloud, move forward

  1. In the top menu go to the Server-> Create Cluster

2. Now you need to select the options.

  1. Cluster Name (name can be anything easy for you to remember)
  2. Main Server (Select any server from the cloud you have added in your account which you want to use as master)
  3. Failover Server (Select a server that will work as a failover server, make sure this is a fresh CyberPanel server with no websites hosted on this server)
  4. Cloudflare Account to use (Select API Key that you using the article mentioned above)
  5. Sync Data Every (Select time from 5-55 minutes to sync data from main server to fail over server)

3. After providing all information Press Create Cluster button.

The next screen will show you the status of your cluster along with real-time data from your cluster nodes.

Once servers are attached to cluster, you will get a Boot Cluster button. Click the button, once both Main and Fail over server are booted, your cluster is now successfully created.

Servers will boot and show you in logs once done.

Once the clusters are booted you don't need to do anything. Sit back and relax, CyberPanel Cloud will take care of everything and notify you when your main server is down and then perform a DNS switch.

If you have any question or need help setting up a cluster feel free to contact us via our help desk.

CyberPanel have recently launched High Availability feature where you need to select a Cloudflare API to switch DNS in case Main server goes down. We will use your Cloudflare API to switch DNS to Fail over server so that your sites remain online.

Follow the article below to configure Cloudflare API so that you can start creating clusters.


Table of Contents:

  1. Get an API key from Cloudflare
  2. Login to CyberPanel Cloud
  3. Configure your Cloudflare to Cyberpanel Cloud

1. Get an API key from Cloudflare:

In the first step, you have to log in to your Cloudflare to get an API key. Visit here to log in to Cloudflare.

In Cloudflare dashboard

  1. Go to the Profile option on the right click My Profile.

2. In the top bar click on API Tokens then check the Global API key in the Keys section below.

3. Then Click the View button in front of the Global API Key.

4. You can see the API key in the prompt window.

This will ask for your Cloudflare password. Provide the details and press View.

You can see your API key copy this key and move to the next step.


2. Log in to CyberPanel Cloud:

Go to https://cloud.cyberpanel.net/ provide your login details and login to your CyberPanel Cloud account.

3. Configure your Cloudflare to Cyberpanel Cloud:

Once you logged in to the cloud account,

  1. In the Top menu go to the Settings-> Cloudflare

2. In the Cloudflare screen you have to provide all required information.

  1. Name (Any name you want to give)
  2. API Key (The key you copied from the Cloudflare account)
  3. Email (Valid email address that you used in Clouflare)

After providing all the information click Create button.

Below the add API key, you can see already configured keys.

You are now ready to create Highly Available Clusters.

CyberPanel version required: v2.1.1 or above, if you are below this version read our old article to manage child-domains.

Deleting a child domain in CyberPanel is now easier than ever. You can delete the child domain from CyberPanel with just a few clicks.

Table of Contents:

  1. Login to CyberPanel
  2. Delete Child Domain

Login to CyberPanel:

Login to your CyberPanel using the credentials. Visit the access URL:

https://<Your-ip/domainname>:8090

Delete Child Domain:

To delete the child domain just go to Website->List Child Domians in the left menu of CyberPanel dashboard.

 

 

Here you find all of your subdomains. Below every domain, you can find a delete button. Press the Delete button.

 

A prompt appears in front of you which asks you either you want to delete the root directory for this child domain or not.

If you check this option, the Document Root (or in simple words the files for this subdomains) will be deleted as well. However if you do not check this option, your subdomain will be deleted but its files will be kept in file-system.

 

When you have an active and working website you always have to take care of your data.

What happens if you suddenly see that your website is not working, or your data on the website is deleted or your website is hacked, or some update crashed the whole website. Oh, it’s a very critical and dangerous situation for you.

Now, to avoid this type of situation you need to set up a proper backup for your website. Backups are always proving as useful and important for you.

CyberPanel Cloud brings a new exclusive feature for you to set up your backups with CyberPanel Cloud.


Follow steps to setup Backup:

  1. Login to CyberPanel Cloud
  2. Manage Your server
  3. Setup backups for your website
  4. Restore Backup from Cloud

Login to CyberPanel Cloud:

To set up cloud backups you need to login to CyberPanel Cloud first.

Visit https://cloud.cyberpanel.net/ and log in by providing the login details.

 

 

If you do not have an account, please create an account and buy a suitable plan from the Cloud. Read more about plan and Cloud here https://cyberpanel.net/docs/what-is-cyberpanel-cloud/


Manage Your server

Once you logged in you can see the different options. On the top menu, you can see the first option Servers.

 

Click on this server button and you can see all your server you added to CyberPanel Cloud.

On your server, you can see three dots on the top as shown below. Click on this button.

 

You can see three options

  1. Manage
  2. CyberPanel Access
  3. Delete

Click on the manage button here.

 


Create Backup For your Website:

Here in this manage Dashboard, you can see the websites that you added below. There is a Launch button for each website as shown below. Click that launch button.

 

Once you get in the manage website option here you can see the Cloud Back option when you click on you can see a Create Backup option.

 

 

Here you can see the option for which you want to add backup. The most important thing you have to take care of that is what you want to include in a backup.

  1. Data
  2. Databases
  3. Emails

If you do not select any option nothing is included in the backup but a backup file will be created and a backup added.


Restore Backup From Cloud:

Here is another exciting and important feature that you can restore your backup from the backup page.

Below the create backup button you can see the restore button if you want to restore backup instantly you can restore the backup by just clicking the restore button.

 

 

 

 

PHP 8.0 has been released on 26th November and come with a ton of new features and breaking changes. CyberPanel has added PHP 8.0 and all the currently available extensions. You can update your CyberPanel now and start testing your application to make it future proof.

PHP 8.0 is a major version which means it has been anticipated for years and it was under development for more than 2 years. This brings loads of changes to the type system, syntax, error handling, strings, object-oriented programming, and much more.

PHP 8.0 also introduces JIT ( Just in Time) compilation which makes it much easier and faster to run code that can be predicted.

So let's start discussing significant changes and new features.


New Features

Constructor property promotion

The new version allows you to define and assign variables right in the constructor instead of having to define first, ask or set them in the constructor's argument list and then assign the values.
So a typical PHP 7 or below class initialization code looks like this

class Point {
    public int $x;
    public int $y;
    public int $z;

    public function __construct(
        int $x = 0,
        int $y = 0,
        int $z = 0,
    ) {
        $this->x = $x;
        $this->y = $y;
        $this->z = $z;
    }
}

 

With PHP 8 it can be shortened to this

class Point {
  public function __construct(
    public float $x = 0.0,
    public float $y = 0.0,
    public float $z = 0.0,
  ) {}
}

 

Named Arguments

Before PHP 8.0 we could pass parameter as arguments but they had to be in order that they were defined in the function ( positional arguments ) and there was no way that you could pass them along with the name of the argument, so you always had to make sure that they were in order and it made writing code a bit difficult and more time-consuming. It was an additional nuisance to check for declaration whenever you had to debug.
For example in PHP 7 and below a typical function and its call would look like this

function str_contains(string $haystack, string needle): bool {
//code to find the needle in the haystack
}
str_contains('FooBar', 'Foo');

But if you mistakenly send the "needle" first or if you function has many arguments and you missed one of them you would be in trouble however from PHP 8.0 you can send the name along the argument too.

function str_contains(string $haystack, string $needle): bool {
//code to find the needle in the haystack
}
str_contains(haystack: 'FooBar', needle: 'Foo');

You could also send the named arguments in different order and it would still work

function str_contains(string $haystack, string $needle): bool {
//code to find the needle in the haystack
}
str_contains(needle: 'Foo', haystack: 'FooBar');

As you can understand this could help make the code easier to write, understand and debug.

Null-safe Operator

We have all been there when we have to add a extra check to make sure something is present in the any object before calling a pointer or a nested pointer if we don't want a missing info resulting in a fatal error

PHP 8.0 adds a null safe operator to -> to provides safety in method/property chaining when the return value or property can be "null"

In PHP 7 and below we had to do something like this

$country =  null;

if ($session !== null) {
  $user = $session->user;

  if ($user !== null) {
    $address = $user->getAddress();
 
    if ($address !== null) {
      $country = $address->country;
    }
  }
}

With PHP 8 it can be done in a single line like this

return $user->getAddress()?->getCountry()?->isoCode;

The ?-> null-safe operator short-circuits the rest of the expression if it encounters a null value, and immediately returns null without causing any errors.

Attributes

Atrributes or meta-data annotations are one of the biggest changes in PHP 8.0. Till this version PHPdoc was used to add comments, now we can attributes which can be fetched programmatically when declared using "use" keyword and reflection API

This can be done using << >> operators instead of using *@ method

Here is a complete example

use App\Annotations\FooAttribute;
use App\Annotations\ClassAttrib as FooClassAttrib;
use App\Annotations\FooParamAttrib;
use External\Attr\BarClassAttrib;

<<App\Annotations\FooAttribute>>
function foo_func(<<FooParamAttrib('Foo1')>> $foo) {}

<<FooAttribute('hello')>>
<<BarClassAttrib(42)>>
class Foo {
    <<ConstAttr>>
    <<FooAttribute(null)>>
    private const FOO_CONST = 28;
    private const BAR_CONST = 28;

    <<PropAttr(Foo::BAR_CONST, 'string')>>
    private string $foo;

    <<SomeoneElse\FooMethodAttrib>>
    public function getFoo(<<FooClassAttrib(28)>>): string{}
}

JIT ( Just in time ) Compilation

JIT is arguably the biggest change that has been added to PHP 8. In a compiled language, the source code is converted to computer-readable code ahead of time. Interpreted languages, on the other hand, convert the source code as it's executed, which is much slower. PHP is an interpreted language, and there have been several tactics used to improve PHP performance in the past with the latest step is the addition of the JIT compiler in PHP 8.

The JIT compiler is a middle ground between compilation and interpretation. It will compile and cache some sections of code at runtime so that the compiled version can be used instead of the interpreted version. This could lead to huge performance gains for PHP, but with some caveats. Generally, JIT compilers mostly benefit CPU-intensive applications, such as 3D rendering or large mathematical computations. If you're using PHP for web applications, you may not see a substantial performance boost by enabling the JIT compiler.

PHP team has shared some results which show improvement in processing speed for synthetic benchmarks

However one of the developer says the following

 it currently doesn’t seem to significantly improve real-life apps like WordPress (with opcache.jit=1235 326 req/sec vs 315 req/sec).

It’s planned to provide additional effort, improving JIT for real-life apps, using profiling and speculative optimizations.”

So we might have to wait a few more version to see the results on web apps like WordPress or Laravel based apps.

throw as an expression

Prior to PHP 8.0, throw was a statement and it was not allowed to throw an exceptions in when a single expression is expected. It is now possible to throw an exception in arrow functions, ternary expressions, or anywhere else the PHP parser expects a single expression.

Arrow Functions:

$fn = fn() => throw new \Exception('oops');

Ternary expressions:

$value = isset($_GET['value'])
? $_GET['value']
: throw new \InvalidArgumentException('value not set');

$value ??= throw new \InvalidArgumentException('value not set');

$foo = $bar ?: throw new \InvalidArgumentException('$bar is falsy');

$foo = $bar ?? throw new \InvalidArgumentException('$bar is not set');

Match expression

Switch statement gets and elder more powerful sister called match. Its an expression so the results can be stored. Although it does strict comparison only.

So a switch statement like this in PHP 7

switch (8.0) {
  case '8.0':
    $result = "Oh no!";
    break;
  case 8.0:
    $result = "This is what I expected";
    break;
}
echo $result;
//> Oh no!

Can now be written as

echo match (8.0) {
  '8.0' => "Oh no!",
  8.0 => "This is what I expected",
};
//> This is what I expected

String functions

PHP 8.0 comes with better string search but its only string sensitive and save you from add !== to strops() function

Without this function, the usual way to find if a given string contains another string is to use to the strpos() function:

if (strpos('Foo Bar Baz', 'Bar') !== false) {
echo 'Found';
}

strpos() function returns the position of the needle string, or false if the needle is not found. This is error-prone, because if the needle is found at the position 0 of the haystack, it evaluates to false unless strict comparison (===) used.

To explain further, the following snippet is not correct:

if (strpos('Foo Bar Baz', 'Foo')) {
echo 'Found';
}

Because Foo is found at the beginning of the haystack, the return value of strpos() call will be 0, which evaluates to false, and the if block will not run.

With the new str_contains function, it is easy to do this:

if (strpos('Foo Bar Baz', 'Foo')) {
echo 'Found';
}

Similarly, two more string functions are added to check if the string begins or ends with another string

str_starts_with to determine if a string starts with another string and str_ends_with to determine if the string ends with another string

str_starts_with (string $haystack, string $needle): bool;
str_ends_with (string $haystack, string $needle): bool;

Deprecations and removals

Adding PHP 8 to Cyberpanel

Installing PHP 8 to Cyberpanel is simple and easy. Just run the upgrade command and it will be installed for you. In case you don't know how to update, please follow this guide

https://cyberpanel.net/docs/upgrading-cyberpanel/

Still not using CyberPanel? Well, you are missing out a lot. CyberPanel provide 1-Click installers for all major server providers and a single command to install if you are using something else. So what are you waiting for?

Get Started Now 

 

chevron-down