云网牛站
所在位置:首页 > Linux云服务器 > 在Fedora 29系统上安装LAMP的详细步骤

在Fedora 29系统上安装LAMP的详细步骤

2019-01-23 11:41:25作者:叶云稿源:云网牛站

本文介绍在Fedora 29/Fedora 28系统上安装配置LAMP的详细步骤,采用Apache、MySQL/MariaDB、PHP构架,数据库可以是MySQL或者是MariaDB,不影响整体LAMP架构,本文采用的是MariaDB。

 

第1步:安装Fedora 29参考文章

我们选用的Linux操作系统版本是Fedora 29,先要安装它,请参考安装Fedora 29的方法及使用Vagrant运行Fedora 29系统一文。

 

第2步:安装基本软件包/将SELinux设置为Permissive

安装基本软件包,如vim、curl、wget、telnet:

sudo dnf -y update

sudo dnf -y install vim bash-completion curl wget telnet

如果这是你第一次操作SELinux,我建议将其置于Permissive模式或完全禁用它,运行以下命令检查SELinux状态:

# sestatus 

SELinux status:enabled

SELinuxfs mount:/sys/fs/selinux

SELinux root directory:/etc/selinux

Loaded policy name:targeted

Current mode:enforcing

Mode from config file:enforcing

Policy MLS status:enabled

Policy deny_unknown status:allowed

Memory protection checking:actual (secure)

Max kernel policy version:31

默认模式是强制执行,要将其置于允许模式,请执行:

sudo setenforce 0

sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

要完全禁用它:

sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

确认配置的持久状态:

$ cat /etc/selinux/config | grep SELINUX=

# SELINUX= can take one of these three values:

SELINUX=permissive

 

第3步:安装Apache httpd服务器

安装并更新Fedora系统后,继续安装Apache httpd服务器:

sudo dnf -y install httpd

然后配置httpd基本设置,编辑配置文件/etc/httpd/conf/httpd.conf并设置:

ServerAdmin admin@example.com

ServerName  example.com

ServerTokens Prod

可以选择设置Keepalive:

KeepAlive On

启用并启动httpd服务:

sudo systemctl start httpd

sudo systemctl enable httpd

如果你有firewalld运行,请允许http和https服务:

sudo firewall-cmd --add-service={http,https} --permanent

sudo firewall-cmd --reload

 

第4步:安装PHP和扩展

安装PHP并配置httpd以支持PHP脚本的执行,Fedora 29在其存储库中附带PHP 7.2(要安装PHP 7.3请参考在Fedora 29/Fedora 28系统下安装PHP 7.3的方法):

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-29.noarch.rpm

sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-29.noarch.rpm

安装PHP和常用扩展:

sudo dnf -y install php php-cli php-php-gettext php-mbstring php-mcrypt php-mysqlnd php-pear php-curl php-gd php-xml php-bcmath php-zip

输出信息大致如下:

安装:

php x86_64 7.2.11-1.fc29更新2.9 M

php-bcmath x86_64 7.2.11-1.fc29更新44 k

php-gd x86_64 7.2.11-1.fc29更新49 k

php-mbstring x86_64 7.2.11-1.fc29更新466 k

php-pecl-zip x86_64 1.15.4-1.fc29更新52 k

php-pear noarch 1:1.10.6-1.fc29 fedora 348 k

安装依赖项:

gd x86_64 2.2.5-7.fc29更新128 k

jbigkit-libs x86_64 2.1-15.fc29更新49 k

libX11 x86_64 1.6.7-1.fc29更新593 k

libX11-common noarch 1.6.7-1.fc29更新155 k

libtiff x86_64 4.0.9-13.fc29更新165 k

php-cli x86_64 7.2.11-1.fc29

确认已安装的PHP版本:

$ php -v

PHP 7.2.11 (cli) (built: Oct 9 2018 15:09:36) ( NTS )

可以通过将-m选项传递给phpcommand来查看加载的扩展:

$ php -m

在文件/etc/php.ini上设置PHP时区:

date.timezone = Africa/Nairobi

注:请根据自己所在地进行设置,以上时区设置不一定适合你,就注意更改。

 

第5步:在Fedora 29上安装MariaDB数据库

本文采用的是MariaDB数据库,当然你也可以采用MySQL数据库。

Fedora上游存储库有MariaDB 10.3,可以使用dnf命令安装:

sudo dnf install mariadb-server

安装后,设置字符集:

sudo vim /etc/my.cnf.d/mariadb-server.cnf

在[mysqld]部分下设置你的字符集:

[mysqld]

character-set-server=utf8

然后启动mariadb服务并使其在启动时启动:

sudo systemctl start mariadb

sudo systemctl enable mariadb

执行MariaDB初始设置,例如设置root密码,禁用远程root登录:

$ mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): 

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

... Success!

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!

这个时候就可以使用MariaDB了,不过需要回答如下问题:

输入root的当前密码(输入none):<Enter>

设置root密码? [是/否] y

删除匿名用户? [是/否] y

删除测试数据库并访问它? [是/否] y

现在重新加载权限表? [是/否] y

测试登录,如下图:

在Fedora 29系统上安装LAMP的详细步骤

创建和删除测试数据库,如下图:

在Fedora 29系统上安装LAMP的详细步骤

要删除数据库和用户,如下图:

在Fedora 29系统上安装LAMP的详细步骤

我们已确认我们的数据库工作正常,要允许远程连接,请允许防火墙上的端口3306:

sudo firewall-cmd --add-service=mysql --permanent 

sudo firewall-cmd --reload

你还可以限制来自其它网络的访问:

sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \

service name="mysql" source address="10.1.1.0/24" accept'

 

第6步:测试Lamp Stack安装

要在Fedora 29上进行Lamp安装的测试,先创建一个PHP测试页面:

sudo vim /var/www/html/phpinfo.php

加入:

<?php

// Show all information, defaults to INFO_ALL

phpinfo();

?>

在浏览器上重新加载httpd服务并打开页面:

sudo systemctl reload httpd

打开添加的PHP信息页面:http://[serverIP]/phpinfo.php(请换成自己的地址),会出现如下图的页面,标志着整个安装配置很成功:

在Fedora 29系统上安装LAMP的详细步骤

到这里,你已经在Fedora 29系统上完成安装LAMP的所有步骤了。

 

相关主题

Linux云服务器CentOS 7.4 64位PHP环境配置[LAMP]

精选文章
热门文章