ubuntu mysql apache_如何在Ubuntu搭建Web服务器--使用Mysql+PHP+Apache--入门
发布日期:2021-06-24 13:37:57 浏览次数:3 分类:技术文章

本文共 2956 字,大约阅读时间需要 9 分钟。

最近被安排搞一个实验,新手入门,学习如何搭建服务器,做了点笔记,适合像我一样的菜鸟小白,如有大佬,自可指点迷津,望见谅。

部分内容网上搜索而得,如侵权,请告知。

好了,正式开始。

先说一下有几个问题:

1.Linux搭建服务器的好处: 主流的云服务器太贵,Linux的比较稳定一些

2.Php和Apache的关系: Php是语言,超文本预处理器,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。 而Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。

3.Linux中的包管理器:a.Linux的常用包管理其 apt rpm yum 安装系统的时候没有,我们需要自己手动安装,就想我们安装和卸载程序一样。 b.Ubuntu默认的包管理器是apt,而rpm和yum是Redhat的软件包管理器。 c.Ubuntu绝大多数用apt就够了,我们也可以使用剩下两种包管理器。

如何安装rpm? 直接使用命令 apt install rpm

如何安装yum? 直接使用命令 apt install yum

查看apt管理的所有包,使用命令 apt list

查看apt所有已经安装的包,使用命令 apt list --installed

一、在Ubuntu系统下安装mysql

1.开启Ubuntu系统,然后打开一个终端,直接获取root权限,使用命令 sudo su ,然后输入你设定的系统的密码,如图所示。

2.然后在Ubuntu上安装mysql,我们使用如下几条命令就可以安装完成

apt-get install mysql-server

apt-get install mysql-client

apt-get install libmysqlclient-dev

在安装过程中可能会出现如下提示

输入Y表示同意,我们可以直接敲击回车表示同意,安装过程可能会慢一些,稍微等待一下就好了。

3.Ubuntu安装net-tools

使用命令 apt install net-tools就可以安装完成啦。

4.下面我们检查mysql是否已经安装成功

使用命令 sudo netstat -tap | grep mysql , 如果看到有mysql的socket处于监听状态这就表示我们已经安装成功了

5.然后我们登录mysql数据库看看:

使用命令 mysql -u root -p 该命令中 -u表示选择一个登录的用户, root就是我们所选择的用户, -p表示该登录用户的密码,我们输入完成这条命令之后会提示我们输入密码,此时我们输入密码就可以登录到mysql,默认会有一个root用户,密码为空。

我们可以使用命令 show databases; 查看当前的数据库,某些mysql命令后一定要记得加上分号,否则无法执行的。

使用命令quit 可以直接退出mysql

二、在Ubuntu中安装Apache2

1.Ubuntu安装Apache2

使用命令apt-get install apache2 ,出现提示后直接敲回车表示同意就OK了

2.安装完成后,我们检查一下是否安装成功,我们在Ubuntu系统中打开浏览器,一般为Firefox自带的浏览器就可以,在浏览器中输入地址 http:localhost,检查本地服务器,安装成功截图如下

3.有关Apache的默认的一些目录

默认文档根目录是在 /var/www目录下

配置文件是在 /etc/apache2/apache2.conf

配置存储的子目录在 /etc/apache2目录下

4.重启和关闭Apache服务器

我们一般使用重启Apache服务器多一些,且一般开机会自动启动。

a.重启Apache服务器 sudo /etc/init.d/apache2 restart

b.开启Apache服务器 sudo /etc/init.d/apache2 start

c.关闭Apache服务器 sudo /etc/init.d/apache2 stop

三、安装PHP

1.我们这里将该安装的扩展都安装一下,可能比较多,安装时间比较长,为以后少一些不必要的麻烦,使用命令

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:ondrej/php && sudo apt-getupdate

sudo apt-get -y install php7.2

如果之前有其他版本的PHP,将其禁用掉,使用如下禁用命令

sudo a2dismod php5

sudo a2enmod php7.2

安装一些常用的扩展,这里建议大家安装一下,使用命令

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-getinstall php7.2-gd

sudo apt-getinstall php7.2-soap

sudo apt-getinstall php7.2-gmp

sudo apt-getinstall php7.2-pspell

sudo apt-getinstall php7.2-bcmath

sudo apt-getinstall php7.2-enchant

sudo apt-getinstall php7.2-imap

sudo apt-getinstall php7.2-ldap

sudo apt-getinstall php7.2-opcache

sudo apt-getinstall php7.2-readline

sudo apt-getinstall php7.2-sqlite3

sudo apt-getinstall php7.2-xmlrpc

sudo apt-getinstall php7.2-bz2

sudo apt-getinstall php7.2-interbase

sudo apt-getinstall php7.2-pgsql

sudo apt-getinstall php7.2-recode

sudo apt-getinstall php7.2-sybase

sudo apt-getinstall php7.2-xsl

sudo apt-getinstall php7.2-dba

sudo apt-getinstall php7.2-phpdbg

sudo apt-getinstall php7.2-snmp

sudo apt-getinstall php7.2-tidy

sudo apt-getinstall php7.2-zip

到此安装完成。

转载地址:https://blog.csdn.net/weixin_33218985/article/details/113143622 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:xiaocms不支持mysql_IIS+php 不支持mysql的一个问题以及解决
下一篇:apache php mysql 下载_windows下安装apache+php+mysql

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月08日 06时33分26秒