ubuntu19 安装php nginx

 

2、备份apt源的配置文件:

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

作为一个好的开发者一定要学会备份。

3、打开apt源的配置文件

sudo vim /etc/apt/sources.list

4、清空sources.list文件内的所有内容,vim命令模式下输入下面命令

:%d

5、把下面的阿里云源复制到sources.list文件内

## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu/ bionic main
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ bionic multiverse
# deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# 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

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

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

6、保存并退出,vim命令行模式下输入以下命令

:wq

7、更新apt源

sudo apt update

二、安装Nginx服务器

sudo apt install -y nginx

等待安装完毕后,我们打开浏览器输入127.0.0.1测试看看,出现以下画面就说明安装成功了

 

Nginx访问成功页面

三、安装php7.3

本来想讲安装7.2的,这样可能会方便一些,不过想了一下,php7.4都快要出来了,况且我自己也用着php7.3也没啥问题,直接讲最新的吧。但是Ubuntu的阿里云源还没更新到PHP7.3,这里我们就要手动添加ppa源了,不知道ppa源是什么的可以去百度一下吧,这里就不做多余的解释了。

1、安装software-properties程序,为了方便我们使用ppa源下载

sudo apt-get install software-properties-common

2、添加PHP的ppa源

sudo add-apt-repository ppa:ondrej/php

3、更新apt源

sudo apt-get update

4、安装php7.3

sudo apt-get install -y php7.3 php7.3-fpm

这里不仅限于安装php7.3了,想安装PHP7.2的可以把7.3换成7.2,看你们想要什么版本就安装什么版本,这里我以最新的去讲。

安装快要结束了,apt给我们报了个错误,如下图:

 

php7.3安装报错

看到错误了,先不要慌,看看报错上写的是什么,错误上说Apache未能启动或启动失败,我一想,会不会是Ubuntu19.04上预装了Apache,来检查一下就知道了,输入如下命令:

apache2 -v

 

查看Apache版本

果然,Apache不愧是老大哥啊,咋哪都有他,不过没事,看图中PHP7.3是安装上的了,你们也可以自己检查一下,命令为:

php -v

既然PHP没问题,那么我们把Apache给干掉把,我这人强迫症,留着碍眼,万一哪天Nginx报错了就有可能是Apache搞的鬼,输入以下命令卸载掉Apache和其的相关依赖:

sudo apt autoremove -y apache2

到这里PHP就安装完了,需要安装一些别的扩展的,可以去根据自己的PHP版本去apt源里搜索对应的扩展进行安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值