系统版本:CentOS 7.6.1810(最小化安装)。
本教程不关闭防火墙,不关闭 SELinux,使用 REMI 和 EPEL 源。
如果要查看你的版本,执行:
[root@pluvet ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
设置时区
[root@pluvet ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@pluvet ~]# yum -y install ntpdate
[root@pluvet ~]# ntpdate ntp.ntsc.ac.cn
安装 MySQL(MariaDB)
[root@pluvet ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
[root@pluvet ~]# yum -y install epel-release
[root@pluvet ~]# yum -y install mariadb-server mariadb
[root@pluvet ~]# systemctl start mariadb.service
[root@pluvet ~]# systemctl enable mariadb.service
[root@pluvet ~]# mysql_secure_installation
之后会问你:Enter current password for root (enter for none):
输入回车,然后重新设置一个复杂的密码,接下来一路回车,就装好了。
安装 httpd(Apache)
[root@pluvet ~]# yum -y install httpd
[root@pluvet ~]# systemctl start httpd.service
[root@pluvet ~]# systemctl enable httpd.service
防火墙运行 http(s) 服务
[root@pluvet ~]# firewall-cmd --permanent --zone=public --add-service=http
[root@pluvet ~]# firewall-cmd --permanent --zone=public --add-service=https
[root@pluvet ~]# firewall-cmd --reload
安装 php7.3
本来想装 7.4 的,不过现在还不稳定,算了。
[root@pluvet ~]# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@pluvet ~]# yum -y install yum-utils
[root@pluvet ~]# yum update
[root@pluvet ~]# yum-config-manager --enable remi-php73
[root@pluvet ~]# yum-config-manager --enable remi-php73
[root@pluvet ~]# yum -y install php php-opcache
[root@pluvet ~]# systemctl restart httpd.service
接下来测试。
[root@pluvet ~]# vi /var/www/html/info.php
写入:
<?php
phpinfo();
访问:http://(公网ip)/info.php
。看到:
PHP Version 7.3.6
就说明 php 和 Apache 没得问题。
安装 php 扩展
这个各取所需,不是非要装不可。
[root@pluvet ~]# yum install -y php73-php-pdo php73-php-mysqlnd php73-php-gd php73-php-ldap php73-php-json php73-php-odbc php73-php-pear php73-php-xml php73-php-xmlrpc php73-php-mbstring php73-php-soap curl-devel
[root@pluvet ~]# systemctl restart httpd.service
别忘了删除 phpinfo 页面,不安全。
[root@pluvet ~]# rm -f /var/www/html/info.php
安装 phpMyAdmin
这个正式用的时候就别装了。这里还是记录一下:
[root@pluvet ~]# yum -y install phpMyAdmin
[root@pluvet ~]# vi /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
Require all granted # 别漏了这一行
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
[root@pluvet ~]# vi /etc/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['auth_type'] = 'http';
[root@pluvet ~]# systemctl restart httpd.service