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

spacer.png

 

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_pass   127.0.0.1:9000;
            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:

<?php
phpinfo();

 

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

 

spacer.png

 

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

  • Metin2 Dev 1
  • Good 2
  • Love 3
Link to comment
Share on other sites

  • 3 weeks later...
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 comment
Share on other sites

  • 2 years later...

Does it work for freebsd 13.2?

“To be humble with superiors is duty, with equals is courtesy, with inferiors is nobility.”
Benjamin Franklin

 

Por favor, desative seu AdBlock quando usar meus links de download.

Please, disable your 
AdBlock when use my download links.

Me

AdBlock 
On:   


699691-icon-20-sad-face-eyebrows-48.png

 

Adblock Off:  



Streamline-65-48.png

 

 

Angry One Piece GIF by Toei Animation

Link to comment
Share on other sites

  • 1 month later...

Announcements



×
×
  • 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.