CentOS 8.3 已发布有一段时间了,小编已经尝鲜过了,关于更新的功能网上很多,这里不在重复了,先给出下载地址:http://mirror.centos.org/centos/8/isos/
如果是centos 7.0的版本或者8.0其他版本,可以按照一下代码进行升级:yum update -y
查看版本信息:cat /etc/centos-release
本实例采用yum安装模式,如果希望使用编译安装,请查看本站另一篇文章:
一、安装nginx1.18
1,安装yum-utils,输入命令:yum install yum-utils
2,添加nginx源。CentOS8系统自带的nginx源版本是1.14,我们可以自己创建高版本的nginx源,
命令:vi /etc/yum.repos.d/nginx.repo
添加下列内容
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、查看nginx源,命令:yum info nginx
4,安装nginx,命令:yum install nginx
5,nginx基本命令,
开启 nginx:systemctl start nginx
停止nginx:systemctl stop nginx
重启nginx:systemctl reload nginx
开机启动nginx:systemctl enable nginx
二、安装多版本PHP
1、安装remi
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
2、安装PHP
yum install php56
yum install php56-php-fpm
yum install php72
yum install php72-php-fpm
yum install php80
yum install php80-php-fpm
想安装那个版本的PHP,上面PHP数字后面换成对应版本即可,安装后记得先不要启动的
3、配置selinux
要允许selinux运行php-fpms脚本,请运行以下命令:
semanage port -a -t http_port_t -p tcp 9056
semanage port -a -t http_port_t -p tcp 9072
semanage port -a -t http_port_t -p tcp 9081(此处按照规律应该是9080,但是我服务器这个端口被占用了,就使用9081了)
4、配置php-fpm
默认每个php-fpm版本都在9000端口上侦听,因为我们要运行多个php版本,所以我们需要更改默认端口:
sed -i ‘s/:9000/:9056/’ /etc/opt/remi/php56/php-fpm.d/www.conf
sed -i ‘s/:9000/:9072/’ /etc/opt/remi/php72/php-fpm.d/www.conf
sed -i ‘s/:9000/:9081/’ /etc/opt/remi/php80/php-fpm.d/www.conf
每个PHP的www.conf修改为
listen = 127.0.0.1:9056
listen = 127.0.0.1:9072
listen = 127.0.0.1:9081
5、启动
systemctl start php56-php-fpm
systemctl start php72-php-fpm
systemctl start php80-php-fpm
加入开机启动
systemctl enable php56-php-fpm
systemctl enable php72-php-fpm
systemctl enable php80-php-fpm
6、安装需要的PHP扩展
yum install php72-php-redis
yum install php72-php-swoole
yum install php72-php-mbstring
yum install php72-php-gd
yum install php72-php-xml
……
注:手动增加扩展,下载模块上传到下面文件夹
/opt/remi/php71/root/lib64/php/modules
添加ini文件在一下文件夹
/etc/opt/remi/php71/php.d
三、安装MySQL数据库
1、禁用MySQL默认的AppStream存储库:
sudo dnf remove @mysql
sudo dnf module reset mysql && sudo dnf module disable mysql
2、centos8没有MySQL存储库,我们使用centos 7存储库。创建一个新的存储库文件:
sudo vim /etc/yum.repos.d/mysql-community.repo
插入一下代码:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0
3、安装MySQL(这里我选择MySQL5.7)
sudo dnf – -enablerepo=mysql57-community install mysql-community-server
4、下载完成后检查版本
yum repolist enabled | grep “mysql-community“
出现以下信息说明成功:
mysql-connectors-community MySQL Connectors Community 141
mysql-tools-community MySQL Tools Community 105
mysql57-community MySQL 5.7 Community Server
5、启动、重启、加入开机启动、查看启动状态MySQL
systemctl start mysqld
systemctl restart mysqld
systemctl enable mysqld
systemctl status mysqld
6、获取安装mysql后生成的临时密码,用于登录
grep ‘temporary password’ /var/log/mysqld.log
最后的字符即时临时密码
7、登陆修改密码(如果不想密码太复杂输入set开头的命令)
登陆:mysql -uroot -p
修改MySQL设置密码限制:
mysql>
set global validate_password_policy=0;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;
上面命令执行过之后可以修改密码了:
mysql> set password for ‘root’@’localhost’=password(‘123456’);
四、配置nginx的PHP环境,安装之后nginx默认情况下是不解析PHP的配置如下:
修改/etc/nginx/nginx.conf
在最后大括号上面添加
include /etc/nginx/conf.d/*.conf;
然后在conf.d文件夹里面添加域名配置
location ~ .php$ {
root /mydata/web/php;
fastcgi_pass 127.0.0.1:9072; #这里用哪个PHP版本,就改成对应的端口即可
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启php72-php-fpm
到此配置完成
评论0