How To Install Nginx, MySQL and PHP (FEMP) Stack on FreeBSD 13.0
1. First, update your FreeBSD system.
# freebsd-update fetch
# freebsd-update install
2. Install Nginx.
# pkg install nginx
Enable Nginx:
# sysrc nginx_enable=yes
Start Nginx:
# service nginx start
Check if nginx is running normally?
It worked.
3. Install MySQL
# pkg install mysql80-client mysql80-server
Enable MySQL:
# sysrc mysql_enable=yes
Start MySQL:
# service mysql-server start
Starting mysql.
4. Install PHP
The following command to install php8.0 and commonly used modules:
# pkg install php74 php74-mysqli php74-mbstring php74-zlib php74-curl php74-gd php74-json
5. Configure Nginx and PHP to make them work together
Edit Nginx's config file /usr/local/etc/nginx/nginx.conf uncomment or modify or add config as follows:
user www;
error_log /var/log/nginx/error.log;
http block:
access_log /var/log/nginx/access.log;
location ~ \.php$ {
root /usr/local/www/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
root /usr/local/www/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Restart Nginx:
# service nginx restart
Configure php-fpm
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Open file /usr/local/etc/php.ini and uncomment out ;cgi.fix_pathinfo=1 and change it's value to 0.
Enable php-fpm:
# sysrc php_fpm_enable=yes
Start php-fpm:
# service php-fpm start
Create file /usr/local/www/nginx/info.php
<?php phpinfo(); ?>
Check if they work?
It worked.
Delete /usr/local/www/nginx/info.php
# rm -rf /usr/local/www/nginx/info.php
Comments
Post a Comment