Premium Shogun 4614 Posted April 29, 2014 Premium Share Posted April 29, 2014 (edited) Today I will explain you how to set up the nginx webserver in FreeBSD. While Apache has a long tradition, it has been overtaken performance wise by newer, more robust software like nginx, as can be seen in this comparisongraph: Setting up is even simpler than Apache. First we will build the nginx binaries. We have 2 choices, the stable version, and the development or beta version ("nginx-devel"). We will install the stable version in this tutorial. The first thing is downloading the FreeBSD ports collection to our server: portsnap fetch extractOr if we already ran this command earlier we can just update the ports that have been changed with: portsnap fetch update Then we navigate to the folder and build nginx: cd /usr/ports/www/nginx make config install clean Make sure PHP-FPM and CLI versions are marked here. You can use up/down arrow and space to navigate through the list of options. When we are done, all we have to do is just press enter and wait for the package to be compiled, which may take some minutes. If you want nginx to be started automatically on reboot, add the following lines to /etc/rc.conf: nginx_enable="YES"Next we need to configure nginx. The configuration file is found in /usr/local/etc/nginx/nginx.conf and you can overwrite the default with the one I'm providing next: user www; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; keepalive_timeout 20; server { listen 80; server_name mydomain.com; root /usr/local/www/nginx; index index.php; location @missing { rewrite ^ $scheme://$host/index.php permanent; } location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; include fastcgi_params; } location ~ /. { deny all; } } }The only thing you need to change here (in principle) is the ServerName directive you must enter your domain name here instead of mydomain.com Now we are ready to serve pages, but since we will not be serving a static website, we need also php-fpm. We will be installing version 5.5 of the PHP language which is the latest available at this moment in the ports. pkg install lang/php55Besides php, we will most likely need some extensions for our website. We already updated our ports collection earlier so we will just navigate to the php55-extensions folder: cd /usr/ports/lang/php55-extensions make config install cleanWe will be shown a long list of modules we can install. For example, we will be most likely using MySQL, so mark this module (SPACE key). PDO, MYSQLi and CURL are also used quite often. After we chose our desired modules, we can press enter and wait for all the modules to build. This can take quite a while! Finally, we set PHP-FPM to be started on reboot as well adding the following line to rc.conf php_fpm_enable="YES"That's all! Now it's time to upload our website to the /usr/local/www/nginx folder and start our webserver: service nginx start service php-fpm startIf there is anything wrong, we can check the access and error logs: tail -f /var/log/nginx-error.log Edited August 18, 2022 by Metin2 Dev Core X - External 2 Internal 10 Link to comment Share on other sites More sharing options...
nagattoxg 2 Posted May 18, 2014 Share Posted May 18, 2014 And when you go to IP of freebsd, in there says that we have to configure a nginx... Link to comment Share on other sites More sharing options...
Premium Shogun 4614 Posted May 18, 2014 Author Premium Share Posted May 18, 2014 I don't understand what you mean Link to comment Share on other sites More sharing options...
.JαyZoN 41 Posted May 20, 2014 Share Posted May 20, 2014 You forgot a lot of things. On a fresh and new system there is no pkg with the name "dialog4ports" so there can't be "a list of options". pkg_add -r php55 This will not longer work. So install this from ports is correct. (cd /usr/ports/lang/php55 && make install clean) cd /usr/ports/devel/php55-extensions is also not correct. The extensions are placed in /usr/ports/lang/php55-extensions. You should try to follow your guide with a fresh system. (maybe with a VM?) However, it's no offense. I am using nginx for a long time so i can say it's really better than apache. The graphs are telling the rest. Link to comment Share on other sites More sharing options...
Premium Shogun 4614 Posted May 23, 2014 Author Premium Share Posted May 23, 2014 You forgot a lot of things. On a fresh and new system there is no pkg with the name "dialog4ports" so there can't be "a list of options". pkg_add -r php55 This will not longer work. So install this from ports is correct. (cd /usr/ports/lang/php55 && make install clean) cd /usr/ports/devel/php55-extensions is also not correct. The extensions are placed in /usr/ports/lang/php55-extensions. You should try to follow your guide with a fresh system. (maybe with a VM?) However, it's no offense. I am using nginx for a long time so i can say it's really better than apache. The graphs are telling the rest. Thansks for pointing out the error in the extensions path. But I would say that dialog4ports stuff is installed automatically. Link to comment Share on other sites More sharing options...
Strzikjav 0 Posted May 26, 2014 Share Posted May 26, 2014 Where is the main Directory to view webpages? €: found it myself, with your config it's "usr/local/www/ngix-dist" Link to comment Share on other sites More sharing options...
DaCookie -Raven 35 Posted May 26, 2014 Share Posted May 26, 2014 very usefull^^ i tried this some years ago but i failed xD thanks for this tut now i know what to do^^ Link to comment Share on other sites More sharing options...
Premium Shogun 4614 Posted May 26, 2014 Author Premium Share Posted May 26, 2014 Where is the main Directory to view webpages? In nginx.conf: root /usr/local/www/nginx; But you can change this to whatever you want. Just make sure it's readable by the www user. Link to comment Share on other sites More sharing options...
ѕeмa™ 308 Posted February 25, 2015 Share Posted February 25, 2015 (edited) I have errors when i try install php extensions: Someone know why i have this errors? Edited August 19, 2022 by Metin2 Dev Core X - External 2 Internal https://m2admin.net/ Link to comment Share on other sites More sharing options...
Shichirojii 8 Posted February 25, 2015 Share Posted February 25, 2015 Me the index is blank. Any solution? Link to comment Share on other sites More sharing options...
Reboot 772 Posted February 25, 2015 Share Posted February 25, 2015 Me the index is blank. Any solution? Best solution Link to comment Share on other sites More sharing options...
ѕeмa™ 308 Posted March 2, 2015 Share Posted March 2, 2015 Me the index is blank. Any solution? I have the same error, when i try enter in my website is blank but the phpinfo() read fine. Any solutions? Freebsd 9.2 https://m2admin.net/ Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now