63

详解:在Ubuntu上安装并配置LAMP

 5 years ago
source link: https://www.linuxprobe.com/ubuntu-lamp.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
导读 LAMP是一组用于使Web服务器启动和运行的开源软件。 首字母缩写代表Linux,Apache,MySQL和PHP。 由于虚拟专用服务器已经在运行Ubuntu,所以linux部分被处理。 这里是如何安装其余的。
第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 for
them.  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 source
php5-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,它应该类似于此。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK