本文介绍如何在 FreeBSD 13 零碎中装置 Nginx、MySQL、和 PHP 服务。零碎环境 FreeBSD 13.0-RELEASE 更新零碎在装置任何软件之前更新零碎是一个好习惯,以便查看零碎更新:root@freebsd:~ # freebsd-update fetch
root@freebsd:~ # freebsd-update install
装置 Nginx 应用 pkg 包管理器装置 nginx:root@freebsd:~ # pkg install -y nginx
启动 nginx 要在系统启动时运行 Nginx 服务,须要在 /etc/rc.conf 配置文件的开端增加一行 nginx_enable=”yes”。运行上面的命令,主动将 nginx_enable=”yes” 附加到 rc.conf 文件中,而后启动服务:root@freebsd:~ # sysrc nginx_enable=yes
root@freebsd:~ # service nginx start
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
nginx 相干配置 nginx 的配置文件在 /usr/local/etc/nginx 目录中,名称为 nginx.conf,能够应用 vim 编辑器关上配置文件。root@freebsd:~ # vim /usr/local/etc/nginx/nginx.conf
user www;
worker_processes 1;
error_log /var/log/nginx/error.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/local/www/nginx;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {root /usr/local/www/nginx-dist;}
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;
}
}
}
装置 MySQL 应用上面命令来装置 mysql:root@freebsd:~ # pkg install mysql80-server mysql80-client
要在系统启动时启用它,应用上面命令将 mysql_enable=yes 增加到 rc.conf 文件中:root@freebsd:~ # sysrc mysql_enable=yes
启动 mysql:root@freebsd:~ # service mysql-server start
Starting mysql.
装置 PHPPHP 是一种服务器端语言,与 HTML 联合应用以创立动静 Web 内容。它还连贯到 MySQL 数据库以检索和上传内容。上面命令来装置 php8.0 和罕用的模块。root@freebsd:~ # pkg install -y php80 php80-mysqli php80-mbstring php80-zlib php80-curl php80-gd php80-json
配置 php-fpm 上面将 php.ini-production 配置文件复制一份,改名为 php.ini:root@freebsd:/usr/local/etc # cp /usr/local/etc/php.ini{-production,}
关上文件 /usr/local/etc/php.ini 并勾销正文;cgi.fix_pathinfo=1,将其值更改为 0。root@freebsd:~ # cat /usr/local/etc/php.ini | grep ‘^cgi.fix_pathinfo’
cgi.fix_pathinfo=0
设置 php-fpm 开机启动:root@freebsd:~ # sysrc php_fpm_enable=yes
php_fpm_enable: -> yes
root@freebsd:~ # service php-fpm start
Performing sanity check on php-fpm configuration:
[03-Jun-2021 18:51:27] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.
root@freebsd:~ #
拜访 php 测试页在 /usr/local/www/nginx 目录下创立一个 php 测试文件,名为:test.php:root@freebsd:~ # vim /usr/local/www/nginx/test.php
浏览器拜访一下查看是否可看到测试页:
测试没问题了,能够从服务器中删除测试文件,以防止将无关服务器的信息裸露。root@freebsd:~ # rm -rf /usr/local/www/nginx/test.php
总结目前地位曾经在 FreeBSD 零碎上装置了 Nginx、MySQL 和 PHP!