IT技术

Ubuntu 搭建php7+Nginx+MySQL
作者:
来源: 本站
发布日期: 2019/6/20 11:09:53
点击量: 1471次
【 字体:
背景颜色:


1. 下载安装php7.0、php7.0-fpm及其他常用模块
sudo apt-get install -y php7.0
sudo apt-get install -y php7.0-fpm
sudo apt-get install -y php-zip
sudo apt-get install -y php-dompdf
sudo apt-get install -y php-xml
sudo apt-get install -y php-mbstring
sudo apt-get install -y php-curl
sudo apt-get install -y php-mysql

2. 下载安装Nginx(1.10.3)
sudo apt-get install -y nginx
1
3. 配置Nginx
修改/etc/nginx/sites-available下的default文件
# Add index.php to the list if you are using PHP
index.php index index.html index.htm index.nginx-debian.html;
1
2
在server项中找到关于php的配置并启用


location ~ \\.php$ {
                include snippets/fastcgi-php.conf;
                #With php7.0-cgi alone:
                #fastcgi_pass 127.0.0.1:9000;
                #With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }





4. 测试服务器
重启Nginx:
重启php7.0-fpm
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php7.0-fpm restart
1
2
在/var/www/html目录下新建一个php文件
<?php
phpinfo();
?>



安装MySQL

安装mysql

$ sudo apt-get install mysql-server-5.6 mysql-client-5.6

途中会提示设置MySQL的密码,安装好后:

$ mysql -uroot -p
 
然后输入刚刚设置的密码,能成功进入即成功安装。



FAQ
修改nginx默认端口号
在/etc/nginx/sites-available/default中修改server项中的端口监听
listen 8080 default_server;
listen [::]:8080 default_server;
1
2
修改默认站点目录
root /var/www/html;
1
启用php错误提示
修改php.ini配置文件/etc/php/7.0/fpm/php.ini
# display_errors = Off
displau_errors = On
# error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
error_reporting = E_ALL | E_STRICT


unable to bind listening socket for address '/run/php/php7.1-fpm.sock' no such file or directory

启动命令:sudo /etc/init.d/php7-fpm start

php启动的时候报这个错误!

手动创建 目录 mkdir -pv /run/php/




 
Ubuntu 16.04下载软件速度有点慢,因为默认的是从国外下载软件,那就更换到国内比较好的快速更新源(就是这些软件所在的服务器),一般直接百度Ubuntu更新源就能出来一大堆,这时候最好是找和自己Ubuntu版本一致的更新源,我的Ubuntu版本是16.04,下面是我找到的一个比较好的更新源。


1.寻找国内镜像源


https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/






2.配置source  list源


sources.list系统自带的,源是来Ubuntu的官网!安装包比较慢,所以最好切换成国内的


linuxidc.com@ubuntu:~$ cd /etc/apt
linuxidc.com@ubuntu:/etc/apt$ sudo cp sources.list sources.list.bak
linuxidc.com@ubuntu:/etc/apt$ vim sources.list                                                 


# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse


# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse


3. 更新源


linuxidc.com@ubuntu:/etc/apt$ sudo apt-get update 
命中:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
命中:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease        
命中:3 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease      
命中:4 http://mirrors.aliyun.com/ubuntu xenial-security InRelease        
正在读取软件包列表... 完成 


测试:安装sl包
linuxidc.com@ubuntu:/etc/apt$ sudo apt-get install sl


linuxidc.com@ubuntu:/etc/apt$ sl






4.其他一些命令


sudo apt-get update  更新源
sudo apt-get install package 安装包
sudo apt-get remove package 删除包
sudo apt-cache search package 搜索软件包
sudo apt-cache show package  获取包的相关信息,如说明、大小、版本等
sudo apt-get install package --reinstall  重新安装包
sudo apt-get -f install  修复安装
sudo apt-get remove package --purge 删除包,包括配置文件等
sudo apt-get build-dep package 安装相关的编译环境
sudo apt-get upgrade 更新已安装的包
sudo apt-get dist-upgrade 升级系统
sudo apt-cache depends package 了解使用该包依赖那些包
sudo apt-cache rdepends package 查看该包被哪些包依赖
sudo apt-get source package  下载该包的源代码
sudo apt-get clean && sudo apt-get autoclean 清理无用的包
sudo apt-get check 检查是否有损坏的依赖





deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse             
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse          
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse     
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse               
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse             
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse 


sudo apt-get update  && sudo apt-get -y upgrade//更新一下列表


docker run -it -d --name webln -p 80:80 -v /d/dockerwww:/mmt/www lnweb  /bin/bash

扫一扫在手机打开当前页

Contact

联系我们

告诉我们您想要的吧!我们为当地客户提供专业、及时的服务
地址:云南省昆明市白云路368号
电话:400-871-8716 (工作时间:09:00-18:00(周一至周五))
何总:23592693
李总:53815112