1. 程式人生 > >ubuntu18.04 安裝配置nginx+php+mysql

ubuntu18.04 安裝配置nginx+php+mysql

2018-08-17 15:15:09 1.首先輸入使用者名稱和密碼進行登入

2.升級更新軟體包

sudo apt-get update

sudo apt-get upgrade

判斷都填y

3.安裝nginx

sudo apt-get install nginx

在瀏覽器輸入你的ip地址測試是否安裝成功

4.安裝資料庫

sudo apt-get install mysql-server php7.2-mysql

輸入mysql -u root -p 測試資料庫安裝是否成功

quit 可以退出

5.安裝php-fpm

sudo apt-get install php7.2-fpm

6.配置php-fpm

sudo vi /etc/php/7.2/fpm/php.ini

將;cgi.fix_pathinfo=1改成cgi.fix_pathinfo=0(還要去掉分號) 位置在全屏狀態下的40%的第一行,看右下角

修改儲存內容的方法自己檢視vi 的操作

7.重啟php-fpm

sudo service php7.2-fpm restart

8.解決nginx開啟php檔案總是顯示下載php檔案的問題

sudo 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 PHP scripts to FastCGI server
#

#location ~ .php$ { #include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; #}

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

}

去掉註釋儲存

location ~ .php$ { include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; }

9.重啟nginx

sudo service nginx restart

10.測試nginx是否解析php

cd /var/www/html

sudo vi phpinfo.php

在phpinfo.php中輸入

<?php phpinfo(); ?>

11.修改許可權

1)首先進入伺服器根目錄 cd /var/www/html

2)再使用chmod sudo chmod 777 html/