zoukankan      html  css  js  c++  java
  • 使用Ubuntu搭建Web服务器

    在VMware上搭建虚拟机的教程可以参考这篇文章:
    Click Here

    如果已经安装过Linux虚拟机或者主机上本来就是Linux系统的朋友请略过,直接看以下内容。

    首先在自己的ubuntu上搭建服务器环境

    切换到root权限

    sudo su
    

    然后输入你的密码,就进入到了root权限。这很重要,不在root权限下没法进行下载。

    下载Apache2

    apt-get install apache2
    

    在这里插入图片描述

    记得下载前要换源,将源换为国内的一些比较快的源,比如清华源、阿里源等。具体操作参考上面安装虚拟机的最后一部分,不然默认源是国外的源,下载速度会比较慢。

    下载完以后是这样子
    在这里插入图片描述
    然后打开刘浏览器访问127.0.0.1,可以看到这个:
    在这里插入图片描述
    这个是安装Apache以后的默认页面。出现这个证明Apache安装成功。

    或者可以在terminal下输入ifconfig查看自己的ip
    在这里插入图片描述
    如果ifconfig的时候报错的话需要

    apt-get install net-tools
    

    然后可以在主机上访问这个ip,发现效果一样,这个就已经是一个初步的服务器了。

    在这里插入图片描述

    安装MySQL

    执行命令:

    apt-get install mysql-server
     
    apt-get install mysql-client
     
    apt-get install libmysqlclient-dev
    

    检查是否安装成功:

    sudo netstat -tap | grep mysql
    

    在这里插入图片描述
    然后登陆MySQL看看:

    mysql -u root -p   回车
    输入密码(初始密码是root)
    

    然后就进入了MySQL:
    在这里插入图片描述
    可以使用show databases;查看当前已经存在的数据库:

    在这里插入图片描述
    输入exit退出
    在这里插入图片描述

    关于数据库的操作后续还会介绍,这里就不多讲了。

    接下来安装PHP

    输入命令:

    sudo apt-get install software-properties-common
    
    sudo add-apt-repository ppa:ondrej/php && sudo apt-get update
    
    sudo apt-get -y install php7.2
    

    输入php -v可以查看当前php的版本信息。
    在这里插入图片描述

    然后安装常用扩展:

    sudo apt-get -y install php7.2-fpm php7.2-mysql php7.2-curl php7.2-json php7.2-mbstring php7.2-xml  php7.2-intl php7.2-odbc php7.2-cgi
    

    还有其他的一些扩展(按需下载)

    sudo apt-get install php7.2-gd
    sudo apt-get install php7.2-soap
    sudo apt-get install php7.2-gmp      
    sudo apt-get install php7.2-pspell     
    sudo apt-get install php7.2-bcmath   
    sudo apt-get install php7.2-enchant    
    sudo apt-get install php7.2-imap       
    sudo apt-get install php7.2-ldap       
    sudo apt-get install php7.2-opcache
    sudo apt-get install php7.2-readline   
    sudo apt-get install php7.2-sqlite3    
    sudo apt-get install php7.2-xmlrpc
    sudo apt-get install php7.2-bz2
    sudo apt-get install php7.2-interbase
    sudo apt-get install php7.2-pgsql      
    sudo apt-get install php7.2-recode     
    sudo apt-get install php7.2-sybase     
    sudo apt-get install php7.2-xsl     
    sudo apt-get install php7.2-dba 
    sudo apt-get install php7.2-phpdbg     
    sudo apt-get install php7.2-snmp       
    sudo apt-get install php7.2-tidy       
    sudo apt-get install php7.2-zip
    

    安装完以后,一个基本的服务器就安装完成了,接下来就开始激动人心的Hello World!了~

    cd /var/www/html
    ls    #列出当前目录下只有一个index.html文件
    rm index.html    #删掉index.html
    echo Hello World! > index.php
    

    然后浏览器刷新一下/或者重新访问127.0.0.1
    在这里插入图片描述
    一个基本的Apache + PHP + MySQL服务器就搭建完成啦~

  • 相关阅读:
    m-n的随机整数 包括m n
    获取url参数 hash类型
    js 数组转带空格字符串
    产生n-m的随机数组
    js 判断android、IOS
    判断是否微信浏览器
    文本左右对齐方式css
    H5微信支付流程
    H5微信授权登录流程
    H5页面 input禁止弹出键盘
  • 原文地址:https://www.cnblogs.com/shenjuxian/p/13739100.html
Copyright © 2011-2022 走看看