备份原来的源
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的相关包及配置
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
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/
卸载原有mysql :
net stop msyql
mysqld -remove
下载:
https://dev.mysql.com/downloads/mysql/
ps:如果装之前装过数据库文件删除mysql目录下的data文件夹
1、初始化数据库:
mysqld --initialize --console
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