温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Ubuntu上怎么搭建LAMP环境

发布时间:2022-01-25 14:36:58 来源:亿速云 阅读:121 作者:iii 栏目:开发技术

本篇内容主要讲解“Ubuntu上怎么搭建LAMP环境”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Ubuntu上怎么搭建LAMP环境”吧!

LAMP是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件: Linux,操作系统; Apache,网页服务器; MySQL,数据库管理系统(或者数据库服务器); PHP 和有時 Perl 或 Python,脚本语言。

Ubuntu上怎么搭建LAMP环境

第1步:安装Apache

Apache是一个免费开源软件,可运行世界上50%的Web服务器。

要安装apache,打开终端并键入以下命令:

sudo apt-get update
sudo apt-get install apache2

而已。 要检查是否安装了Apache,请将浏览器指向您服务器的IP地址(例如http://12.34.56.789)。 该页面应该显示的话“它的工作!”像这样 。

如何查找您的服务器的IP地址您可以运行以下命令来显示您的服务器的IP地址。

ifconfig eth0 | grep inet | awk '{ print $2 }'

第2步:安装MySQL

MySQL是一个强大的数据库管理系统,用于组织和检索数据

要安装MySQL,请打开终端并键入以下命令:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

在安装过程中,MySQL会要求您设置root密码。 如果你错过了在程序安装时设置密码的机会,以后很容易从MySQL shell中设置密码。

一旦你安装了MySQL,我们应该用这个命令激活它:

sudo mysql_install_db

通过运行MySQL设置脚本完成:

sudo /usr/bin/mysql_secure_installation

提示将要求您输入当前的root密码。

输入。

Enter current password for root (enter for none):

OK, successfully used password, moving on...
然后提示将询问您是否要更改root密码。 继续,选择N并继续下一步。

这是最简单只是说是的所有选项。 最后,MySQL将重新加载和实现新的更改。

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

一旦你完成了,你可以通过安装PHP完成。

第3步:安装PHP

PHP是一种开源的Web脚本语言,广泛用于构建动态网页。要安装PHP,请打开终端并键入此命令。

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

在您对提示两次回答yes之后,PHP将自行安装。它也可能是有用的添加php到目录索引,以提供相关的php索引文件:

sudo nano /etc/apache2/mods-enabled/dir.conf

将index.php添加到索引文件的开头。 页面现在应该如下所示:

&ltIfModule mod_dir.c>

         DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm

&lt/IfModule>

PHP模块,PHP还有各种有用的库和模块,您可以将其添加到虚拟服务器上。 您可以查看可用的库。

apt-cache search php5-
终端将显示可能的模块列表。 开头是这样的:

php5-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5-cli - command-line interpreter for the php5 scripting language
php5-common - Common files for packages built from the php5 sourcephp5-curl - CURL module for php5
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-gmp - GMP module for php5
php5-ldap - LDAP module for php5
php5-mysql - MySQL module for php5
php5-odbc - ODBC module for php5
php5-pgsql - PostgreSQL module for php5
php5-pspell - pspell module for php5
php5-recode - recode module for php5
php5-snmp - SNMP module for php5
php5-sqlite - SQLite module for php5
php5-tidy - tidy module for php5
php5-xmlrpc - XML-RPC module for php5
php5-xsl - XSL module for php5
php5-adodb - Extension optimising the ADOdb database abstraction library
php5-auth-pam - A PHP5 extension for PAM authentication
[...]

一旦您决定安装该模块,请键入:

sudo apt-get install name of the module

通过使用空格分隔每个模块的名称,可以一次安装多个库。恭喜! 你现在有LAMP在你的Droplet!

第4步:结果 – 请参阅您的服务器上的PHP

虽然安装了LAMP,我们仍然可以通过创建一个快速的PHP信息页面来查看组件在线要进行设置,首先创建一个新文件:

sudo nano /var/www/info.php
在以下行中添加:

然后保存并退出。

重新启动apache以使所有更改生效:

sudo service apache2 restart

访问您的PHP信息页面完成(确保您替换示例IP地址与您正确的IP地址):http://12.34.56.789/info.php,它应该类似于此。

到此,相信大家对“Ubuntu上怎么搭建LAMP环境”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI