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

1.首先輸入用戶名和密碼進行登陸php

2.升級更新軟件包html

sudo apt-get updatemysql

sudo apt-get upgradenginx

判斷都填ysql

3.安裝nginx數據庫

sudo apt-get install nginx瀏覽器

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

4.安裝數據庫php7

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

輸入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.2-fpm.sock;
#	# With php-cgi (or other tcp sockets):
#	fastcgi_pass 127.0.0.1:9000;
}

注意:fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;修改成fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

由於我安裝的是php7.2 查看路徑/run/php/php7.2-fpm.sock 以下目錄所指:

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/

相關文章
相關標籤/搜索