قالب وردپرس درنا توس
Home / How To / How to set FEMP Stack (FreeBSD, Nginx, MySQL 8 and PHP 7.4) on FreeBSD 12

How to set FEMP Stack (FreeBSD, Nginx, MySQL 8 and PHP 7.4) on FreeBSD 12



A FEMP stack, similar to a LEMP stack on Linux, is a collection of open source software that is usually installed together to allow a FreeBSD server to host dynamic websites and web applications. FEMP is an abbreviation for F reeBSD (operating system), Nginx (HTTP server pronounced E ngine-x), M ySQL (database server), and P HP (programming language for processing dynamic PHP content).

In this tutorial, we install components in a FEMP stack on a FreeBSD 12.1 server with pkg the FreeBSD package manager.

Requirements

Before you start this guide, you need the following:

  • A FreeBSD 1
    2.1.
  • A user with root privileges or sudo user to make configuration changes.
  • Basic knowledge of the FreeBSD system and command line interface is recommended.

Initial steps

Check the FreeBSD version.

  uname -ro 
# FreeBSD 12.1-RELEASE [19659011] Make sure your FreeBSD system is up to date.

  freebsd-update fetch install 
pkg update && pkg upgrade -y

Install neces sary package.

  pkg install -y sudo vim bash curl 

Create a new user account with your username. We use johndoe .

  adduser 
# Username: johndoe
# Full name: John Doe
# Uid (Leave blank by default):
# Login group [johndoe]:
# Login group is johndoe. Invite johndoe to other groups? []: wheels
# Login class [default]:
# Shell (sh csh tcsh nology) [sh]: bash
# Home directory [/home/johndoe]:
# Home directory permissions (Leave blank by default) :
# Use password-based authentication? [yes]:
# Use an empty password? (yes / no) [no]:
# Use a random password? (yes / no) [no]:
# Enter password: your_secure_password
# Re-enter password: your_secure_password
# Unlock account after creation? [no]:
# OK? (yes / no): yes
# Add another user? (yes / no): no
# goodbye!

Run visudo and divide the % wheel ALL = (ALL) ALL line so that members of the wheel group to execute all commands.

  visudo 

# Uncomment by removing hash (#) sign
#% wheel ALL = (ALL) ALL

Now, switch to your newly created user with su :

  su - johndoe 

NOTE: Replace johndoe with your username.

Set up time zone:

  sudo tzsetup 

Step 1 - Install mainline Nginx

Nginx web server is currently one of the most popular web servers in the world. It is a great choice for web hosting.

You can install Nginx with FreeBSD's package manager, pkg . A package manager allows you to install most software without any problem from an archive maintained by FreeBSD. You can learn more about how to use pkg here.

To install the latest mainline Nginx, issue the following command:

  sudo pkg install -y nginx-devel 

Check the version:

  nginx -v 
# nginx version: nginx / 1.17. 7

This command installs the latest mainline version, which can be reliably used on a production server. To install the latest stable version, use only the nginx package instead of nginx-devel .

Now, enable and start Nginx:

  sudo sysrc nginx_enable = yes 
sudo service nginx start

To verify that Nginx has started, you can run the following command:

  sudo service nginx status [19659012] As a result, you see something similar: 

  # Output 
nginx runs as pid 17607.

You can verify that Nginx was installed and working without error by visiting the server's public IP address in your browser. Navigate to your_server_IP . You see the standard "Welcome to nginx!" page.

Step 2 - Install MySQL 8.0

Now that your web server is running, it's time to install MySQL, relational database management system. The MySQL server will organize and provide access to databases where your server can store information.

Again, you can use pkg to get and install your software.

To install MySQL 8.0 with pkg use this command:

  sudo pkg install -y mysql80-client mysql80 server 

This command installs the latest version of The MySQL client and server, which is currently 8.xx .

Check Version:

  mysql --version 
# mysql Ver 8.0.17 for FreeBSD12.0 on amd64 (Source Distribution)

Now, enable and start MySQL:

  sudo sysrc mysql_enable = yes 
sudo service mysql-server start

To verify that MySQL has started, you can run the following command:

  sudo service mysql-server status 

You will see something like the following:

  # Output 
mysql runs as pid 19066.

As a good practice, you must run mysql_secure_installation security script that will remove some insecure defaults and somewhat restrict access to your database system.

  sudo mysql_secure_installation 

