{"id":1835,"date":"2019-01-02T10:53:49","date_gmt":"2019-01-02T07:53:49","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1835"},"modified":"2024-03-11T22:10:13","modified_gmt":"2024-03-11T19:10:13","slug":"install-nginx-mysql-php-femp-stack-on-freebsd-12","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-nginx-mysql-php-femp-stack-on-freebsd-12\/","title":{"rendered":"Install FEMP Stack on FreeBSD 12"},"content":{"rendered":"\n<figure class=\"gb-block-image gb-block-image-5aea2905\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"463\" class=\"gb-image gb-image-5aea2905\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/femb-stack.png\" alt=\"Install FEMP Stack on FreeBSD 12\" title=\"femb-stack\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/femb-stack.png?v=1685872128 780w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/femb-stack-768x456.png?v=1685872128 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/figure>\n\n\n\n<p>In this tutorial, we are going to learn how to install FEMP Stack on FreeBSD 12. Just like FAMP Stack, FEMB Stack is an acronym for <strong>F<\/strong>reeBSD, the Operating System, <strong>E<\/strong>ngine-X (Nginx) the web server, <strong>M<\/strong>ySQL the database server and<strong> P<\/strong>HP the server side scripting language.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-femp-stack-on-free-bsd-12\">Installing FEMP Stack on FreeBSD 12<\/a><ul><li><a href=\"#update-package-repository\">Update Package Repository<\/a><\/li><li><a href=\"#install-nginx-on-free-bsd-12\">Install Nginx on FreeBSD 12<\/a><ul><li><a href=\"#start-and-enable-nginx\">Start and Enable Nginx<\/a><\/li><\/ul><\/li><li><a href=\"#configure-nginx\">Configure Nginx<\/a><\/li><li><a href=\"#install-my-sql-on-free-bsd-12\">Install MySQL on FreeBSD 12<\/a><ul><li><a href=\"#start-and-enable-my-sql-service\">Start and Enable MySQL Service<\/a><\/li><li><a href=\"#run-my-sql-initial-secure-script\">Run MySQL Initial Secure Script<\/a><\/li><\/ul><\/li><li><a href=\"#install-php-on-free-bsd-12\">Install PHP on FreeBSD 12<\/a><ul><li><a href=\"#configure-php\">Configure PHP<\/a><\/li><li><a href=\"#configure-php-fpm\">Configure PHP-FPM<\/a><\/li><li><a href=\"#configure-nginx-to-work-with-php-processor\">Configure Nginx to work with PHP processor<\/a><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-femp-stack-on-free-bsd-12\">Installing FEMP Stack on FreeBSD 12<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"update-package-repository\">Update Package Repository<\/h3>\n\n\n\n<p>Ensure your system is up-to-date by running the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">freebsd-update fetch\nfreebsd-update install<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nginx-on-free-bsd-12\">Install Nginx on FreeBSD 12<\/h3>\n\n\n\n<p>Nginx Web server is available on the default FreeBSD repositories and can be installed using the <code>pkg<\/code> package manager command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pkg install nginx<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"start-and-enable-nginx\">Start and Enable Nginx<\/h4>\n\n\n\n<p>To enable Nginx web server to run on system boot, run the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sysrc nginx_enable=yes<\/code><\/pre>\n\n\n\n<p>This will add the line <code>nginx_enable=\"yes\"<\/code> at the end of the <code>\/etc\/rc.conf<\/code> configuration file.<\/p>\n\n\n\n<p>Start Nginx<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service nginx start<\/pre>\n\n\n\n<p>You can check the status of Apache as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>service nginx status<\/strong><\/pre>\n\n\n\n<pre id=\"block-243dfd0f-2ae4-4bcd-8dfd-ee05e651f403\" class=\"wp-block-preformatted\">nginx is running as pid 2959.<\/pre>\n\n\n\n<p>Similarly, start and enable PHP-FPM to run on system boot;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sysrc php_fpm_enable=\"YES\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>service php-fpm start<\/code><\/pre>\n\n\n\n<p>To verify that you can actually access you web server from the browser, navigate to the browser and type the IP address of your web server. If everything is working fine, you should be able to see the default FreeBSD Nginx welcome page headed, <code>\"<strong>Welcome to nginx!<\/strong>\"<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-nginx\">Configure Nginx<\/h3>\n\n\n\n<p>The default configuration file for Nginx resides under <code>\/usr\/local\/etc\/nginx<\/code> as <code>nginx.conf<\/code>.<\/p>\n\n\n\n<p>Open the configuration file for editing and proceed as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/usr\/local\/etc\/nginx\/nginx.conf<\/pre>\n\n\n\n<p>Set the <code>user<\/code> that Nginx uses for normal operations to <code>www<\/code> by uncommenting the line <code>#user nobody<\/code> and making appropriate substitution.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">user www;<\/pre>\n\n\n\n<p>Set the value of the <code>worker_processes<\/code> directive to the number same as the number of CPU cores of your server. By default, it is set to 1.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">worker_processes 2;<\/pre>\n\n\n\n<p>Uncomment the error log file directive and set the logging level to information.<\/p>\n\n\n\n<pre>error_log &#x2F;var&#x2F;log&#x2F;nginx&#x2F;error.log info;\n<\/pre>\n\n\n\n<p>Uncomment the access log file directive under <code>http<\/code> block and set the value as follows;<\/p>\n\n\n\n<pre>access_log &#x2F;var&#x2F;log&#x2F;nginx&#x2F;access.log;<\/pre>\n\n\n\n<p>Set the value of the <code>server_name<\/code> directive under <code>server<\/code> block to the hostname or IP address of your server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sever_name kifarunix-demo.com;<\/pre>\n\n\n\n<p>Configure Nginx to server PHP content by adding index.php as the first value of <code>index<\/code> directive.<\/p>\n\n\n\n<p>Remove the document root and index directives under the <strong>location block<\/strong> and define them under the server block context.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u00a0   server {\n        listen       80;\n        server_name  kifarunix-demo.com;\n        ...\n<strong>        root   \/usr\/local\/www\/nginx-dist;<\/strong>\n<strong>        index  index.php index.html index.htm;\n<\/strong>\n<strong>        location \/ {<\/strong>\n<strong>\t\ttry_files $uri $uri\/ =404;<\/strong>\n<strong>        }<\/strong>\n<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Restart Nginx;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx  -t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx: the configuration file \/usr\/local\/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/usr\/local\/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n<p>Restart if there is no error;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service nginx restart<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-my-sql-on-free-bsd-12\">Install MySQL on FreeBSD 12<\/h3>\n\n\n\n<p>Just like Nginx, MySQL can be installed directly from default FreeBSD 12 default repositories using the package manager. To install MySQL 8.0, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pkg install mysql80-server<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"start-and-enable-my-sql-service\">Start and Enable MySQL Service<\/h4>\n\n\n\n<p>Enable MySQL as a service so it can start on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sysrc mysql_enable=yes<\/pre>\n\n\n\n<p>Start MySQL<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">service mysql-server start<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"run-my-sql-initial-secure-script\">Run MySQL Initial Secure Script<\/h4>\n\n\n\n<p>Run the normal MySQL security script to remove some default configurations.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql_secure_installation<\/pre>\n\n\n\n<p>The script may prompt you whether to enforce strong password creation. If you need to enforce secure password creation, then press&nbsp;<strong>y&nbsp;<\/strong>to accept and choose the level of password validation policy.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n\nVALIDATE PASSWORD COMPONENT can be used to test passwords\nand improve security. It checks the strength of password\nand allows the users to set only those passwords which are\nsecure enough. Would you like to setup VALIDATE PASSWORD component?\n\nPress y|Y for Yes, any other key for No: y\n\nThere are three levels of password validation policy:\n\nLOW    Length &gt;= 8\nMEDIUM Length &gt;= 8, numeric, mixed case, and special characters\nSTRONG Length &gt;= 8, numeric, mixed case, special characters and dictionary file\n\nPlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1\nPlease set the password for root here.\n\nNew password: <strong>STRONG PASS<\/strong>\n\nRe-enter new password: <strong>STRONG PASS<\/strong>\n\nEstimated strength of the password: 100 \nDo you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y\n\n<\/code><\/pre>\n\n\n\n<p>Next;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>remove anonymous users,<\/li>\n\n\n\n<li>disallow remote root login,<\/li>\n\n\n\n<li>remove test databases<\/li>\n\n\n\n<li>reload privilege tables to effect the changes.<\/li>\n<\/ul>\n\n\n\n<pre class=\"scroll-box\"><code>\n\nBy default, a MySQL installation has an anonymous user,\nallowing anyone to log into MySQL without having to have\na user account created for them. This is intended only for\ntesting, and to make the installation go a bit smoother.\nYou should remove them before moving into a production\nenvironment.\n\nRemove anonymous users? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\n\nNormally, root should only be allowed to connect from\n'localhost'. This ensures that someone cannot guess at\nthe root password from the network.\n\nDisallow root login remotely? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\nBy default, MySQL comes with a database named 'test' that\nanyone can access. This is also intended only for testing,\nand should be removed before moving into a production\nenvironment.\n\n\nRemove test database and access to it? (Press y|Y for Yes, any other key for No) : y\n - Dropping test database...\nSuccess.\n\n - Removing privileges on test database...\nSuccess.\n\nReloading the privilege tables will ensure that all changes\nmade so far will take effect immediately.\n\nReload privilege tables now? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\nAll done!\n\n<\/code><\/pre>\n\n\n\n<p>You can now login to your MySQL server and create your databases!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-php-on-free-bsd-12\">Install PHP on FreeBSD 12<\/h3>\n\n\n\n<p>PHP works with HTML to generate dynamic web content. In order for PHP to connect to MySQL database to retrieve information for serving to the web server, you need to install PHP Apache and MySQL extensions. The following command installs the most common PHP modules.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pkg install php82 php82-mysqli php82-mbstring php82-zlib php82-curl php82-gd<\/pre>\n\n\n\n<p>If you require other PHP extensions, you can simply search and install them as shown above.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-php\">Configure PHP<\/h4>\n\n\n\n<p>Copy the sample PHP configuration file into place.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp \/usr\/local\/etc\/php.ini{-production,}<\/pre>\n\n\n\n<p>Open the file <code>\/usr\/local\/etc\/php.ini<\/code> for editing the uncomment the line <code>;cgi.fix_pathinfo=1<\/code> and set its value to 0 so that PHP intepreter cannot processing files not found.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/usr\/local\/etc\/php.ini<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">;cgi.fix_pathinfo=1\ncgi.fix_pathinfo=0<\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-php-fpm\">Configure PHP-FPM<\/h4>\n\n\n\n<p>Configure PHP-FPM to listen on a Unix socket. By default, it listens on TCP port 9000 on localhost.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/usr\/local\/etc\/php-fpm.d\/www.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>;listen = 127.0.0.1:9000\n<strong>listen = \/var\/run\/php-fpm\/php-fpm.sock<\/strong><\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Create PHP-FPM unix socket directory and set proper ownership;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/var\/run\/php-fpm<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>chown -R www:www \/var\/run\/php-fpm<\/code><\/pre>\n\n\n\n<p>Restart PHP-FPM;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service php-fpm restart<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-nginx-to-work-with-php-processor\">Configure Nginx to work with PHP processor<\/h4>\n\n\n\n<p>Configure Nginx to work with PHP processor by uncommenting the lines under the <code>location<\/code> block with PHP configurations as shown below. Replace the TCP socket, <span class=\"st\"><code>127.0.0.1:9000;<\/code> with unix socket <\/span><code class=\"code-highlight language-nginx hljs \"><span class=\"hljs-url\">unix:\/var\/run\/php-fpm.sock<\/span>;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/usr\/local\/etc\/nginx\/nginx.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u00a0       location ~ \\.php$ {\n            try_files $uri =404;\n            fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n            fastcgi_pass   <strong>unix:\/var\/run\/php-fpm\/php-fpm.sock;<\/strong>\n            fastcgi_index  index.php;\n            fastcgi_param  SCRIPT_FILENAME $request_filename;\n            include        fastcgi_params;\n        }\n<\/code><\/pre>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Restart Nginx;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx  -t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx: the configuration file \/usr\/local\/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/usr\/local\/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n<p>Restart if there is no error;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service nginx restart<\/code><\/pre>\n\n\n\n<p>Create PHP test configuration file under the Nginx default document root directory to verify whether PHP is working well with Nginx web server. The default document root directory is <code>\/usr\/local\/www\/nginx-dist<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/usr\/local\/www\/nginx-dist\/test.php<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n\n\n\n<p>Verify that Nginx has not syntactical error and restart it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx -t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">nginx: the configuration file \/usr\/local\/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/usr\/local\/etc\/nginx\/nginx.conf test is successful<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">service nginx restart<\/pre>\n\n\n\n<p>Navigate to the browser and the address in the format, <code>http:\/\/server_IP_address\/test.php<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1056\" height=\"934\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/php-nginx-freebsd.png\" alt=\"Install FEMP Stack on FreeBSD 12\" class=\"wp-image-16993\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/php-nginx-freebsd.png?v=1685874629 1056w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/php-nginx-freebsd-768x679.png?v=1685874629 768w\" sizes=\"(max-width: 1056px) 100vw, 1056px\" \/><\/figure>\n\n\n\n<p>Beautiful. Now remove the test file from your server to avoid exposing the information about server to the public.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm -rf \/usr\/local\/www\/nginx-dist\/test.php<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-mariadb-10-5-on-freebsd-13\/\">Install MariaDB 10 on FreeBSD 13<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/upgrade-freebsd-12-to-13\/\" target=\"_blank\" rel=\"noreferrer noopener\">Upgrade FreeBSD 12 to 13<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to learn how to install FEMP Stack on FreeBSD 12. Just like FAMP Stack, FEMB Stack is an acronym<\/p>\n","protected":false},"author":1,"featured_media":16992,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,280,928,929,304,342,938,253],"tags":[6838,6839,6830],"class_list":["post-1835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-freebsd","category-mariadb","category-mysql","category-nginx","category-php","category-phpmyadmin","category-web-servers","tag-install-femb-on-freebsd","tag-install-mysql-8-on-freebsd","tag-install-php-8-on-freebsd","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1835"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1835"}],"version-history":[{"count":29,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1835\/revisions"}],"predecessor-version":[{"id":21104,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1835\/revisions\/21104"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16992"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}