如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

news/2024/7/5 4:55:28
本文介绍如何在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

如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

启动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.

如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)
如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

nginx相关配置

nginx的配置文件在/usr/local/etc/nginx目录中,名称为nginx.conf,可以使用vim编辑器打开配置文件。

root@freebsd:~ # vim /usr/local/etc/nginx/nginx.confuser  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;}}
}

如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

安装MySQL

使用下面命令来安装mysql:

root@freebsd:~ # pkg install mysql80-server mysql80-client

要在系统启动时启用它,使用下面命令将mysql_enable=yes添加到rc.conf文件中:

root@freebsd:~ # sysrc mysql_enable=yes

如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)
启动mysql:

root@freebsd:~ # service mysql-server start
Starting mysql.

安装PHP

PHP 是一种服务器端语言,与 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 successfulStarting php_fpm.
root@freebsd:~ # 

如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)

访问php测试页

/usr/local/www/nginx目录下创建一个php测试文件,名为:test.php:

root@freebsd:~ # vim /usr/local/www/nginx/test.php 

浏览器访问一下查看是否可看到测试页:
如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)如何在FreeBSD中安装Nginx,MySQL,PHP(FEMP)
测试没问题了,可以从服务器中删除测试文件,以避免将有关服务器的信息暴露。

root@freebsd:~ # rm -rf /usr/local/www/nginx/test.php 

总结

目前位置已经在 FreeBSD 系统上安装了 Nginx、MySQL 和 PHP!


http://lihuaxi.xjx100.cn/news/284463.html

相关文章

程序员到新公司后第一周该干些什么?不该干些什么?

转自:网络不管你是打算进公司实习的大学生,还是刚跳槽的职场人士,进入新公司的第一周,面对完全不熟悉的环境和团队,陌生感是必然的。我们有一些建议,让你看起来不会像个“局外人”。01 熟悉环境虽然你之前因…

百度发的208亿春晚红包,靠这样的技术送到了你手上 | 解读

2019 年的春晚红包项目对百度而言是一次大考,背后需要强大的技术来支撑。如你所见,百度不负“技术大厂”的标签,春晚红包期间系统稳定运行,没有出现宕机事故。在这样一个庞大而复杂的项目面前,他们是如何去用技术去化解…

Java非阻塞I/O模型之NIO说明

在了解NIO (Non-Block I/O) 非阻塞I/O模型之前,我们可以先了解一下原始的BIO(Block I/O) 阻塞I/O模型,NIO模型能够以非阻塞的方式更好的利用服务器资源,需要的朋友可以参考下 组件说明 (1)Channel:NIO模型中的管道,管道是链接建立…

假如曹操是一名程序员,会发生什么?

点击上方蓝色“视学算法”,选择“设为星标” 来源 | W3CSchool 东汉网络科技有限公司,本来是一家名扬四海的家族企业,可由于近几年来,越来越多的亲戚,在公司担任重要岗位,真正的人才越来越少,东…

这样就能用MathType编辑^符号

大家都知道数学公式中的符号有很多,有些符号的名称还很多,比如,^这个字符,可以是乘方、插入符号、插入符、托字符等。所以一些用户在使用过程中有点搞不清,但是Mathtype的符号模板有很多种,基本可以满足各种…

何恺明的GN之后,权重标准化新方法能超越GN、BN吗? | 技术头条

点击上方↑↑↑蓝字关注我们~「2019 Python开发者日」,购票请扫码咨询 ↑↑↑作者 | Siyuan Qiao、Huiyu Wang、Chenxi Liu、Wei Shen、Alan Yuille(Johns Hopkins University,约翰霍普金斯大学)译者 | 刘畅编辑 | Jane出品 | AI科…

如何在 Unix 和 DOS 格式之间转换文本文件

本文介绍如何在 Unix 和 DOS 格式之间转换文本文件。DOS 文本文件带有回车符( \r )和换行符( \n )作为它们的换行符,而 Unix 文本文件只有( \n )换行符作为换行符。 有多种方法可以将 DOS 文本文…