分类:笔记 日期:2020-04-19 作者:caocaofff 浏览:1207
目的:作为应急使用,希望用最少的时间搭建好一个集成 nginx、php7.2、mysql的环境,可供临时测试或网站演示需要。
环境:
操作系统:Ubuntu1804
网络:IPv4,需开放22、80端口,能连外网
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/debian/ stretch nginx" | tee /etc/apt/sources.list.d/nginx.list
echo "deb-src http://nginx.org/packages/debian/ stretch nginx" | tee -a /etc/apt/sources.list.d/nginx.list
apt-get update
apt-get install nginx
配置文件路经:/etc/nginx/conf.d
建议先备份默认配置文件:
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
编辑默认配置文件:
vim /etc/nginx/conf.d/default.conf
内容举例:
server {
listen 80;
server_name localhost;
root /www;
index index.php;
location / {
}
location ~ \.php$ {
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
apt-get install software-properties-common
add-apt-repository -y ppa:ondrej/php
apt update
apt-get install php7.2 php7.2-mysql php7.2-fpm php7.2-curl php7.2-xml php7.2-gd php7.2-mbstring php7.2-memcached php7.2-zip php7.2-yac php7.2-opcache php7.2-redis
查看php版本以确认安装成功
php -v
配置php-fpm
vim /etc/php/7.2/fpm/pool.d/www.conf
找到以下内容,并用英文分号注释
;listen = /run/php/php7.2-fpm.sock
换成下面的内容
listen = 127.0.0.1:9000
确认nginx和php-fpm的运行用户必须一致是www-data(可跳过,因为默认就是www-data)
vim /etc/nginx/nginx.conf
看一下开头是否有以下内容
user www-data;
启动php-fpm和nginx
service php7.2-fpm start
service nginx start
apt-get install mysql-server
安装结束后,启动服务
service mysql start
进入到mysql中:
mysql -uroot -p
无需输入密码,直接进入mysql
【可跳过】修改mysql的root用户密码,这里举例把密码改成admin
grant all privileges on *.* to 'root'@'% ' identified by 'root' with grant option;
use mysql;
update user set authentication_string=PASSWORD("admin") where User='root';
刷新权限
flush privileges;
但是一般情况下,我们不去使用root用户,需要新建普通用户
create user 'admin'@'localhost' identified by 'admin';
添加bbs数据库权限给admin
grant all privileges on bbs.* to 'admin'@'localhost';
刷新权限
flush privileges;
【谨慎操作】也可以删除用户
delete from mysql.user Where user='admin';
最后退出
quit
CC版权: 本篇博文采用《CC 协议》,转载必须注明作者和本文链接