安装部分必要软件
apt-get install curl vim wget unzip apt-transport-https lsb-release ca-certificates
Nginx安装
- 增加key
wget -O /etc/apt/trusted.gpg.d/nginx-mainline.gpg https://packages.sury.org/nginx-mainline/apt.gpg
- 增加源
cat >> /etc/apt/sources.list.d/nginx.list << EOF
deb https://mirror.xtom.com.hk/sury/nginx-mainline/ $(lsb_release -sc) main
EOF
- 更新源并安装
apt-get update
apt-get install nginx-extras
- 设置系统启动
systemctl enable nginx
- 查看版本
nginx -v
PHP安装
- 加入
gpg
wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg
- 加入源
sh -c ‘echo “deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list’
- 更新源
apt-get update
- 安装
PHP7.2
apt install php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip php7.2-opcache -y
- 修改
php.ini
防止跨目录攻击
sed -i ‘s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/’ /etc/php/7.2/fpm/php.ini
- 开启
php-fpm
service php7.2-fpm start
- 开机启动
systemctl enable php7.2-fpm
nginx
配置新站点
vim /etc/nginx/sites-enabled/example.com.conf
server {
listen 80;
listen [::]:80;
# 指定网站目录,可根据自己情况更换,建议放在 /var/www 目录下
root /var/www/example.com;
index index.php index.html index.htm;
# 默认第一个域名,替换 example.com 为您的域名
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
# 开启 PHP7.2-fpm 模式,如需要安装 PHP 7.1.x 请修改为 fastcgi_pass unix:/run/php/php7.1-fpm.sock;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
- 重启
nginx
service nginx restart
- 验证
vim /var/www/example.com/phpinfo.php
<?php phpinfo(); ?>
- win10 hosts文件添加域名
127.0.0.1 example.com
- 浏览器输入
http://example.com/phpinfo.php
server {
listen 80;
listen [::]:80;
root /var/www/example.com;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
MySQL安装
- 使用
Percona Server
代替原生的MySQL
- 导入
Percona Server
的官方源
wget https://repo.percona.com/apt/percona-release_0.1-5.$(lsb_release -sc)_all.deb
dpkg -i percona-release_0.1-5.$(lsb_release -sc)_all.deb
- 更新源
apt-get update
- 安装mysql
apt-get install percona-server-server-5.7
-
输入两次root密码
-
开启服务,检查版本
service mysql start
mysql -V
- 开机启动
systemctl enable mysql
- 修改root密码,允许root用户远程登录
mysql -u root -p
mysql> use mysql;
mysql> set password for root@localhost = password('root');
mysql> update user set host='%' where user='root';
mysql> select host, user from user;
mysql> flush privileges;