ubuntu的web服务器_如何将家用Ubuntu PC变成LAMP Web服务器

ubuntu的web服务器

ubuntu的web服务器

banner

Got a Linux PC you want to put to work? Maybe you’re not comfortable with the command-line only version of Ubuntu Server Edition. Here’s how to keep the standard Ubuntu desktop and add web-serving capabilities to it.

有想要使用的Linux PC吗? 也许您对仅命令行版本的Ubuntu Server Edition不满意。 以下是保留标准Ubuntu桌面并为其添加Web服务功能的方法。

Whether you’re not comfortable with a command-line only system, you’re using your Ubuntu desktop for other things, or you just need it installed for a few particular apps, you can add Apache, MySQL, and PHP to any standard desktop installation of Ubuntu very quickly and easily.

无论您是对仅命令行系统还是不满意,是将Ubuntu桌面用于其他用途,还是只需要为一些特定的应用程序安装它,都可以将Apache,MySQL和PHP添加到任何标准桌面非常快速,轻松地安装Ubuntu。

简单命令 (The Simple Command)

Let’s start installation with the use of a very clever command:

让我们使用一个非常聪明的命令开始安装:

sudo apt-get install lamp-server^

须藤apt-get install lamp-server ^

It will NOT work without the caret at the end. Once you’ve got that entered, you’ll see that it auto-selects all of the necessary packages and will ask you to confirm the “large” amount of data to be downloaded.

没有最后的插入符,它将无法工作。 输入后,您会看到它会自动选择所有必要的程序包,并要求您确认要下载的“大量”数据。

02 confirm

Just sit back and let it do its thing until you get a blue screen pop up.

只要坐下来,让它做事情,直到弹出蓝屏。

03 mysql root password

Enter a password for the MySQL root account, which is what you’ll need to create other users and manage databases, then hit Enter to continue. You’ll be prompted to re-enter your password, so do that and hit Enter again.

输入MySQL根帐户的密码,这是创建其他用户和管理数据库所需的密码,然后按Enter键继续。 系统将提示您重新输入密码,然后重新输入密码。

That’s it for installation!

安装即已完成!

测试Apache和PHP (Testing Apache and PHP)

Let’s test Apache to see if it’s serving properly. Open up a browser and direct it the following URL:

让我们测试一下Apache,看看它是否正常运行。 打开浏览器,并将其指向以下URL:

http://localhost/

http://本地主机/

You should see something like this appear if everything installed correctly:

如果一切都正确安装,您应该看到如下所示:

05 testing apache

Next up, we’ll test to see if PHP is working. In terminal, enter the following command to create a new document:

接下来,我们将测试PHP是否正常运行。 在终端中,输入以下命令以创建一个新文档:

sudo nano /var/www/testing.php

须藤纳米/var/www/testing.php

Then, copy the following code:

然后,复制以下代码:

<?php phpinfo(); ?>

<?php phpinfo(); ?>

Right-click in your terminal and hit paste.

右键单击您的终端,然后单击粘贴。

07 phpinfo
08 nano write-out

Hit CTRL+O to “write-out” or save the file, and then hit CTRL+X to quit.

按CTRL + O以“写出”或保存文件,然后按CTRL + X退出。

Next, restart Apache with the following command:

接下来,使用以下命令重新启动Apache:

sudo service apache2 restart

sudo服务apache2重新启动

And load up the following page in your web browser:

并在您的Web浏览器中加载以下页面:

http://localhost/testing.php

http://localhost/testing.php

And you should see something like this:

而且您应该看到类似以下内容的内容:

10 php success

检查MySQL绑定地址 (Checking MySQL Bind Address)

MySQL has a bind address that should match your system’s. To check your system’s bind address, we can use a quick command:

MySQL的绑定地址应与您的系统匹配。 要检查系统的绑定地址,我们可以使用快速命令:

cat /etc/hosts | grep localhost

猫/ etc / hosts | grep本地主机

That’s a “pipe” or a “stem” in the middle, which is shared with the \ key. You’ll get a couple of results, one of which will show you an IP address.

这是中间的“管道”或“茎”,与\键共享。 您将获得几个结果,其中一个结果将为您显示IP地址。

11 find localhost bind address

You can see from the screenshot above that my bind address is 127.0.0.1.

您可以从上面的屏幕截图中看到我的绑定地址是127.0.0.1。

Next, let’s open up the MySQL config file to see what’s listed there.

接下来,让我们打开MySQL配置文件以查看其中列出的内容。

