广告

本站里的文章大部分经过自行整理与测试

2017年1月16日星期一

LNMP 安装

1. 关闭 Apache (如果有安装)

$ su

$ systemctl stop apache2
$ systemctl disable apache2

$ systemctl stop httpd
$ systemctl disable httpd

2. 安装 Nginx / PHP / MySql

Ubuntu
$ apt install nginx php php-mysql php-fpm mysql-server

Fedora
$ dnf install nginx php php-mysqlnd php-fpm mariadb-server

CentOS
$ yum install nginx php php-mysql php-fpm mariadb-server

OpenSUSE
$ zypper install nginx php7 php7-mysql php7-fpm mysql-community-server

$ cp /etc/php7/fpm/php-fpm.conf.default /etc/php7/fpm/php-fpm.conf
$ cp /etc/php7/fpm/php-fpm.d/www.conf.default /etc/php7/fpm/php-fpm.d/www.conf

3. 设置

$ mysql_secure_installation

3.1) 编辑 php.ini

Ubuntu
$ gedit /etc/php/7.0/fpm/php.ini
Fedora / CentOS
$ gedit /etc/php.ini
OpenSUSE
$ gedit /etc/php7/cli/php.ini

cgi.fix_pathinfo=0

3.2) 编辑 nginx.conf / default

server {
        listen 80;
        listen [::]:80 default_server;
        
server_name member.dlinkddns.com;
root /var/www/html;

        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ =404;
        }
}

Ubuntu

$ gedit /etc/nginx/sites-available/default

server {
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}

CentOS

$ gedit /etc/nginx/nginx.conf

server {
       location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
            include fastcgi_params;
      }
}

Fedora

$ gedit /etc/nginx/nginx.conf

server {
       location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
            include fastcgi_params;
      }
}

OpenSUSE

$ gedit /etc/nginx/nginx.conf

server {
        location ~ \.php$ {
              root /srv/www/htdocs/;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_param SCRIPT_FILENAME  /srv/www/htdocs$fastcgi_script_name;
              fastcgi_index index.php;
              include fastcgi_params;
      }
}

3.3) 编辑 www.conf (Ubuntu 可跳过)

Fedora / CentOS
$ gedit /etc/php-fpm.d/www.conf
OpenSUSE
$ gedit /etc/php7/fpm/php-fpm.d/www.conf

; CentOS
listen = /var/run/php-fpm/php-fpm.sock
; Fedora
listen = /var/run/php-fpm/www.sock
; OpenSUSE
listen = 127.0.0.1:9000

listen.owner = nobody
listen.group = nobody

user = nginx
group = nginx

4. 重启

$ systemctl restart php-fpm

$ nginx -t
$ systemctl reload nginx
$ systemctl enable nginx

5. 测试

Ubuntu / Fedora / CentOS
$ gedit /var/www/html/test.php

OpenSUSE
$ gedit /srv/www/htdocs/test.php

<?
phpinfo();
?>

http://127.0.0.1/test.php

没有评论:

发表评论