linux(ubuntu20.10):用apt方式安装php7.4.9
2023-09-14 08:59:32 时间
一,安装nginx:
1,apt方式安装nginx
root@ku:~# apt-get install nginx
2,安装完成后可以看到nginx已经启动运行:
root@ku:/var/www/html# systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-11-18 16:19:26 CST; 31min ago Docs: man:nginx(8) Main PID: 17111 (nginx) Tasks: 3 (limit: 4615) Memory: 4.5M CGroup: /system.slice/nginx.service ├─17111 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─17112 nginx: worker process └─17113 nginx: worker process 11月 18 16:19:26 ku systemd[1]: Starting A high performance web server and a reverse proxy server... 11月 18 16:19:26 ku systemd[1]: Started A high performance web server and a reverse proxy server.
用ss查看端口:
root@ku:/var/www/html# ss -lntp State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 70 127.0.0.1:33060 0.0.0.0:* users:(("mysqld",pid=6024,fd=32)) LISTEN 0 151 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=6024,fd=34)) LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=17113,fd=6),("nginx",pid=17112,fd=6),("nginx",pid=17111,fd=6)) ...
3,查看默认的配置文件:
ubuntu上默认的站点配置文件位于:/etc/nginx/sites-enabled
查看配置:
root@ku:/etc/nginx/sites-enabled# more default
可以看到默认站点的相关信息:
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; server_name _; location / { try_files $uri $uri/ =404; } }
主要内容如上,document root 目录在 /var/www/html
4,测试在/var/www/html目录下添加一张图片并访问:
root@ku:/etc/nginx/sites-enabled# cp /home/liuhongdi/图片/1370-macos-big-sur-wallpaper.png /var/www/html/a.png
从浏览器查看访问效果:
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,安装php-fpm
1,用apt安装:
root@ku:/etc/nginx/sites-enabled# apt-get install php-fpm
安装完成后查看php的版本:
root@ku:/var/www/html# php --version PHP 7.4.9 (cli) (built: Oct 26 2020 15:17:14) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
2,查看php-fpm安装后是否启动运行?(默认安装完成后会自动启动)
root@ku:/var/www/html# systemctl status php7.4-fpm ● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-11-18 16:15:47 CST; 13min ago Docs: man:php-fpm7.4(8) Process: 16977 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock
/etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/> Main PID: 16974 (php-fpm7.4) Status: "Processes active: 0, idle: 2, Requests: 1, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 4615) Memory: 9.6M CGroup: /system.slice/php7.4-fpm.service ├─16974 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf) ├─16975 php-fpm: pool www └─16976 php-fpm: pool www 11月 18 16:15:47 ku systemd[1]: Starting The PHP 7.4 FastCGI Process Manager... 11月 18 16:15:47 ku systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
可见php-fpm已经运行
三,在nginx配置中添加对php的支持:
1,在站点配置文件中添加对php的支持
root@ku:/etc/nginx/sites-enabled# ls default root@ku:/etc/nginx/sites-enabled# vi default
把以下内容取消注释:效果如下:
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; }
重启nginx
root@ku:/etc/nginx/sites-enabled# systemctl restart nginx
2,测试php程序能否正常执行:
root@ku:/etc/nginx/sites-enabled# cd /var/www/html/ root@ku:/var/www/html# vi info.php
代码为:
root@ku:/var/www/html# more info.php <?php phpinfo(); ?>
从浏览器查看:访问以下地址:
http://127.0.0.1/info.php
效果如图:
从phpinfo的输出中可以发现还缺少mysql/gd等较常用的扩展,
四,安装php的常用扩展:
1,安装
root@ku:/var/www/html# apt-get install php7.4-mysql php-gd root@ku:/var/www/html# apt-get install php7.4-mbstring
2,重启php-fpm服务:
root@ku:/var/www/html# systemctl restart php7.4-fpm
3,再次从浏览器访问phpinfo,可以发现已经包含了这几个扩展
五,查看linux的版本
root@ku:~# more /etc/os-release NAME="Ubuntu Kylin" VERSION="20.10 (Groovy Gorilla)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.10" VERSION_ID="20.10" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=groovy UBUNTU_CODENAME=groovy root@ku:~# uname -r 5.8.0-29-generic
相关文章
- linux添加防火墙_centos防火墙设置与端口开放的方法
- 麒麟Linux轻松安装指南(麒麟linux安装教程)
- Linux安装JDK:一步一步来(linux装jdk)
- Linux网卡启动遭遇挫折:一次行动的失败(linux网卡启动失败)
- Linux网卡自动激活:一种新的管理方式(linux网卡自动激活)
- Linux内核模块掌握之道(linux内核模块使用)
- Linux上必备的软件安装指南(linux必装软件)
- Linux嵌入式系统设计:激发潜能的崭新之路(linux嵌入式设计)
- 安装Linux:从DOS到挑战(dos下安装linux)
- 虚拟机轻松安装Linux系统(用虚拟机装linux)
- Linux语言轻松安装(linux语言安装)
- USB网卡在Linux系统下的安装与使用(usb网卡linux)
- Linux下JDK安装与配置指南(linux版的jdk)
- 快速安装Linux下的QQ服务(linuxqq安装)
- 安装Linux环境下的LZMA压缩工具(linux安装lzma)
- Linux 程序反汇编工具的使用(linux反汇编软件)
- 探索Linux运行C语言程序的方式(linux怎么运行c程序)
- 内容Linux系统必备知识:系统安装和操作(linux操作系统重点)
- Linux中如何使用DNW下载固件(linux使用dnw)
- 如何在Linux系统上安装飞鸽传书?——25字指南(飞鸽传书linux安装)
- Linux启动脚本的执行方式简介(linux启动执行脚本)
- 使用Linux编译生成静态库 全面了解静态库的生成方式(linux编译静态库)
- Linux安装启动引导器教程,让你轻松完成系统安装!(linux安装启动引导器)
- Linux下安装Vim:快速、轻松、简单(linux下载vim)
- 一步步教你用U盘安装Linux(linux安装到u盘)
- 文件Linux安装EXE文件:新的可能性(linux系统安装exe)
- 使用Linux安装AWK实现强大的文本处理(linux安装awk)
- Linux系统:探索最大线程数的界限(linux系统最大线程数)
- “轻松掌握!Linux如何查看当前字符集”(linux查看当前字符集)
- Linux快速安装文件:让您的系统开启快乐之旅!(linux 安装文件 .)
- Linux 遥控器:在家随心所欲操控电脑(linux 遥控器)
- 深入理解Linux中的进程分析(linux进程分析)