Nginx(读”engine x”) 是一款免费、开源的高性能 HTTP 服务。Nginx 稳定、丰富的功能集、配置简单、资源消耗低。本教程介绍了如何通过PHP7支持(通过PHP-FPM)和MysqL5.7支持(LEMP= LINUX + Nginx(发音为“engine x”)+ MysqL+ PHP)在Ubuntu16.04服务器上安装Nginx服务器。

1 初步说明

在本教程中,我使用的IP 地址192.168.1.100,主机名server1.example.com。这些设置可能与你的不同,所以你不得不在适当情况下更换他们。

我运行的所有步骤在本教程中使用root权限,所以一定要确保你以root身份登录:

2 安装MysqL 5.7

安装 MysqL运行命令:

apt-get -y install MysqL-server MysqL-client

安装期间要求设置MysqL的root用户密码 :

New password for the MysqL “root” user:<– yourrootsqlpassword
Repeat password for the MysqL “root” user:<– yourrootsqlpassword

为了确保数据库服务器,并删除匿名用户和测试数据库,运行MysqL_secure_installation命令。

MysqL_secure_installation

期间会被问及一些问题:

root@server1:~# MysqL_secure_installation

Enter password for user root:<– Enter the MysqL root password

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes,any other key for No:<– Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes,any other key for No) :<– Press enter

… skipping.
By default,a MysqL installation has an anonymous user,
allowing anyone to log into MysqL 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? (Press y|Y for Yes,any other key for No) :<– 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? (Press y|Y for Yes,51); text-align:justify"> By default,MysqL 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? (Press y|Y for Yes,any other key for No) :<– y
– 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? (Press y|Y for Yes,51); text-align:justify"> All done!

MysqL is secured Now.

3 安装 Nginx

如果你已经安装了Apache2的话,那么使用这些命令先删除再安装Nginx:

service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2

Ubuntu16.04有Nginx安装包,我们可以安装。

apt-get -y install Nginx

启动ngninx:

service Nginx start

