九溪

溪水润知林,滴露启慧心

用户工具

站点工具


wiki:linux:ubuntu-install-nginx-php-mysql

这是本文档旧的修订版!


Ubuntu 搭建LNMP服务器(Linux/Nginx/MySQL/PHP)

准备

相关文章:

更新软件源

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

安装 Nginx

安装Nginx

sudo apt-get install nginx

查看Nginx版本

nginx -v

Nginx文件语法检测

nginx -t

Nginx的服务控制操作

sudo systemctl status nginx
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

一些网站的配置

DokuWiki网站的Nginx配置

安装php后,需要在配置文件中开启php功能。 以 vim /etc/nginx/sites-available/default 为例

        # 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;
        }

注意:fastcgi_pass中的php版本应与当前安装的版本一致

一些关于Nginx的问题

出现类似 nginx depends on nginx-core (>= 1.10.3-0ubuntu0.16.04.4) 的错误的解决办法:

首先看是否有 Apache2 服务正在启动,关闭它

sudo systemctl stop apache2.service

防止 Apache2 服务自启

sudo systemctl disable apache2.service

重新安装 Nginx

sudo apt-get install nginx

参考

安装 PHP

默认安装php

sudo apt-get install php

或者直接指定版本安装php

sudo apt-get install php7.0

查看安装的php版本(本次安装的为 php7.0)

php -v

安装php*-fpm模块

sudo apt-get install php7.0-fpm

安装其他可能需要的模块

sudo apt-get install php7.0-gd
sudo apt-get install php7.0-mbstring

php相关服务的控制

sudo systemctl start php7.0-fpm
sudo systemctl stop php7.0-fpm
sudo systemctl restart php7.0-fpm
sudo systemctl status php7.0-fpm

安装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 

权限

chown -R www-data:www-data /var/www/test && chmod -R 755 /var/www/test

一些问题的解决办法

nginx搭建php提示No input file specified.

打开fastcgi.conf

vim /etc/nginx/fastcgi.conf

设置fastcgi的可操作目录(防止跨站),在最后添加:

fastcgi_param PHP_VALUE open_basedir=/opt/:/tmp/;

重启nginx

service nginx restart

参考 http://www.fidding.me/article/105

安装 MySQL

注意事项

安装

卸载

完全移除Nginx

sudo apt-get --purge autoremove nginx

重置Nginx配置文件

sudo apt-get -o DPkg::options::=--force-confmiss --reinstall install nginx-common

怎么完全卸载、安装Nginx,参考:

查看已安装的相关软件(以nginx为例)

dpkg --get-selections | grep nginx

评论

请输入您的评论. 可以使用维基语法:
 
wiki/linux/ubuntu-install-nginx-php-mysql.1570268009.txt.gz · 最后更改: 2023/01/03 15:24 (外部编辑)