ubuntu nginx + php7.2 + mysql5.7环境搭建
  WI9e1qFIlIft 2023年11月01日 59 0

一、换源

备份原来的源

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

更换源

sudo gedit /etc/apt/sources.list

阿里源 (Ubuntu 18.04)

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

更新

sudo apt-get update

复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。

sudo apt-get -f install

更新软件

 sudo apt-get upgrade

二、安装PHP

删除php的相关包及配置

sudo apt-get autoremove php7*

可以通过 apt list | grep php7 命令查看是否有php7.2的包,ubuntu16.04默认是有7.0的。
当然,一如既往,首先更新Ubuntu:

apt-get update && apt-get upgrade

添加PHP存储库

sudo apt-get install software-properties-common

接下来,从Ondřej添加PHP存储库:

add-apt-repository ppa:ondrej/php

最后,更新安装包:

sudo apt-get update

安装PHP 7.2

sudo apt-get install php7.2

nginx使用php需要安装php7.2-fpm, 和一些php插件

sudo apt-get install php7.2-mysql php7.2-fpm php7.2-curl php7.2-xml php7.2-gd php7.2-bcmath php7.2-mbstring php-memcached php7.2-zip
php -v

在这里插入图片描述

上述安装php命令会自动安装apache2服务,可以通过 service apache2 status 查看

sudo service apache2 stop
sudo apt remove apache2*
sudo  apt autoremove

开启php报错

找到php.ini
locate php.ini
添加
display_errors=On

三、安装Nginx

apt install nginx
service nginx status #查看状态

在这里插入图片描述
配置php-fpm
有时候安装完成后不知道安装到什么地方啦可以使用下面命令查找下

whereis php-fpm

我的在这里

php-fpm: /usr/sbin/php-fpm7.2

修改nginx配置/etc/nginx/sites-available/default (这个地方是默认的配置文件,也可以加在其他地方)

sudo vi /etc/nginx/sites-available/default
# pass PHP scripts to FastCGI server
# location ~ \.php$ {
	include snippets/fastcgi-php.conf;
#
#	# With php-fpm (or other unix sockets):
	fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#	# With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
	include fastcgi_params;
}
}

最终配置文件:

在这里插入代码片

配置nginx
修改站点根目录访问权限

sudo chmod -R 777 /var/www/html/

在这里插入图片描述

四、安装msyql(win数据库服务器)

卸载原有mysql :

net stop msyql
mysqld -remove

在这里插入图片描述

下载:

https://dev.mysql.com/downloads/mysql/

ps:如果装之前装过数据库文件删除mysql目录下的data文件夹

1、初始化数据库:

mysqld --initialize --console

得到初始密码
在这里插入图片描述
2、将mysql安装为windows的服务:

mysqld -install

3、启动mysql服务
输入net start mysql或sc start mysql

net start mysql

4、登录数据库

Mysql -uroot -p

5、修改数据库口令

alter user 'root'@'localhost' identified by  “123456789;

6、配置远程登录

update user set Host='%' where User='root';

刷新权限

flush privileges;

五、安装应用(我这里装了个metinfo)
直接扔到web目录

/var/www/html

在这里插入图片描述
在这里插入图片描述

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
WI9e1qFIlIft
作者其他文章 更多