How to Install PHP on OpenSUSE 15.2/15.1

last updated in Categories , ,

In this tutorial, you will learn how to install PHP 7.4 on OpenSUSE Linux 15.2/15.1 and configure it with Nginx. PHP is server-side and very popular for various PHP frameworks such as Symfony, Laravel, and open source apps like MediaWiki, WordPress, Nextcloud, and more.

Tutorial requirements
Operating system/appOpenSUSE Linux with Nginx
Root privileges requiredYes
DifficultyEasy (rss)
Estimated completion time10m
Table of contents


Prerequisite to install PHP on OpenSUSE 15.1/15.2

It would be best if you start this tutorial installing Nginx web server. However, first update OpenSUSE Linux software and kernel using CLI:
$ sudo zypper ref
$ sudo zypper up

Next open the terminal app and then type the following zypper command to install Nginx as it is needed for PHP:
$ sudo zypper install nginx
# enable and turn on Nginx for PHP #
$ sudo systemctl enable nginx.service
$ sudo systemctl start nginx.service

See how to install and use Nginx on OpenSUSE Linux server for more information.

Installing PHP on OpenSUSE for Nginx

List all PHP 7.4 packages available on OpenSUSE by type the following command:
$ sudo zypper search php7

Reading installed packages...

S | Name             | Summary                                                   | Type
  | apache2-mod_php7 | PHP7 module for the Apache 2.x webserver                  | package
  | php7             | Interpreter for the PHP scripting language version 7      | package
  | php7-APCu        | APCu - APC User Cache                                     | package
  | php7-bcmath      | "Binary Calculator" extension for PHP                     | package
  | php7-bz2         | bzip2 codec support for PHP                               | package
  | php7-calendar    | PHP7 Extension Module                                     | package
  | php7-ctype       | Character class extension for PHP                         | package
  | php7-curl        | libcurl integration for PHP                               | package
  | php7-dba         | Database abstraction layer for PHP                        | package
  | php7-devel       | PHP7 development files for C/C++ extensions               | package
  | php7-dom         | Document Object Model extension for PHP                   | package
  | php7-embed       | Embedded SAPI Library                                     | package
  | php7-enchant     | Spell checking extension for PHP                          | package
  | php7-xsl         | PHP7 Extension Module                                     | package
  | php7-zip         | ZIP archive support for PHP                               | package
  | php7-zlib        | Zlib compression support for PHP                          | package
  | uwsgi-php7       | PHP7 Plugin for uWSGI                                     | package

Let us install php7-fpm and php7 packages, run:
$ sudo zypper install php7-fpm php7
Install PHP on OpenSUSE Linux using zypper

Verify PHP version

$ php -v # CLI version
$ php-fpm -v # FastCGI process manager for Nginx

PHP 7.4.6 (fpm-fcgi) 
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Enable the PHP FastCGI service

You need to use the systemctl command:
$ sudo systemctl enable php-fpm.service

Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/php-fpm.service

How to configure PHP with Nginx

Let us set up config files using the cd command and cp command
$ cd /etc/php7/fpm/
$ sudo cp -v php-fpm.conf.default php-fpm.conf

'php-fpm.conf.default' -> 'php-fpm.conf'

Edit the php-fpm.conf file using a text editor such as nano command/vim command:
$ sudo vi php-fpm.conf
Set open file descriptor rlimit for the master process:

; The default 1024 is too low:
rlimit_files = 20000

Save and close the file in vim. Next, we are going to set up a new pool called www as follows:
$ cd /etc/php7/fpm/php-fpm.d
$ sudo cp -v www.conf.default www.conf

'www.conf.default' -> 'www.conf'

Edit the www.conf, run:
$ sudo vi www.conf
Unix user/group of processes needed that will run php-fpm:

user = nginx
group = nginx

Enable PHP error log to file named php-scripts.log:

php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/nginx/php-scripts.log
php_admin_flag[log_errors] = on

