如何在Fedora 22上安装LAMP(Linux,Apache,MySQL,PHP)

ygst / 2023-05-03 / 原文

介绍 LAMP堆栈是一组用于启动和运行Web服务器的开源软件。 首字母缩略词代表Linux,Apache,MySQL和PHP。 由于服务器已经在运行Fedora,因此需要处理Linux部分。以下是安装其余部分的方法。 准备 在开始这个教程之前,你应该有一个正在运行的Fedora 22 腾讯云CVM并通过SSH登录。 没有服务器的同学可以在这里购买,不过我个人更推荐您使用免费的腾讯云开发者实验室进行试验,学会安装后再购买服务器。 建立 在开始安装LAMP程序之前,首先应该使用dnf update dnf替换yum作为Fedora在22版中的默认包管理器下载并安装所有更新: sudo dnf update 第一步 - 安装Apache Apache是一款免费的开源软件,运行着全球50%以上的Web服务器。 要安装apache,请打开终端并输入以下命令:

sudo dnf install httpd

安装完成后,您可以在VPS上启动apache:

sudo systemctl start httpd.service

就是这样。要检查Apache是否已安装,请将浏览器指向服务器的IP地址(例如http://12.34.56.789)。
您应该看到默认的Fedora页面: 如何找到您的腾讯云CVM的IP地址 您可以运行以下命令来显示服务器的IP地址。 ifconfig eth0 | grep inet | awk '{ print $2 }'

   第二步 - 安装MySQL 
    MySQL / MariaDB是一个功能强大的数据库管理系统,用于在虚拟服务器上组织和检索数据。
	要安装MySQL,请打开终端并输入以下命令:
	
	sudo dnf install mysql mysql-server
	
	sudo systemctl start mariadb.service
	
	完成安装后,您可以设置root MySQL密码: 
	
	sudo /usr/bin/mysql_secure_installation 
	
	提示将询问您当前的root密码。 由于您刚刚安装了MySQL,因此您很可能没有安装MySQL,因此请按Enter键将其留空。 
	
	Enter current password for root (enter for none): OK, successfully used password, moving on... 
	
	然后提示将询问您是否要设置root密码。继续选择Y并按照说明操作。 
	Fedora自动化设置MySQL的过程,向您询问一系列是或否的问题。 
	
对所有选项说&ldquo;是&rdquo;最容易。最后,MySQL将重新加载并实施新的更改。</p>
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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, MariaDB 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...
​
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
​
Thanks for using MariaDB!

第三步 - 安装PHP

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

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

sudo dnf install php php-mysql

一旦你对PHP提示回答yes,PHP将自行安装。
PHP模块

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

dnf search php-

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

php-fpdf-doc.noarch : Documentation for php-fpdf
php-libvirt-doc.noarch : Document of php-libvirt
php-pear-Auth-radius.noarch : RADIUS support for php-pear-Auth
php-pear-Auth-samba.noarch : Samba support for php-pear-Auth
ice-php-devel.i686 : PHP tools for developping Ice applications
ice-php-devel.x86_64 : PHP tools for developping Ice applications
perl-PHP-Serialization.noarch : Converts between PHP's serialize() output and
                              : the equivalent Perl structure
php-IDNA_Convert.noarch : Provides conversion of internationalized strings to
                        : UTF8
php-Kohana.noarch : The Swift PHP Framework
php-LightweightPicasaAPI.noarch : A lightweight API for Picasa in PHP
php-PHPMailer.noarch : PHP email transport class with a lot of features
php-Smarty.noarch : Template/Presentation Framework for PHP
php-ZendFramework.noarch : Leading open-source PHP framework
php-ZendFramework-Auth-Adapter-Ldap.noarch : Zend Framework LDAP
                                           : Authentication Adapter
php-ZendFramework-Cache-Backend-Apc.noarch : Zend Framework APC cache backend

要查看有关每个模块执行操作的更多详细信息,请在终端中键入以下命令,将模块的名称替换为您要了解的库。

dnf info name of the module

决定安装模块后,键入:

sudo dnf install name of the module

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

恭喜!你现在在你的液滴上有LAMP堆叠!

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

sudo chkconfig httpd on
sudo chkconfig mariadb on

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

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

要进行此设置,请先安装nano文本编辑器并创建一个新文件:

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

添加以下行:



然后保存并退出。

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

sudo systemctl restart httpd.service

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

它看起来应该类似于:

想要了解更多关于安装LAMP的相关教程,请前往腾讯云+社区学习更多知识。


参考文献:《How To Install LAMP (Linux, Apache, MySQL, PHP) on Fedora 22》