如何在CentOS 6安装Linux,Apache,MySQL,PHP(LAMP)

来源:互联网 发布:java编程那些事儿 编辑:程序博客网 时间:2024/04/28 08:56

原创官网
http://www.howtoing.com/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6/


关于LAMP

LAMP是一组用于使Web服务器启动和运行的开源软件。首字母缩写代表Linux,Apache,MySQL和PHP。由于服务器已经运行CentOS,所以linux部分被处理。这里是如何安装其余的。

建立

本教程中的步骤要求虚拟专用服务器上的用户具有root权限。你可以看到如何设置了在初始服务器设置教程第3步和4。

第一步 - 安装Apache

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

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

sudo yum install httpd

一旦安装,你可以启动apache运行在你的VPS上:

sudo service httpd start

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

如何查找您的服务器的IP地址

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

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

第二步 - 安装MySQL

MySQL是一个强大的数据库管理系统,用于在虚拟服务器上组织和检索数据

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

sudo yum install mysql-serversudo service mysqld start

在安装过程中,MySQL会要求您两次许可。在你对两者都说“是”之后,MySQL将安装。

一旦完成安装,您可以设置根MySQL密码:

sudo /usr/bin/mysql_secure_installation

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

因为你刚刚安装MySQL,你很可能不会有一个,所以留空,按enter键。

Enter current password for root (enter for none): OK, successfully used password, moving on...

然后提示将询问您是否要设置root密码。继续,选择Y,然后按照说明进行操作。

CentOS自动化设置MySQL的过程,问你一系列是或否的问题。

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

By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y                                             ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore 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 farwill take effect immediately.Reload privilege tables now? [Y/n] y ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!

第三步 - 安装PHP

PHP是一种开源的Web脚本语言,广泛用于构建动态网页。

要在虚拟专用服务器上安装PHP,请打开终端并键入以下命令:

sudo yum install php php-mysql

一旦你对PHP提示符回答yes,PHP将被安装。

PHP模块

PHP还有各种有用的库和模块,您可以将其添加到服务器上。您可以通过键入以下内容查看可用的库:

yum search php-

然后终端将显示可能的模块列表。开头是这样的:

php-bcmath.x86_64 : A module for PHP applications for using the bcmath libraryphp-cli.x86_64 : Command-line interface for PHPphp-common.x86_64 : Common files for PHPphp-dba.x86_64 : A database abstraction layer module for PHP applicationsphp-devel.x86_64 : Files needed for building PHP extensionsphp-embedded.x86_64 : PHP library for embedding in applicationsphp-enchant.x86_64 : Human Language and Character Encoding Supportphp-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp-imap.x86_64 : A module for PHP applications that use IMAP

要查看有关每个模块的更多详细信息,请在终端中键入以下命令,使用要了解的任何库替换模块的名称。

yum info name of the module

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

sudo yum install name of the module

通过使用空格分隔每个模块的名称,可以一次安装多个库。

恭喜!你现在有LAMP在你的Droplet!

我们还应该将进程设置为在服务器启动时自动运行(Apache一旦启动就会自动运行):

sudo chkconfig httpd onsudo chkconfig mysqld on

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

虽然LAMP安装在虚拟服务器上,但我们仍然可以通过创建快速PHP信息页面查看组件在线

要进行设置,首先创建一个新文件:

sudo nano /var/www/html/info.php

在以下行中添加:

<?phpphpinfo();?>

然后保存并退出。

重新启动apache以使所有更改在虚拟服务器上生效:

sudo service httpd restart

访问您的PHP信息页面完成(确保您替换示例IP地址与您正确的IP地址):http://12.34.56.789/info.php

它应该类似于此 。

查看更多

安装灯泡后,你可以继续使用MySQL(做多一个基本的MySQL教程 ), 创建一个SSL证书 ,或安装FTP服务器 。

原创官网
http://www.howtoing.com/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6/




0 0
原创粉丝点击