---恢复内容开始---

1.nginx的服务端的安装

打开命令行终端,在终端输入,sudo apt-get install nginx  回车即开始安装

kxlc-t@ubuntu:~$ sudo apt-get install nginx
[sudo] kxlc-t 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:nginx-common nginx-core
建议安装:fcgiwrap nginx-doc
下列【新】软件包将被安装:nginx nginx-common nginx-core
升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 201 个软件包未被升级。
需要下载 458 kB 的归档。
解压缩后会消耗 1,482 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.3-0ubuntu0.16.04.2 [26.6 kB]
获取:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.3-0ubuntu0.16.04.2 [428 kB]
获取:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.3-0ubuntu0.16.04.2 [3,490 B]
已下载 458 kB,耗时 3秒 (147 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 nginx-common。
(正在读取数据库 ... 系统当前共安装有 258856 个文件和目录。)
正准备解包 .../nginx-common_1.10.3-0ubuntu0.16.04.2_all.deb  ...
正在解包 nginx-common (1.10.3-0ubuntu0.16.04.2) ...
正在选中未选择的软件包 nginx-core。
正准备解包 .../nginx-core_1.10.3-0ubuntu0.16.04.2_amd64.deb  ...
正在解包 nginx-core (1.10.3-0ubuntu0.16.04.2) ...
正在选中未选择的软件包 nginx。
正准备解包 .../nginx_1.10.3-0ubuntu0.16.04.2_all.deb  ...
正在解包 nginx (1.10.3-0ubuntu0.16.04.2) ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
正在处理用于 ufw (0.35-0ubuntu2) 的触发器 ...
正在处理用于 systemd (229-4ubuntu21.1) 的触发器 ...
正在设置 nginx-common (1.10.3-0ubuntu0.16.04.2) ...
正在设置 nginx-core (1.10.3-0ubuntu0.16.04.2) ...
正在设置 nginx (1.10.3-0ubuntu0.16.04.2) ...
正在处理用于 systemd (229-4ubuntu21.1) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
正在处理用于 ufw (0.35-0ubuntu2) 的触发器 ...

2. nginx服务设置,开启及状态的查看

kxlc-t@ubuntu:~$ sudo systemctl start nginx          ------设置nginx服务开机自启动kxlc-t@ubuntu:~$ sudo systemctl start nginx            ------开启nginx服务
kxlc-t@ubuntu:~$ sudo systemctl status nginx.service     --------查看nginx状态
● nginx.service - A high performance web server and a reverse proxy serverLoaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enActive: active (running) since 四 2018-04-19 15:46:55 CST; 17min agoMain PID: 9898 (nginx)CGroup: /system.slice/nginx.service├─9898 nginx: master process /usr/sbin/nginx -g daemon on; master_pro└─9899 nginx: worker process                           4月 19 15:46:55 ubuntu systemd[1]: Starting A high performance web server and a
4月 19 15:46:55 ubuntu systemd[1]: nginx.service: Failed to read PID from file /
4月 19 15:46:55 ubuntu systemd[1]: Started A high performance web server and a r
4月 19 16:04:17 ubuntu systemd[1]: Started A high performance web server and a r
lines 1-12/12 (END)

3.  nginx版本的输出

kxlc-t@ubuntu:~$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)

4.  将www-data作为网站的根目录使用者,默认情况是root使用

kxlc-t@ubuntu:~$ sudo chown www-data:www-data /usr/share/nginx/html/ -R
kxlc-t@ubuntu:~$

注意:在安装nginx时候,默认创建用户www-data用户

kxlc-t@ubuntu:~$ cat /etc/passwd | grep www-data
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

5. 安装mariadb数据库

sudo apt-get install mariadb-server mariadb-client

6. 配置mariadb数据库

kxlc-t@ubuntu:~$ sudo mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none):
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.You already have a root password set, so you can safely answer 'n'.Change the root password? [Y/n] Y           -------设置root用户的密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] Y      ------禁止匿名用户访问... Success!Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] Y      -------不允许root用户远程登录... Success!By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] Y      ------移除test数据库,并且禁止访问它- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] Y      -------重载私有权限表... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!

7. 安装PHP 插件

