Tutorial requirements | |
---|---|
Operating system/app | OpenSUSE Linux with Nginx |
Root privileges required | Yes |
Difficulty | Easy (rss) |
Estimated completion time | 10m |
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
Verify PHP version
Type:
$ 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/multi-user.target.wants/php-fpm.service → /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 127.0.0.1:9000. 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/www.cyberciti.biz.conf
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 127.0.0.1:9000; 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
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
Testing PHP
Create a new script in your DocumentRoot (set by root in nginx). For example:
$ vi /home/cyberciti.biz/http/test.php
Append the following PHP config:
<?php // phpinfo() - Show information about PHP's configuration on OpenSUSE Linux 15.2 phpinfo(); // Show just the PHP authors/credit information. // phpinfo(INFO_CREDITS); // See php.net/phpinfo ?>
Run it as follows:
https://your-domain/test.php
https://www.cyberciti.biz/test.php
Conclusion
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:
- Linux 25 PHP security security best practices for sys admins.
- PHP.INI settings Disable exec, shell_exec, system, popen and other functions to improve security.
- See Nginx documentation here, OpenSUSE wiki here and PHP documents here.
- Install and use Nginx on OpenSUSE Linux
- Secure Nginx with Let's Encrypt on OpenSUSE Linux
- Install PHP on OpenSUSE Linux 15.2/15.1
🐧 2 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Why OpenSUSE? What advantage am I getting with OpenSUSE? Why not Ubuntu? Ubuntu/RHEL seems like industry-leading distribution in North America.
OpenSUSE ans SUSE Linux is a popular choice outside USA.