CentOS转Ubuntu上Nginx+PHP+MySQL
at 2022-12-04 16:08:47, by 鹏城奋青
背景:在CentOS上PHP8需要自己编译,过程非常麻烦并且编译到最后make test还会发现有几十个cases不通过,那种不知道哪里会出问题的感觉总挥之不去,怕它哪一天突然崩出来。正好CentOS被转为Stream了,于是决定转用Ubuntu罢。
在Ubuntu22上PHP8.1有预编包非常方便,Nginx也有。
1、先移除apache2
sudo apt purge apache2
2、安装php8.1
sudo apt install php8.1
3、安装php8.1-fpm
sudo apt install php8.1-fpm
4、安装nginx
sudo apt install nginx
5、这一步按自己的项目文件布局来即可,主要是写关于项目的虚拟机conf,我将项目放到一个其他人可读的目录下,然后在其中创建关于nginx的目录,如:/opt/dist/tracer/web/nginx/conf/server.conf
server {
listen 80;
server_name tracer.wisforce.com;
index index.html index.php;
root /opt/dist/tracer/web;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#注意:因为php-fpm走的是unix socket,可以在/etc/php/8.1/fpm/pool.d/www.conf 看到
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}
6、启动nginx
systemctl restart nginx
7、启动php8.1-fpm
systemctl restart php8.1-fpm
8、记得将项目目录用户组更为www-data,这是ubuntu下nginx和php约定使用用户组。
chown -R www-data:www-data /opt/dist/tracer/web
9、安装MySQL-8.0-Server
apt install mysql-server-8.0
9、以上是主要步骤,有些微操可能有些区别。