Ubuntu 16.04 LTS 安装 Nginx/PHP 7/MySQL

前端之家收集整理的这篇文章主要介绍了Ubuntu 16.04 LTS 安装 Nginx/PHP 7/MySQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

因为接触linux是从ubuntu开始的,所以,自己建站的时候服务器系统选择了ubuntu。因为版本问题,很多网上的资料不太统一。终于找到了一篇不错的开始整理。


1.安装MysqL


sudo apt-get -y install MysqL-server


安装过程需要设置数据库密码。数据库用户名root,密码自己设定


2.安装Nginx


不用apache是因为听说Nginx的并发比较好,而且我后台用的phalapi推荐使用Nginx
但是需要配置一下才能和PHP协调工作
这个系统安装Nginx版本为1.10 如果想自行升级请参照Nginx官网提示


apt-get -y install Nginx


执行完之后,输入你的地址就会看到欢迎页面,也就证明安装成功了。如果没有,请查找原因


3.安装PHP7
apt-get -y install PHP7.0-fpm


4.配置Nginx


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


vi /etc/Nginx/Nginx.conf

配置参数自己决定,这个我用的默认配置。 下面配置PHP vi /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… vi /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: vi /var/www/html/info.PHP <?PHP PHPinfo(); ?> 如果配置成功,访问info.PHP会在浏览器输出PHP信息的。 5.让MysqLPHP进行连接 先搜索一下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-xsl PHP7.0-mbstring PHP-gettext APCu是随PHP7 PHP Opcache模块的扩展,它增加了一些兼容性功能支持APC缓存(例如wordpress插件缓存)软件。 APCu可以安装如下: apt-get -y install PHP-apcu 重新加载 PHP-FPM: service PHP7.0-fpm reload 6.让 PHP-FPM 使用 TCP 连接 默认情况下PHP-FPM监听 /var/run/PHP/PHP7.0-fpm.sock. 另外,也可以使 PHP-FPM 试用 TCP 连接,打开文件 /etc/PHP/7.0/fpm/pool.d/www.conf… vi /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: service PHP7.0-fpm reload 接下来通过你的Nginx的配置和所有的虚拟主机,并更改fastcgi_pass UNIX行:/var/run/PHP/PHP7.0-fpm.sock; tofastcgi_pass127.0.0.1:9000;,如下: vi /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: service Nginx reload OK,Nginx的LEMP服务器安装完毕。

原文链接:https://www.f2er.com/ubuntu/353402.html

猜你在找的Ubuntu相关文章