在Centos 8上安装PHP7

PHP是一种用于开发动态web页面的脚本web编程语言。

我们将安装最新版本的PHP, 搜索一下PHP的版本

# dnf module list php
Last metadata expiration check: 0:37:04 ago on Sat 11 Apr 2020 03:53:30 AM EDT.
CentOS-8 - AppStream
Name       Stream         Profiles                        Summary                    
php        7.2 [d]        common [d], devel, minimal      PHP scripting language     
php        7.3            common, devel, minimal          PHP scripting language     

Remi s Modular repository for Enterprise Linux 8 - x86_64
Name       Stream         Profiles                        Summary                    
php        remi-7.2       common [d], devel, minimal      PHP scripting language     
php        remi-7.3       common [d], devel, minimal      PHP scripting language     
php        remi-7.4       common [d], devel, minimal      PHP scripting language 

# dnf search php7 |grep installs|grep PHP
Last metadata expiration check: 0:36:37 ago on Sat 11 Apr 2020 03:53:30 AM EDT.
php70.x86_64 : Package that installs PHP 7.0
php71.x86_64 : Package that installs PHP 7.1
php72.x86_64 : Package that installs PHP 7.2
php73.x86_64 : Package that installs PHP 7.3
php74.x86_64 : Package that installs PHP 7.4

当前安装的PHP版本是PHP 7.2。

如果上面没有remi-7.4出现, 则需要先安装yum utils并启用remi-repository。 这样就可以使用Remi存储库安装最新版本的PHP。

# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

要安装新版本PHP 7.4,重置PHP模块。

# dnf module reset php

启用PHP 7.4模块

# dnf module enable php:remi-7.4

安装PHP、PHP- fpm (FastCGI进程管理器)和相关的PHP模块

# dnf install php php-opcache php-gd php-curl php-mysqlnd

如果下载不了,可以试试

# dnf module install php:remi-7.4

查看安装的PHP版本

# php -v 

启动PHP-FPM并使其在开机时自启动。

# systemctl start php-fpm
# systemctl enable php-fpm
# systemctl status php-fpm

如果设置了SELinux,允许Apache通过PHP-fpm来执行PHP代码

# setsebool -P httpd_execmem 1

重启apache web服务器

# systemctl restart httpd

测试, 在 */var/www/html/*中创建一个test.php文件。

test.php

<?php
 phpinfo ();
?>

用浏览器打开 http://服务器ip/test.php。 将能看到PHP的信息。

centos上安装php

安装MariaDB数据库

MariaDB是MySQL数据库的一个分支。它是由一个以前的MySQL团队开发的,他们担心Oracle会把MySQL变成一个闭源项目。它提供了比MySQL更好的创新功能,是MySQL的一个很好替代开源软件。

# dnf install mariadb-server mariadb -y

启动MariaDB服务,并设置在系统启动时自动启动

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb

第一次安装时,执行配置脚本

# 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, well need the current
password for the root user.  If youve just installed MariaDB, and
you havent 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设置root密码
New password:  输入新密码
Re-enter new password: 输入新密码
Remove anonymous users? [Y/n]  输入Y 删除匿名用户
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n]  Y

Thanks for using MariaDB!

尝试连接MariaDB

# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> quit
如何在CentOS 8上安装LAMP

LAMP是Linux、Apache、MySQL和PHP的首字母缩写,是一个流行的免费开放源代码的WEB服务堆栈,网站管理员和开发人员都使用它来测试和托管网站。

LAMP服务器有4个核心组件:Linux 系统,Apache web服务器、MySQL或MariaDB数据库和用于创建动态web页面的流行脚本语言PHP。

安装Apache Web服务器

在centos中,apache的web服务叫做httpd。 因为apache是一个非盈利机构,其下还有其他开源产品。httpd-tools 是方便管理httpd的工具。

# dnf install httpd httpd-tools 
Last metadata expiration check: 0:21:51 ago on Sat 11 Apr 2020 03:53:30 AM EDT.
Package httpd-2.4.37-11.module_el8.0.0+172+85fc1f40.x86_64 is already installed.
Package httpd-tools-2.4.37-11.module_el8.0.0+172+85fc1f40.x86_64 is already installed.
Dependencies resolved.

允许Apache在系统启动时自动启动,并启动httpd服务

# systemctl enable httpd
# systemctl start httpd

查看httpd版本

# httpd -v
# rpm -qi httpd

防火墙开放80端口

# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload

确认Apache web服务正在运行

# systemctl status httpd

也可以使用浏览器打开http://server-IP

更新CentOS 8软件包

在开始任何安装之前最好先进行软件包更新。

# dnf update
日期:2019-04-29 03:18:04 来源:oir作者:oir