Linux Tutorials

FreeBSD set up PHP 7.2 with FPM for Nginx

SEOClerks

How do I set up set up PHP 7.2 with FPM for Nginx internet server operating on FreeBSD working system?

Introduction: PHP is an acronym for “PHP: Hypertext Preprocessor.” It’s an open supply general-purpose scripting language. PHP is helpful for internet growth and to run widespread software program equivalent to MediaWiki, WordPress, and extra. PHP is straightforward to be taught and permits you to write dynamically generated internet pages on the fly. This web page reveals how you can set up PHP 7.2 on a FreeBSD v11.x Unix field together with Nginx internet server.

FreeBSD set up PHP 7.2 with FPM for Nginx

The process for putting in PHP 7.2 on FreeBSD is as follows:

Replace FreeBSD ports treeInstall PHP 7.2 binary bundle: pkg set up nginxInstall Nginx binary packageConfigure Nginx and PHP 7.2Turn on PHP-fpm service on FreeBSDTest the setup

Allow us to see all steps in particulars.

1. Replace FreeBSD ports tree

It’s essential to use the portsnap command
# portsnap fetch replace
Removing on ports and updating FreeBSD ports tree

2. Set up PHP 7.2 on FreeBSD

You’ll be able to set up PHP 7.2 utilizing ports or binary bundle technique. Use any one of many following strategies.

The ports technique

# cd /usr/ports/lang/php72/
# make set up clear
Install the PHP 7.2 port on FreeBSD

The binary bundle technique

Run the pkg command to put in it:
# pkg set up php72
FreeBSD install PHP 7.2 with FPM for Nginx with pkg command

Three. Set up PHP 7.2 extensions on FreeBSD

Once more PHP extensions may be put in utilizing the ports or pkg technique. Use any one of many following methods.

To put in the port, run the next command and select required extensions:
# cd /usr/ports/lang/php72-extensions/ && make set up clear
How to install meta-port to install PHP extensions on FreeBSD
OR add the binary bundle:
# pkg set up php72-extensions
How to install PHP 7.2 with extensions on FreeBSD Unix box
An alternative choice is putting in particular person PHP extensions as per your internet software or software program challenge wants. One can search PHP 7.2 extensions utilizing the pkg command and grep command/egrep command
# pkg search php72 | grep gd
# pkg search php72 | egrep -i –color ‘gd|mysqli|openssl’
# pkg search php72 | egrep –color -i — ‘-(gd|mysqli|openssl|memcached|opcache|json|mbstring|imagick|xml|zip|composer|igbinary)-‘
FreeBSD Installing Required PHP Extensions
Merely set up it:
# pkg set up php72-composer php72-gd php72-json
### OR ###
# pkg set up php72-composer-1.6.5 php72-gd-7.2.10 php72-json-7.2.10 php72-mbstring-7.2.10 php72-mysqli-7.2.10 php72-opcache-7.2.10 php72-openssl-7.2.10 php72-pecl-imagick-Three.four.3_2 php72-pecl-memcached-Three.zero.four php72-xml-7.2.10 php72-zip-7.2.10 php72-pecl-igbinary-2.zero.7

four. Configure PHP-FPM

Edit the file /usr/native/and so on/php-fpm.d/www.conf
# vi /usr/native/and so on/php-fpm.d/www.conf
Discover line:
pay attention = 127.zero.zero.1:9000
Replace it as follows:
pay attention = /var/run/php72-fpm.sock
Uncomment the next line:
pay attention.proprietor = www
pay attention.group = www
pay attention.mode = 0660
Save and shut the file. Allow php-fpm service:
# sysrc php_fpm_enable=YES
Instructions to begin, cease, restart php-fpm service on FreeBSD server:
# service php-fpm cease
# service php-fpm begin
# service php-fpm restart
# service php-fpm standing
FreeBSD start stop restart PHP-fpm service commands

A notice about PHP 7 config

You could set up php.ini file utilizing the php command:
# cp -v /usr/native/and so on/php.ini-production /usr/native/and so on/php.ini
/usr/native/and so on/php.ini-production -> /usr/native/and so on/php.ini
Subsequent, we’re going to safe PHP and customise it:
# vi /usr/native/and so on/php/99-custom.ini
Add the next config:

display_errors=Off
safe_mode=Off
safe_mode_exec_dir=
safe_mode_allowed_env_vars=PHP_
expose_php=Off
log_errors=On
error_log=/var/log/nginx/php.scripts.log
register_globals=Off
cgi.force_redirect=zero
file_uploads=On
allow_url_fopen=Off
sql.safe_mode=Off
disable_functions=show_source, system, shell_exec, passthru, proc_open, proc_nice, exec
max_execution_time=60
memory_limit=60M
upload_max_filesize=2M
post_max_size=2M
cgi.fix_pathinfo=zero
sendmail_path=/usr/sbin/sendmail -fwebmaster@cyberciti.biz -t

Save and shut the file. Restart the PHP on FreeBSD:
# service php-fpm restart

5. Configure Nginx to make use of PHP 7.2 (PHP-FPM)

The ultimate step is connecting Nginx to PHP-FPM service through the FCGI protocol. Edit your Digital Area or nginx.conf file as follows:
# cd /usr/native/and so on/nginx
# vi nginx.conf
OR
# vi vdomains/http.192.168.2.31.conf
Right here is an up to date pattern config file:

server $)
fastcgi_split_path_info ^(.+?.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name)
return 404;

 
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY “”;
 
fastcgi_pass unix:/var/run/php72-fpm.sock;
fastcgi_index index.php;
 
# embody the fastcgi_param setting
embody fastcgi_params;
 
# SCRIPT_FILENAME parameter is used for PHP FPM figuring out
# the script title.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Reload or restart the Nginx server:
# service nginx reload

6. Check the setup

Create a PHP script known as take a look at.php in /wwwwiki/
# vi /wwwwiki/take a look at.php
Append the next code that reveals details about PHP’s configuration utilizing phpinfo:

Save and shut the file. Set tight file permissions on DocumentRoot (internet server root):
# chown -R wwwwiki:wwwwiki /wwwwiki/
# chmod -R 0555 /wwwwiki/
Fireplace an internet browser and take a look at it:
http://192.168.2.31/take a look at.php
http://your-domain-name-here/take a look at.php
Nginx PHP-7.2-fpm running on FreeBSD
And there you might have PHP working as anticipated and Nginx is speaking to PHP-FPM through Unix socket.

How one can confirm that PHP-fpm operating

Use the sockstat command on FreeBSD to checklist operating providers, open ports and unix sockets:
# sockstat -46lu | egrep –color ‘www|nginx|php’
Additionally examine log recordsdata for those who get any issues operating PHP:
# ls -l /var/log/nginx/
# tail -f /var/log/nginx/192.168.2.31.error.log
Verify open ports on FreeBSD ThumbClick on to enlarge picture

Conclusion

This information demonstrated how you can set up PHP FPM securely and configured it utilizing unix socket. Now you might have totally working Nginx server together with PHP 7.2 for creating dynamic internet pages on demand. Subsequent a part of the sequence reveals how you can set up a database server to construct a completely purposeful internet server operating on a FreeBSD working system.

Posted by: Vivek Gite

The creator is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply matters through RSS/XML feed or weekly electronic mail publication.

Source link

Related Articles

Leave a Reply

Back to top button