You will be prompted to set a password, followed by some other questions. Enter a strong password and then press the rest of the questions ENTER to select default values.

Step 3 - Install PHP 7.4

PHP is a server-side scripting language designed for web development. PHP is an indispensable component of the FEMP stack. Python or Perl is often used instead of PHP. But PHP as the most popular option is most often used. Along with the database, it will give your websites or apps dynamic behavior.

Again utilize the pkg system to install PHP components.

To install PHP 7.4 with pkg run this command:

  sudo pkg install -y php74 

Check the PHP version:

  php - version 
# PHP 7.4.0 (cli) (built: 18 Jul 2019 01:14:37) (NTS)
# Copyright (c) 1997-2018 PHP Group
# Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies

This command will install the latest version of PHP, 7.4 .

Now, enable and start PHP-FPM:

  sudo sysrc php_fpm_enable = yes 
sudo service php-fpm start

To verify that PHP-FPM has started, you can run the following command:

  sudo service php-fpm status 

As a result, you see something similar:

  # Output 
php_fpm runs as pid 23005.

Install PH P modules (optional)

To improve PHP You can optionally install some additional modules.

To see currently compiled in PHP modules, you can run this:

  php -m 

# [19659084] # Core # date
# libxml
# mysqlnd
# pcre
# Reflection
# SPL
# standard
# [Zend Modules]

To search for available PHP modules, you can use this command:

  pkg search ^ php74 - * 

The results are mostly PHP 7.4 modules that you can install:

  # Output 
# php74-7.4. 7 PHP scripting language
# php74-Ice37-3.7.2 Modern alternative to object's middleware such as CORBA / COM / DCOM / COM +
# php74-aphpbreakdown-2.2.2 PHP Compatibility Check Code Analyzer
# php74 -aphpunit-1.8 Test frame for unit tests
# php74-bcmath-7.4.7 bcmat h split extension for php
# php74-fragli-0.7.0 Brotli extension for PHP
# php74-bsdconv-11.5. 0 PHP cover for bsdconv
# php74-bz2-7.4.7 The shared bz2 extension for php
# php74-calendar-7.4.7 The shared calendar extension for php
# php74-composer-1.8 .6 Dependency Manager for PHP
# php74-ctype-7.4.7 The shared ctype extension for php
# php74-curl-7.4.7 Curl shared extension for php
#. . .

If, after researching, you decide that you need to install a package, you can do so by using the command pkg install . Most PHP web applications will require additional modules, so it's good to know how to search for them.

Step 4 - Configure Nginx to use PHP module

Before using PHP, you must configure it to work with Nginx. [19659002] Run sudo vim /usr/local/etc/nginx/test.confebrit19459007] and fill in the file with the content below:

  server {

listen 80;
server name SERVER_IP; # Replace with your IP or host name
root / usr / local / www / nginx-dist;
index index.php index.html index.htm;

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

location ~  .php $ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}

}

Save the file and exit from vim.

Now we need to include test.conf in the main file nginx.conf . The main Nginx configuration file lives under / usr / local / etc / nginx as nginx.conf .

Run sudo vim / usr / local / etc / nginx /nginx.confebrit19459007] to open the main configuration file in Vim and add the following line to the block http {} .

  include test.conf; 

Test Nginx Configuration: [19659010] sudo nginx -t

Because you have made configuration changes to Nginx, you must reload the service for those to be applied. Otherwise, Nginx still works with the previous configuration:

  sudo service nginx reload 

Step 5 - Test PHP processing

To test that your system is configured correctly for PHP, you can create a very basic PHP script. You will call this script info.php . By default, the root is set to / usr / local / www / nginx-dist . You can create the info.php file under that location by typing:

  sudo vim /usr/local/www/nginx-dist/info.phpebrit19659011achteAnd add this code to that file: [19659010]  

Navigate to http: //your_server_IP/info.php and you will see the following page:

After installing and installing the FEMP stack, you should delete the info.php file to avoid revealing information about the server to the public:

  sudo rm / usr / local / www / nginx-dist / info.php 

Conclusion

Congratulations, you have installed a FEMP stack on your FreeBSD 12.1 VPS. Now you have several choices for what to do next. You have installed a platform that allows you to install most types of websites and web software on top of it.


Source link