参考网站:http://www.liyblog.top/p/9
1.nginx 和 php 基本安装
1. 更新 apt
apt update
2. 安装 nginx
apt install nginx
3. 查看 nginx 状态
systemctl status nginx
4. 安装 php
apt install php php-fpm
apt-get install php7.2 php7.2-fpm
5. 查看 php 版本(ubuntu 默认安装 php7.2)
php -v
2.nginx 配置 php-fpm
1. 查看 nginx 具体位置,查找 nginx 配置文件位置(当前是在 /etc/nginx )
whereis nginx
2. 进入站点配置目录
cd /etc/nginx/sites-available
3. 配置站点信息
server 配置注意:
1.listen 80; 设置监听端口
2.root/var/www/html 设置项目目录
3.index index.php 设置站点目录入口文件
4.server_name www.liyblog.top 设置站点域名
5.php 配置见下图代码
6.fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; (配置 socket,要配置相对应版本的 php)
7. 删除 /etc/nginx/sites-enabled/default 文件
8. 链接到站点目录 ln -s /etc/nginx/sites-available/blog/etc/nginx/sites-enabled/blog (这一步很重要必须执行)
server {
listen 80;
#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](http://www/html);
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name [www.default.](http://www.liyblog.top/)com;
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;
#}
}
3. 安装配置 mysql
1. 安装 mysql
apt install mysql-server
2. 查看 mysql
netstat -tap | grep mysql
3. 设置 mysql 初始密码
mysql_secure_installation
4. 安装配置 phpmyadmin
1. 安装 phpmyadmin
apt install phpmyadmin
** 注意:Web 自动选择: apache ,lightd 一个都不选!
2.nginx 配置 phpmyadmin
1)、为了统一,将 phpmyadmin ln 到 /var/www
sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin
2)、直接 cp default 过来修改
cd /etc/nginx/sites-available/
sudo cp default phpmyadmin
3)sudo vim /etc/nginx/site-available/phpmyadmin
修改这个 phpmyadmin 以下 2 处
listen 999;(此处需要在阿里云平台放行 999 端口)
root /var/www/phpmyadmin;
4)、连接到 sites-enabled
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin
5)测试、重启 nginx 服务
sudo nginx -t
必须测试正确!
sudo systemctl restart nginx
3. 访问 phpmyadmin (需要加上 index.php)
phpmyadmin 账户
默认用户名:phpmyadmin
密码:自己设置的密码
来源:CSDN
作者:tank_ft
链接:https://blog.csdn.net/tank_ft/article/details/103881801