sudo nano /etc/mysql/my.cnf

须藤nano /etc/mysql/my.cnf

Scroll down until you see a line beginning with “bind-address” like below.

向下滚动,直到看到以“ bind-address”开头的行,如下所示。

12 my.cnf bind address good

As you can see, the bind-address is the same, so we’re good. If yours is different, just change it so it matches what you found above.

如您所见,bind-address是相同的,所以我们很好。 如果您的与众不同,则只需对其进行更改,使其与您在上面找到的内容匹配。

安装phpMyAdmin (Installing phpMyAdmin)

If you’re not familiar with MySQL and its commands, then you may have some trouble managing databases and tables. phpMyAdmin helps you tackle that by providing a PHP interface for MySQL administration. It’s easy to install and can really come in handy, so let’s get to it.

如果您不熟悉MySQL及其命令,那么在管理数据库和表时可能会遇到麻烦。 phpMyAdmin通过为MySQL管理提供PHP接口来帮助您解决这一问题。 它易于安装,并且真的可以派上用场,所以让我们开始吧。

sudo apt-get install phpmyadmin

须藤apt-get install phpmyadmin

If this command doesn’t work, you may need to enable additional repositories.

如果此命令不起作用,则可能需要启用其他存储库。

14 installing phpmyadmin

You’ll get another blue screen come up asking you to choose which web server to configure. Make sure the red block is next to “apache2” and be SURE to hit the Space bar. This will mark it with an asterisk, and then you can hit Enter.

您将看到另一个蓝屏,要求您选择要配置的Web服务器。 确保红色方块位于“ apache2”旁边,并确保按下空格键。 这将用星号标记它,然后您可以按Enter。

15 select apache2 for phpmyadmin

You’ll be asked if phpmyadmin should configure a default database for its own use. Choose Yes.

系统将询问您phpmyadmin是否应配置一个默认数据库供自己使用。 选择是。

16 yes to default db

Next, you’ll be asked to enter the password of the admin account used to create this database and user. Since we haven’t created any other MySQL users, enter your MySQL root password.

接下来,将要求您输入用于创建此数据库和用户的管理员帐户的密码。 由于我们尚未创建任何其他MySQL用户,因此请输入您MySQL根密码。

17 enter mysql root password

Lastly, you’ll create a password to use with phpmyadmin, and you’ll have to confirm it again.

最后,您将创建一个可与phpmyadmin一起使用的密码,并且必须再次进行确认。

18 password for phpmyadmin

Once you’re done, restart Apache.

完成后,重新启动Apache。

You can log in to phpMyAdmin by going to the following URL:

您可以通过以下URL登录到phpMyAdmin:

http://localhost/phpmyadmin/

http:// localhost / phpmyadmin /

20 phpmyadmin success

Use “root” as the username and then enter the root MySQL password.

使用“ root”作为用户名,然后输入MySQL的root密码。

21 login success


There’s more than a few important passwords here, and you’ll be tempted to use the same password as your root account. If you choose to do this, be sure that it’s a very secure password, something with mixed character classes and a good length. Remember, you are giving others access to your computer by installing this software, so take proper precautions.

这里有许多重要的密码,您将很想使用与根帐户相同的密码。 如果选择这样做,请确保它是一个非常安全的密码,包含混合字符类和适当长度的密码。 请记住,通过安装此软件,您可以使他人访问您的计算机,因此请采取适当的预防措施。

If this is your first time playing with a web server, you may be wondering where the files you want to host go. They’re in /var/www/ be default, and will need elevated privileges to access that directory. One idea is to mount a separate partition to that point to be used solely for serving web stuff. Check out our other article, What is the Linux fstab and How Does It Work?, to get some more information for that.

如果这是您第一次使用Web服务器,则您可能想知道要托管的文件在哪里。 它们默认位于/ var / www /中,并且需要提升的特权才能访问该目录。 一种想法是将一个单独的分区安装到该点,以仅用于提供Web服务。 请查看我们的另一篇文章, 什么是Linux fstab以及它如何工作? ,以获取更多信息。

And, now that you have your own web server, why not learn How To Archive, Search, and View Your Tweet Statistics with ThinkUp?

而且,既然您拥有自己的Web服务器,为什么不学习如何使用ThinkUp存档,搜索和查看Tweet统计信息呢?

翻译自: https://www.howtogeek.com/howto/42480/how-to-turn-your-home-ubuntu-pc-into-a-lamp-web-server/

ubuntu的web服务器

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值