输入您的Web服务器的IP地址或主机名到浏览器(例如http://192.168.1.100),你应该看到如下页面:

Ubuntu16.04的默认Nginx的文档根目录为/var/www/html

4 安装 PHP 7

安装如下:

apt-get -y install PHP7.0-fpm

5 配置 Nginx

打开配置文件/etc/Nginx/Nginx.conf:

nano /etc/Nginx/Nginx.conf

配置很容易理解 (你可以点击官方教程:http://wiki.nginx.org/NginxFullExample或:http://wiki.nginx.org/NginxFullExample2)

首先(这是可选)调整keepalive_timeout到一个合理的值:

[...]
    keepalive_timeout   2;
[...]

虚拟主机服务器{}容器定义。默认的虚拟主机是在/etc/Nginx/sites-available/default 文件中定义- 修改它,如下所示:

nano/etc/Nginx/sites-available/default

[...]
server {
 listen 80 default_server;
 listen [::]:80 default_server;

 # SSL configuration
 #
 # listen 443 ssl default_server;
 # listen [::]:443 ssl default_server;
 #
 # Note: You should disable gzip for SSL traffic.
 # See: https://bugs.debian.org/773332
 #
 # Read up on ssl_ciphers to ensure a secure configuration.
 # See: https://bugs.debian.org/765782
 #
 # Self signed certs generated by the ssl-cert package
 # Don't use them in a production server!
 #
 # include snippets/snakeoil.conf;

 root /var/www/html;

 # Add index.PHP to the list if you are using PHP
 index index.html index.htm index.Nginx-debian.html;

 server_name _;

 location / {
 # First attempt to serve request as file,then
 # as directory,then fall back to displaying a 404.
 try_files $uri $uri/ =404;
 }

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ \.PHP$ {
 include snippets/fastcgi-PHP.conf;

 # With PHP7.0-cgi alone:
 # fastcgi_pass 127.0.0.1:9000;
 # With PHP7.0-fpm:
 fastcgi_pass unix:/run/PHP/PHP7.0-fpm.sock;
 }

 # deny access to .htaccess files,if Apache's document root
 # concurs with Nginx's one
 #
 location ~ /\.ht {
  deny all;
 }
}
[...]

server_name _;使这是一个默认虚拟主机(当然,你可以同时喜欢这里www.example.com指定主机名)。

根目录 /var/www/html;意味着文档根目录/var/www/html.

PHP重要组成部分位置 ~ \.PHP$ {}stanza. 取消注释它来启用它。

现在保存文件并重新加载Nginx:

service Nginx reload

下一步打开/etc/PHP/7.0/fpm/PHP.ini

nano /etc/PHP/7.0/fpm/PHP.ini

设置cgi.fix_pathinfo=0:

[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; prevIoUs behavIoUr was to set PATH_TRANSLATED to SCRIPT_FILENAME,and to not grok
; what PATH_INFO is.  For more information on PATH_INFO,see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://PHP.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

重新加载 PHP-FPM:

service PHP7.0-fpm reload

建立探针文件/var/www/html:

nano /var/www/html/info.PHP

<?PHP
PHPinfo();
?>

浏览器访问 (e.g.http://192.168.1.100/info.PHP):

6 让 MysqL 获得 PHP 7支持

先搜索一下PHP支持的模块:

apt-cache search PHP7.0

使用下面的命令安装:

apt-get -y install PHP7.0-MysqL PHP7.0-curl PHP7.0-gd PHP7.0-intl PHP-pear PHP-imagick PHP7.0-imap PHP7.0-mcrypt PHP-memcache PHP7.0-pspell PHP7.0-recode PHP7.0-sqlite3 PHP7.0-tidy PHP7.0-xmlrpc PHP7.0-xslPHP7.0-mbstringPHP-gettext

APCu是随PHP7 PHP Opcache模块的扩展,它增加了一些兼容性功能的支持APC缓存(例如wordpress的插件缓存)软件。

APCu可以安装如下:

apt-get -y install PHP-apcu

重新加载 PHP-FPM:

刷新http://192.168.1.100/info.PHP浏览器看看模块安装情况:

7 让 PHP-FPM 使用 TCP 连接

默认情况下PHP-FPM监听 /var/run/PHP/PHP7.0-fpm.sock. 另外,也可以使 PHP-FPM 试用 TCP 连接,打开文件/etc/PHP/7.0/fpm/pool.d/www.conf

nano /etc/PHP/7.0/fpm/pool.d/www.conf

修改如下:

[...]
;listen = /var/run/PHP5-fpm.sock
listen = 127.0.0.1:9000
[...]

这将使PHP-FPM端口9000侦听的IP127.0.0.1(本地主机)。请确保您使用的端口,是不是在你的系统上使用。

然后重新加载 PHP-FPM:

PHP7.0-fpm reload

接下来通过你的Nginx的配置和所有的虚拟主机,并更改fastcgi_pass UNIX行:/var/run/PHP/PHP7.0-fpm.sock; tofastcgi_pass127.0.0.1:9000;,如下:

nano /etc/Nginx/sites-available/default

[...]
        location ~ \.PHP$ {
 include snippets/fastcgi-PHP.conf;

 # With PHP7.0-cgi alone:
 fastcgi_pass 127.0.0.1:9000;
 # With PHP7.0-fpm:
 # fastcgi_pass unix:/run/PHP/PHP7.0-fpm.sock;
 }
[...]

最后,重新加载Nginx:

OK,Nginx的LEMP服务器安装完毕。

Ubuntu 16.04 LTS 安装 Nginx/PHP 7/MySQL 5.7 (LEMP)的更多相关文章

  1. macos – 运行brew命令充满了’同意Xcode / iOS许可证需要管理员权限,请通过sudo以root身份重新运行.’

    所以我跑了:如果滚动到底部,可以输入“同意”,然后就可以了.

  2. 从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

    我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码:这里是PHP的一大块,POST变量不在正确的位置?我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!解决方法$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:

  3. ios – 仅适用于iPad的Settings.bundle?

    我有一种情况需要通过设置应用程序为我的应用程序提供一个设置.我的应用程序是通用的,但这个特殊的设置只在iPad上有意义,所以我只希望我的应用程序显示在iPad上的设置中.这可能吗?

  4. ios – Swift 4设置捆绑,获取默认值

    我创建了一个包含大约8个切换开关的设置包.我想要做的是从设置包中获取默认值.目前我现在有这两种方法:我在viewDidLoad中调用这些方法然而,这并没有得到我的默认值.如果我关闭应用程序,打开设置,调整设置并重新打开应用程序,这会产生正确的值.有没有获得默认设置?

  5. Swift调用OC和C

    Swift文件:main.swiftOC文件:Root.hRoot.mC函数文件:Fun.c桥接文件:工程名称-Bridging-Header.h

  6. OC调用Swift

    修改main.m文件OC文件:Root.hRoot.mSwift文件:Person.swift

  7. swift学习2 元组 tuples

    swift中出现了一种新的数据结构,非常牛掰的元组tuples如果懂PHP的猿,会发现这个元组和PHP的数组非常类似,同样是可以默认不指定key,也可以指定key目前的学习疑问是,如何进行元组的遍历?

  8. swift 跳到系统设置界面

    首先需要设置一下:跳转到系统的设置页主页,在iOS8.0的时候,Apple出了这么个玩意UIApplicationopenSettingsURLString,可以跳转到系统设置主页参考:http://www.jianshu.com/p/580d84dda738http://www.jianshu.com/p/8e354e684e8a

  9. 尝试使用swift mailer,gmail smtp,php发送邮件

    这里是我的代码:在运行时出现此错误…

  10. android – 以编程方式捕获网络流量(无根)

    我正在尝试查找资源或库,这些资源或库可以允许我以编程方式捕获设备的所有网络数据包的流量,无论是来自wifi还是移动网络.我相信没有必要成为sharkforroot会请求这种混杂模式的root用户,因为Play商店有thisapp可以捕获所有网络流量而不需要root.我根本无法弄清楚如何做同样的事情.我的问题是:这个应用程序是如何实现此捕获的?

随机推荐

  1. crontab发送一个月份的电子邮件

    ubuntu14.04邮件服务器:Postfixroot收到来自crontab的十几封电子邮件.这些邮件包含PHP警告.>我已经解决了这些警告的原因.>我已修复每个cronjobs不发送电子邮件(输出发送到>/dev/null2>&1)>我删除了之前的所有电子邮件/var/mail/root/var/spool/mail/root但我仍然每小时收到十几封电子邮件.这些电子邮件来自cronjobs,

  2. 模拟两个ubuntu服务器计算机之间的慢速连接

    我想模拟以下场景:假设我有4台ubuntu服务器机器A,B,C和D.我想在机器A和机器C之间减少20%的网络带宽,在A和B之间减少10%.使用网络模拟/限制工具来做到这一点?

  3. ubuntu-12.04 – 如何在ubuntu 12.04中卸载从源安装的redis?

    我从源代码在Ubuntu12.04上安装了redis-server.但在某些时候它无法完全安装,最后一次makeinstallcmd失败.然后我刚刚通过apt包安装.现在我很困惑哪个安装正在运行哪个conf文件?实际上我想卸载/删除通过源安装的所有内容,只是想安装一个包.转到源代码树并尝试以下命令:如果这不起作用,您可以列出软件自行安装所需的步骤:

  4. ubuntu – “apt-get source”无法找到包但“apt-get install”和“apt-get cache”可以找到它

    我正在尝试下载软件包的源代码,但是当我运行时它无法找到.但是当我运行apt-cache搜索squid3时,它会找到它.它也适用于apt-getinstallsquid3.我使用的是Ubuntu11.04服务器,这是我的/etc/apt/sources.list我已经多次更新了.我尝试了很多不同的debs,并没有发现任何其他地方的错误.这里的问题是你的二进制包(deb)与你的源包(deb-src)不

  5. ubuntu – 有没有办法检测nginx何时完成正常关闭?

    &&touchrestarted),因为即使Nginx没有完成其关闭,touch命令也会立即执行.有没有好办法呢?这样的事情怎么样?因此,pgrep将查找任何Nginx进程,而while循环将让它坐在那里直到它们全部消失.你可以改变一些有用的东西,比如睡1;/etc/init.d/Nginx停止,以便它会休眠一秒钟,然后尝试使用init.d脚本停止Nginx.你也可以在某处放置一个计数器,这样你就可以在需要太长时间时发出轰击信号.

  6. ubuntu – 如何将所有外发电子邮件从postfix重定向到单个地址进行测试

    我正在为基于Web的应用程序设置测试服务器,该应用程序发送一些电子邮件通知.有时候测试是使用真实的客户数据进行的,因此我需要保证服务器在我们测试时无法向真实客户发送电子邮件.我想要的是配置postfix,以便它接收任何外发电子邮件并将其重定向到一个电子邮件地址,而不是传递到真正的目的地.我正在运行ubuntu服务器9.10.先感谢您设置本地用户以接收所有被困邮件:你需要在main.cf中添加:然后

  7. ubuntu – vagrant无法连接到虚拟框

    当我使用基本的Vagrantfile,只配置了两条线:我看到我的虚拟框打开,但是我的流氓日志多次显示此行直到超时:然后,超时后的一段时间,虚拟框框终于要求我登录,但是太久了!所以我用流氓/流氓记录.然后在我的物理机器上,如果我“流氓ssh”.没有事情发生,直到:怎么了?

  8. ubuntu – Nginx – 转发HTTP AUTH – 用户?

    我和Nginx和Jenkins有些麻烦.我尝试使用Nginx作为Jenkins实例的反向代理,使用HTTP基本身份验证.它到目前为止工作,但我不知道如何传递带有AUTH用户名的标头?}尝试将此指令添加到您的位置块

  9. Debian / Ubuntu – 删除后如何恢复/ var / cache / apt结构?

    我在ubuntu服务器上的空间不足,所以我做了这个命令以节省空间但是现在在尝试使用apt时,我会收到以下错误:等等显然我删除了一些目录结构.有没有办法做apt-getrebuild-var-tree或类似的?

  10. 检查ubuntu上安装的rubygems版本?

    如何查看我的ubuntu盒子上安装的rubygems版本?只是一个想法,列出已安装的软件包和grep为ruby或宝石或其他:)dpkg–get-selections

返回
顶部