目录
1、安装环境准备
ubuntu 18.04 (适用windows运行方式)
版本:PHP-7.2 ;Nginx-1.14; Mysql-5.7
2、操作步骤
Step_1:检测软件包列表
sudo apt list
sudo apt search all | grep php
Step_2:更新软件包
sudo apt update
sudo apt upgrade
Step_3:安装软件包
sudo apt install nginx
sudo apt install php7.2
sudo apt install php7.2-fpm
sudo apt install mysql
启动服务:
Nginx服务:
service nginx start #启动服务
ps -ef | grep nginx #查看运行状态
nginx -v #版本号
PHP服务:
service php7.2-fpm start
ps -ef | grep php-7.2-fpm
php -v
MYsql服务:
service mysql start
ps -ef | grep mysql
Step_4:配置环境
Nginx配置:
1.创建配置文件 并 建立软链接(方便开启或关闭配置)
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.conf
ln -s /etc/nginx/sites-enabled/default.conf /etc/nginx/sites-available/default.conf
2. 配置端口 80;root目录;server_name;
开启include snippets/fastcgi-php.conf;和fastcgi_pass unix:/var/run/php7.2-fpm.sock;
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;
root /srv/web;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name www.ps.cn;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
user:www-data #用户配置
#权限查看
cat /etc/passwd | grep 用户
cat /etc/group | grep 组名
whoami #当前用户
#权限设置
chown -R www-data:www-data /srv/www/
groupadd www-data
useradd -s /sbin/nologin -g www-data www-data
3.检测并重启nginx:
service nginx -t #检查配置是否成功
service nginx restart #重启nginx服务
service php7.2-fpm restart #重启php服务
依赖检查及启动:
systemctl enable php-fpm #开机启动
netstat -lnt | grep 9000 #端口检测 使用端口时
whereis php-fpm #实用查找
echo "<?php phpinfo(); ?>" > index.php
Step_5:访问测试
浏览器虚拟IP访问,输出phpinfo信息。
或
配置windows hosts文件,添加新一行内容
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 www.ps.cn # 新增虚拟机ip对应域名
访问域名:http://www.ps.cn
Step_6:注意事项
a/ 如windows环境运行 linux系统注意事项,开启windows子系统并按照ubuntu系统。
b/ 安装包版本选择,根据apt list查找对应版本。
c/ 系统安装目录选择;etc/系统配置 var/数据log usr/软件程序 srv/service站点代码。
d/ nginx配置 虚拟主机(独立域名不用默认default.conf ),及软连接配置。
e/ 服务启动及检查配置。
3、参考
ubuntu配置:
https://jingyan.baidu.com/article/fc07f989a357db12ffe519fd.html
https://www.sysgeek.cn/apt-vs-apt-get/
ngnix安装:
https://blog.youkuaiyun.com/github_37501169/article/details/73441847
https://www.zhaokeli.com/article/8496.html
https://www.cnblogs.com/crazytata/p/9686490.html
linux系统:
https://blog.youkuaiyun.com/zyddj123/article/details/82497640
https://www.cnblogs.com/silence-hust/p/4319415.html
https://blog.youkuaiyun.com/weixin_38750084/article/details/82903030