How to Install the Latest Version of PHP on a Ubuntu Server and Install PHP Plugins for WordPress

Install PHP on  Ubuntu and PHP Plugins for WordPress

PHP is one of the most popular server-side scripting languages that powers many websites and web applications. In this article, we will show you how to install the latest version of PHP on a Ubuntu server and how to install PHP plugins for WordPress, one of the most widely used content management systems.

Installing PHP on Ubuntu

Depending on your Ubuntu version, the default PHP package may not be the latest one. To install the latest version of PHP on Ubuntu, you can use a third-party repository maintained by Ondřej Surý, a Debian developer.

To enable the repository, run the following commands:

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

Then, update your package list and install PHP:

sudo apt update
sudo apt install php

This will install the latest PHP package available from the repository, along with some additional, related packages in most cases.

To check the installed PHP version, run:

php -v

You should see something like this:

PHP 8.1.2 (cli) (built: Feb  9 2022 10:29:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Integrating PHP with Apache or Nginx

If you are using Apache or Nginx as your web server, you need to install and configure the corresponding PHP module or FPM service to process PHP files.

Apache

If you are using Apache as your web server, run the following command to install the Apache PHP module:

sudo apt install libapache2-mod-php

Once the package is installed, restart Apache for the PHP module to get loaded:

sudo systemctl restart apache2

Nginx

If you are using Nginx as your web server, you need to use PHP-FPM (“fastCGI process manager”) to handle the PHP files.

Run the following command to install PHP-FPM:

sudo apt install php-fpm

Once the installation is completed, the FPM service will start automatically. To check the status of the service, run:

systemctl status php-fpm

You should see something like this:

● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-05-30 09:55:27 CEST; 5min ago
       Docs: man:php-fpm8.1(8)
   Main PID: 1234 (php-fpm8.1)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2286)
     Memory: 14.3M
        CPU: 135ms
     CGroup: /system.slice/php8.1-fpm.service
             ├─1234 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
             ├─1235 php-fpm: pool www
             └─1236 php-fpm: pool www

You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:

server {
    # . . . other code
    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    }
}

Do not forget to restart the Nginx service so that the new configuration takes effect:

sudo systemctl restart nginx

Installing PHP Extensions

PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt:

sudo apt install php-[extname]

For example, to install MySQL and GD extensions, you would run the following command:

sudo apt install php-mysql php-gd

After installing a new PHP extension, depending on your setup, do not forget to restart Apache or PHP-FPM service.

Installing PHP Plugins for WordPress

WordPress is a popular content management system that allows you to create and manage websites easily. WordPress has a large collection of plugins that add various features and functionalities to your website.

To install PHP plugins for WordPress, you need to have WordPress installed on your server first. You can follow this guide on how to install WordPress on Ubuntu.

Once you have WordPress installed and running, you can access your WordPress dashboard by visiting http://your_server_ip/wp-admin in your browser.

From there, you can browse and install plugins from the official WordPress plugin directory or upload plugins from other sources.

To browse and install plugins from the WordPress plugin directory, go to Plugins > Add New in your dashboard menu.

You will see a list of featured plugins that you can filter by category or search by keyword.

To install a plugin, click on the Install Now button below its name and description.

Once the plugin is installed, click on the Activate button to enable it.

To upload plugins from other sources, go to Plugins > Add New > Upload Plugin in your dashboard menu.

You will see a form where you can choose a plugin file from your computer or enter a URL of a plugin file.

The plugin file must be in ZIP format and must contain a valid plugin header comment.

Click on the Install Now button to upload and install the plugin.

Once the plugin is installed, click on the Activate Plugin link to enable it.

Conclusion

In this article, I have shown you how to install the latest version of PHP on a Ubuntu server and how to integrate it with Apache or Nginx web servers. We have also shown you how to install PHP extensions and plugins for WordPress.

PHP is a powerful and versatile language that can help you create dynamic and interactive web pages. By installing and configuring PHP on your server, you can run various web applications and frameworks that use PHP as their backend language.

We hope this article was helpful and informative for you. If you have any questions or feedback, feel free to leave a comment below.

Thank you for reading!


Home » Blog » EN » Linux – EN » How to Install the Latest Version of PHP on a Ubuntu Server and Install PHP Plugins for WordPress

Lascia un commento