Set resources and memory limits for PHP scripts for security reasons:

; set default value 
php_admin_value[memory_limit] = 128M

Start the PHP FastCGI service on OpenSUSE 15.2

$ sudo systemctl start php-fpm.service
The above command will start php-fpm at It is the address on which to accept FastCGI requests and we will configure Nginx.

Stop the PHP FastCGI service on OpenSUSE Linux

$ sudo systemctl stop php-fpm.service

Restart the PHP FastCGI service on OpenSUSE

$ sudo systemctl restart php-fpm.service

Check the status of the PHP FPM service

$ sudo systemctl status php-fpm.service

 php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-07-15 15:53:47 UTC; 6s ago
 Main PID: 3001 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 3
   CGroup: /system.slice/php-fpm.service
           ├─3001 php-fpm: master process (/etc/php7/fpm/php-fpm.conf)
           ├─3002 php-fpm: pool www
           └─3003 php-fpm: pool www

Jul 15 15:53:47 nixcraft-opensuse systemd[1]: Starting The PHP FastCGI Process Manager...
Jul 15 15:53:47 nixcraft-opensuse systemd[1]: Started The PHP FastCGI Process Manager.

Nginx and PHP configuration

Edit the nginx.conf or your virtual host domain file as follows:
$ sudo vi /etc/nginx/vhosts.d/
Update Nginx server block as follows:

        # PHP config #   
        location ~ \.php$ {
                # 404
                try_files                     $fastcgi_script_name =404;
                # default fastcgi_params
                include                       /etc/nginx/fastcgi_params;
                # fastcgi settings
                fastcgi_pass        ;
                fastcgi_index                 index.php;
                fastcgi_buffers               8 16k;
                fastcgi_buffer_size           32k;
                # fastcgi params
                fastcgi_param DOCUMENT_ROOT   $realpath_root;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

Save and close the file. Restart/reload php-fpm service:
$ sudo systemctl restart php-fpm.service

Searching PHP extensions

Use the zypper as follows along with the grep command:
$ sudo zypper search php7
# find module starting with 'm' #
$ sudo zypper search php7-m\*
$ sudo zypper search php7 | grep mysql

OpenSUSE search PHP modules

Installing PHP extensions

We can install MySQL database client for PHP as follows:
$ sudo zypper install php7-mysql
GD Graphics Library extension for PHP:
$ sudo zypper install php7-gd
A typical WordPress and MediaWiki installation needs the following modules:
$ sudo zypper install php7-gd php7-json php7-opcache php7-readline php7-redis php7-exif php7-gettext php7-zlib php7-imagick php7-iconv php7-ctype php7-curl php7-intl php7-mbstring php7-pdo php7-mysql php7-fileinfo php7-openssl php7-zip php7-dom
PHP 7 WordPress mediawiki OpenSUSE modules

Testing PHP

Create a new script in your DocumentRoot (set by root in nginx). For example:
$ vi /home/
Append the following PHP config:

   // phpinfo() - Show information about PHP's configuration on OpenSUSE Linux 15.2
   // Show just the PHP authors/credit information.
   // phpinfo(INFO_CREDITS);
   // See 

Run it as follows:

OpenSUSE phpinfo outputs
Click to enlarge


You learned how to install and test PHP 7.4 on your OpenSUSE Linux 15.2/15.1 server. See the following resources for more information:

This entry is 3 of 3 in the OpenSUSE Linux LEMP Stack Tutorial series. Keep reading the rest of the series:
  1. Install and use Nginx on OpenSUSE Linux
  2. Secure Nginx with Let's Encrypt on OpenSUSE Linux
  3. Install PHP on OpenSUSE Linux 15.2/15.1

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


2 comment

  1. Why OpenSUSE? What advantage am I getting with OpenSUSE? Why not Ubuntu? Ubuntu/RHEL seems like industry-leading distribution in North America.

Leave a Comment