1、跑命令
sudo apt-get update
sudo apt-get upgrade2、安装add-apt-repository命令
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php && sudo apt-get update
sudo apt-get -y install php7.2-fpm3、安装常用扩展
sudo apt-get install php7.2-mysql php7.2-curl php7.2-json php7.2-mbstring php7.2-xml4、安装nginx
sudo apt-get install nginx
5、安装mysql
#切换管理员权限
sudo su
#安装mysql服务器端和客户端
apt-get install mysql-server mysql-client6、编辑nginx配置文件
cd /etc/nginx/sites-available
cp default php
vim php
cd sites-enabled
rm default
ln -s /etc/nginx/sites-available/php /etc/nginx/sites-enabled/php
server {
#注意,一台服务器,只能有一个default_server!!!其他项目配置文件,直接将default_server这个单词删掉即可。
listen 80;
#listen [::]:80 default_server;
#自己的项目路径
root /var/www/cms;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
#改成自己的真实域名,如果不改表示本机(localhost)
server_name _;
#重定向
# return 301 https://域名/$request_uri;
#根据框架需求,配置url重写
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
#或者
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
7、thinkphp配置
修改这个配置文件
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}8、laravel 配置
location / {
try_files $uri $uri/ /index.php?$query_string;
}9、重启Nginx和php7.2-fpm
service nginx restart
nginx -t10、修改权限,上传项目(laravel只需给public和storage最高权限)
cd /var/www
chmod -R 777 cms
复制命令:ln -s /etc/nginx/sites-available/php /etc/nginx/sites-enabled/php