sudo apt install php7.0 php7.0-fpm php7.0-mysql php-common php7.0-cli php7.0-common php7.0-json

输出:

kxlc-t@ubuntu:~$ sudo apt install php7.0 php7.0-fpm php7.0-mysql php-common php7.0-cli php7.0-common php7.0-json
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:libevent-core-2.0-5
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:php7.0-opcache php7.0-readline
建议安装:php-pear
下列【新】软件包将被安装:php-common php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-jsonphp7.0-mysql php7.0-opcache php7.0-readline
升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 201 个软件包未被升级。
需要下载 3,653 kB 的归档。
解压缩后会消耗 14.5 MB 的额外空间。
您希望继续执行吗? [Y/n] Y
获取:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php-common all 1:35ubuntu6.1 [10.8 kB]
获取:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-common amd64 7.0.28-0ubuntu0.16.04.1 [840 kB]
获取:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-json amd64 7.0.28-0ubuntu0.16.04.1 [16.9 kB]
获取:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-opcache amd64 7.0.28-0ubuntu0.16.04.1 [77.1 kB]
获取:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-readline amd64 7.0.28-0ubuntu0.16.04.1 [12.8 kB]
获取:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-cli amd64 7.0.28-0ubuntu0.16.04.1 [1,282 kB]
获取:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 php7.0-fpm amd64 7.0.28-0ubuntu0.16.04.1 [1,288 kB]
获取:8 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0 all 7.0.28-0ubuntu0.16.04.1 [1,290 B]
获取:9 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-mysql amd64 7.0.28-0ubuntu0.16.04.1 [124 kB]
已下载 3,653 kB,耗时 5秒 (707 kB/s)
正在选中未选择的软件包 php-common。
(正在读取数据库 ... 系统当前共安装有 259138 个文件和目录。)
正准备解包 .../php-common_1%3a35ubuntu6.1_all.deb  ...
正在解包 php-common (1:35ubuntu6.1) ...
正在选中未选择的软件包 php7.0-common。
正准备解包 .../php7.0-common_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-common (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-json。
正准备解包 .../php7.0-json_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-json (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-opcache。
正准备解包 .../php7.0-opcache_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-opcache (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-readline。
正准备解包 .../php7.0-readline_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-readline (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-cli。
正准备解包 .../php7.0-cli_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-cli (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-fpm。
正准备解包 .../php7.0-fpm_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-fpm (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0。
正准备解包 .../php7.0_7.0.28-0ubuntu0.16.04.1_all.deb  ...
正在解包 php7.0 (7.0.28-0ubuntu0.16.04.1) ...
正在选中未选择的软件包 php7.0-mysql。
正准备解包 .../php7.0-mysql_7.0.28-0ubuntu0.16.04.1_amd64.deb  ...
正在解包 php7.0-mysql (7.0.28-0ubuntu0.16.04.1) ...
正在处理用于 man-db (2.7.5-1) 的触发器 ...
正在处理用于 systemd (229-4ubuntu21.1) 的触发器 ...
正在处理用于 ureadahead (0.100.0-19) 的触发器 ...
正在设置 php-common (1:35ubuntu6.1) ...
正在设置 php7.0-common (7.0.28-0ubuntu0.16.04.1) ...Creating config file /etc/php/7.0/mods-available/calendar.ini with new versionCreating config file /etc/php/7.0/mods-available/ctype.ini with new versionCreating config file /etc/php/7.0/mods-available/exif.ini with new versionCreating config file /etc/php/7.0/mods-available/fileinfo.ini with new versionCreating config file /etc/php/7.0/mods-available/ftp.ini with new versionCreating config file /etc/php/7.0/mods-available/gettext.ini with new versionCreating config file /etc/php/7.0/mods-available/iconv.ini with new versionCreating config file /etc/php/7.0/mods-available/pdo.ini with new versionCreating config file /etc/php/7.0/mods-available/phar.ini with new versionCreating config file /etc/php/7.0/mods-available/posix.ini with new version

8. PHP插件服务的启动及状态的查看

kxlc-t@ubuntu:~$ sudo systemctl enable php7.0-fpmkxlc-t@ubuntu:~$ sudo systemctl start php7.0-fpm
kxlc-t@ubuntu:~$ sudo systemctl status php7.0-fpm
● php7.0-fpm.service - The PHP 7.0 FastCGI Process ManagerLoaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preseActive: active (running) since 四 2018-04-19 16:54:52 CST; 4min 33s agoProcess: 24868 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, stMain PID: 24877 (php-fpm7.0)Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/seCGroup: /system.slice/php7.0-fpm.service├─24877 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)      ├─24879 php-fpm: pool www                                            └─24880 php-fpm: pool www                                            4月 19 16:54:52 ubuntu systemd[1]: Stopped The PHP 7.0 FastCGI Process Manager.
4月 19 16:54:52 ubuntu systemd[1]: Starting The PHP 7.0 FastCGI Process Manager.
4月 19 16:54:52 ubuntu systemd[1]: Started The PHP 7.0 FastCGI Process Manager.
4月 19 16:59:16 ubuntu systemd[1]: Started The PHP 7.0 FastCGI Process Manager.
lines 1-15/15 (END)

第5步:创建一个Nginx虚拟主机

Nginx服务器就像Apache中的一个虚拟主机。 我们不会使用默认的服务器块,因为它不足以运行PHP代码,如果我们修改它,它变得一团糟。 因此,通过运行以下命令来删除启用了站点的目录中的默认符号链接。 (它仍然是可用的/etc/nginx/sites-available/default

sudo rm /etc/nginx/sites-enabled/default

然后在/etc/nginx/conf.d/目录下创建一个全新的服务器文件。
sudo vim /etc/nginx/conf.d/default.conf   -------将以下文本粘贴到文件中。 将192.168.1.108替换为您的实际服务器IP地址。server {listen 80;listen [::]:80;server_name 192.168.1.108;      ----ip地址替换为自己的ip地址root /usr/share/nginx/html/;index index.php index.html index.htm index.nginx-debian.html;location / {try_files $uri $uri/ /index.php;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}location ~ \.php$ {fastcgi_pass unix:/run/php/php7.0-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;include snippets/fastcgi-php.conf;}location ~ /\.ht {deny all;}
}

PHP功能的测试

打开/usr/share/nginx/html/info.php , 输入下列代码:

<?php phpinfo()?>

在浏览器输入,ip-adress/info.php,即可出现下面页面;

如何安装PHP7.2

PHP7.2是PHP的最新稳定版本,于2017年11月30日发布,与PHP7.1相比,性能有所提升。 我们可以从Ondrej Sury添加PPA来在Ubuntu 17.10上安装PHP7.2。 那个人也是Certbot PPA的维护者。

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

然后我们可以使用下面的命令安装PHP7.2和通用扩展。

sudo apt install php7.2 php7.2-fpm php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

现在启动PHP7.2-FPM。

sudo systemctl start php7.2-fpm

在系统启动时启用自动启动。

sudo systemctl enable php7.2-fpm

检查其状态:

systemctl status php7.2-fpm

然后在/etc/nginx/conf.d/目录下创建一个全新的服务器文件。

sudo nano /etc/nginx/conf.d/default.conf

将以下文本粘贴到文件中。 将192.168.1.108替换为您的实际服务器IP地址。

server {listen 80;listen [::]:80;server_name 192.168.1.108;root /usr/share/nginx/html/;index index.php index.html index.htm index.nginx-debian.html;location / {try_files $uri $uri/ /index.php;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}location ~ \.php$ {fastcgi_pass unix:/run/php/php7.1-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;include snippets/fastcgi-php.conf;}location ~ /\.ht {deny all;}
}

转载于:https://www.cnblogs.com/sunshine-1/p/8884695.html

Ubuntu 下安装LEMP环境 实战相关推荐

  1. openni linux arm,Ubuntu下安装配置OpenNI实战笔记

    1. 库OpenNI SensorKinect NITE的安装 (1)OpenNI step1 :下载 OpenNI库文件 选择"OpenNI Binaries"->&quo ...

  2. ubuntu下安装lamp环境

    一.安装 1. 首先安装SSH sudo apt-get install ssh 2.安装MySQL(虽然现在最新版为5.1,但是还只能装5.0版本) sudo apt-get install mys ...

  3. ubuntu下安装模拟环境carla

    经历了长时间的尝试安装编译build版本的carla,最后以失败告终.主要出错在最后一步的make launch上,会出现configuring incompleting. 最终转向了ubuntu的预 ...

  4. 在虚拟机Ubuntu下安装java环境

    一.可以在window平台下下载linux系统版本的java,然后通过xftp传输到虚拟机 我下载的java文件是jdk-18_linux-x64_bin.tar.gz 下图左侧就是windows系统 ...

  5. ubuntu下安装golang环境

    1.到官网下载go语言的压缩包,这里推荐https://studygolang.com/dl 如 go1.10.4.linux-amd64.tar.gz 2.解压到本地目录 tar -zxvf go1 ...

  6. linux/ubuntu下安装java开发环境

    在ubuntu下安装和配置java开发环境,下面对自己的一些实践做了一下总结. Sun JDK的安装一般有两种方式: 一.通过ubuntu提供的包管理工具进行安装 ubuntu在其包仓库里都包括有JD ...

  7. ubuntu下Android开发环境的搭建:eclipse+SDK详细安装教程+常见问题及其解决方案

    先讲具体的安装步骤然后再说常见问题及解决方案. ubuntu下安装eclipse+SDK具体步骤: 1.安装JDK: 在官网(http://www.oracle.com/technetwork/jav ...

  8. ubuntu mysql 环境,Ubuntu下安装搭建MySQL环境步骤介绍

    摘要 腾兴网为您分享:Ubuntu下安装搭建MySQL环境步骤介绍,翼拍照,易码平台,洋葱数学,小度等软件知识,以及poco美人相机,收卡啦,crc16校验工具,ps画笔样式,机械标准件,法硕联盟论坛 ...

  9. Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL

     Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL 2012-09-15 11:12:31 标签:php mysql ubuntu nginx php-fpm 原创作品,允许转载 ...

最新文章

  1. Linux上 Can‘t connect to X11 window server using XX as the value of the DISPLAY 错误解决方法
  2. Sympy常见多个变量【一行代码创建】
  3. Python中必知的知识点:文本转义及编码的常用方法
  4. SQL Server存储过程里全库查找引用的数据库对象(表、存储过程等)
  5. 15个基本的C#面试问题
  6. 鸿蒙测试机型微博,华为多款机型开启鸿蒙尝鲜:微博已适配HarmonyOS小尾巴
  7. css过度效果 从无到有,求教,对于CSS3 transition和transform实现的一个特效原理不是太明白?...
  8. Python爬虫的经典多线程方式,生产者与消费者模型
  9. Linux下的防火墙管理(包含图形和命令、伪装和转发)
  10. ROS 可视化(一): 发布PointCloud2点云数据到Rviz
  11. 云原生时代,需要什么样的数据库?
  12. Windows Phone 7(WP7)开发 获取网络状态
  13. 《软件工程》网上书店项目需求规格说明书
  14. 金蝶服务器连接协议,k3金蝶客户端连接服务器配置
  15. R语言---ggplot图片边缘空白设置和ggplot映射的shape值多余6个
  16. Python数据可视化,Pyecharts库,外圆环内饼图制作
  17. 2021年数据中台行业十大关键词
  18. 计算机桌面曝光,win7电脑桌面壁纸曝光过高影响图标怎么办?亲测实用解决方法...
  19. 【cs224n学习作业】Assignment 1 - Exploring Word Vectors【附代码】
  20. ISO26262对软件开发的规定

热门文章

  1. sci_loopback_int的例程(中断程序)
  2. Linux内核中读写文件数据的方法
  3. 【Qt】Qt窗口程序
  4. 【Tiny4412】Uboot常用命令
  5. 【Linux】一步一步学Linux——find命令(47)
  6. python统计行号_如何使用Python脚本分析CPU使用情况的?
  7. 每天一道LeetCode-----两个有序数组合并后的第K个数
  8. php递归多维数组为缩进列表,php – 缩进列表到多维数组
  9. mongodb存入mysql_关于mongodb转存MySQL
  10. html(5)标签form表单——进阶