如何在Fedora 26上安装Apache,MySQL,PHP(LAMP)堆栈
时间:2020-03-05 15:27:58 来源:igfitidea点击:
Fedora 26已于alpha和beta版本发布后于2016年7月11日发布。
如果我们已经安装了Fedora 26并准备安装LAMP堆栈,那么本文将指导我们在Fedora 26上安装LAMP堆栈。
最新的fedora版本在其存储库中提供了最新版本的apache,mysql和php,因此在Fedora 26上安装LAMP堆栈时无需添加任何第三方存储库。
安装Apache
要安装Apache,请更新系统并使用dnf进行安装。
# sudo dnf install httpd
如果以上命令在下载软件包时停顿,请清除dnf数据库缓存,然后重新运行该命令。
# sudo dnf clean all
启用httpd服务并启动apache
# sudo systemctl enable httpd.service # sudo systemctl start httpd.service
使用以下命令检查Apache的版本。
# httpd -v Server version: Apache/2.4.27 (Fedora) Server built: May 12 2016 10:43:59
如果我们已经启用了防火墙,则使用以下两个命令启用通过系统防火墙对http或者https的访问。
# sudo firewall-cmd --add-service={http,https} --permanent # sudo firewall-cmd --reload
如果我们之前没有做过防火墙以确保安全,请安装并启用防火墙,然后执行上述两个命令。
# sudo dnf install firewalld -y # sudo systemctl start firewalld # sudo systemctl enable firewalld
使用以下命令检查httpd服务的状态。
# sudo systemctl status httpd.service
通过将Web浏览器指向“ http://Apache-Server-IP”来测试Apache Web服务器
安装MariaDB
使用以下命令安装最新的MariaDB,并在安装后从命令行使用mysql检查MariaDB的版本。
# sudo dnf install mariadb-server # mysql -V mysql Ver 15.1 Distrib 10.1.25-MariaDB, for Linux (x86_64) using readline 5.1
启动/启用mariaDB服务并检查其状态。
# sudo systemctl start mariadb.service # sudo systemctl enable mariadb.service # sudo systemctl status mariadb.service
(可选)我们可以使用'mysql_secure_installation'保护mariaDB安装。
# mysql_secure_installation
安装PHP
要安装最新的PHP,请在终端上使用以下命令
# sudo dnf install php php-common
现在,安装一些常用的php模块并重新启动apache,以使所有更改生效。
# sudo dnf install php php-common php-mysqlnd php-gd php-imap php-xml php-cli php-opcache php-mbstring # systemctl restart httpd
查找已安装的PHP版本
# php -v PHP 7.1.7 (cli) (built: May 6 2016 12:10:54) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.1.7, Copyright (c) 1999-2016, by Zend Technologies
在apache的文档根目录内创建一个php文件。
# vi /var/www/html/info.php <?php echo phpinfo(); ?>
将网络浏览器指向“ http://Server-IP/info.php”。