Jump to content

How to setup nginx and php on FreeBSD to host your website

Recommended Posts

There instructions have been tested on FreeBSD 12.1!


First of all we want to install update the package repository:

pkg update


If you have never used pkg probably you will be asked to install it.


Now run this command to install php7.4 and nginx


pkg install php74 nginx


We can install the most common php extensions running this command:


 pkg install php74-extensions php74-mysqli php74-mbstring php74-curl php74-gd


The following extensions will be installed:

		php74-ctype: 7.4.14
        php74-curl: 7.4.14
        php74-dom: 7.4.14
        php74-extensions: 1.0
        php74-filter: 7.4.14
        php74-gd: 7.4.14
        php74-iconv: 7.4.14
        php74-json: 7.4.14
        php74-mbstring: 7.4.14
        php74-mysqli: 7.4.14
        php74-opcache: 7.4.14
        php74-pdo: 7.4.14
        php74-pdo_sqlite: 7.4.14
        php74-phar: 7.4.14
        php74-posix: 7.4.14
        php74-session: 7.4.14
        php74-simplexml: 7.4.14
        php74-sqlite3: 7.4.14
        php74-tokenizer: 7.4.14
        php74-xml: 7.4.14
        php74-xmlreader: 7.4.14
        php74-xmlwriter: 7.4.14


Enable nginx and php service to automatically start

sysrc nginx_enable=yes
sysrc php_fpm_enable=YES


We can start nginx and php for the first time by running

service nginx start
service php-fpm start


You can open now your web browser and type the server ip in the address bar.

You should see a page like this



We are going to configure nginx now. Open the file nginx.conf located in /usr/local/etc/nginx and modify the section "server":


    server {
        listen       80;
        server_name  _;
		root   /var/www;
        index  index.php index.html index.htm;

        location / {
			try_files $uri $uri/ =404;

        location ~ \.php$ {
			try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $request_filename;
            include        fastcgi_params;
        location ~ /\.ht {
            deny  all;


Change mydomainname.com with your domain  (or server ip).


We can test now if php is working correctly.


The files of your webiste will be hosted in the folder /var/www (you can change it in the configuration above). Create a new file inside that folder and call it index.php with this content:



Now open again the browser and type the ip address/domain name and you should see something like this:




The server is working properly and you can upload now your script :)


You might need to install more php extentions according to the requirements of  your script

  • Love 2
  • Good 2
Link to post
  • 3 weeks later...

dont work

Starting php_fpm.
/usr/local/sbin/php-fpm: Undefined symbol "[email protected]_1.5"
[23-Feb-2021 12:13:11] ERROR: no data have been read from pipe
/usr/local/etc/rc.d/php-fpm: WARNING: failed to start php_fpm

Edited by Bizzy
Link to post
On 2/23/2021 at 8:55 PM, Bizzy said:

is fixed i switch to freebsd 12.1 and is okay sry :) can you make a tutorial for ishop or so? ^^

You have to purchase an item shop script or get one for free in the internet and host it on your server. You have just to throw the ishop folder inside /var/www

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Activity

    1. 0

      Compile Server

    2. 0

      QC error message for special characters next to apostrophes

    3. 135

      Render Target Remastered

    4. 0

      Mount not attacking

    5. 2

      Rodnia2 | PVM | International | 3k+ players | Multiple-Languages | 2nd server opening: 13.02.2021

    6. 218

      WorldEditor ReMIX

    7. 54

      Quiver System

  • Recently Browsing

    No registered users viewing this page.



Chatroom Rules


Join our Discord

A request for help = Shoutbox Ban

Be respectful & Respect the rules


  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.