快如閃電的安裝php7.4套件(centos 7)

yyy123456發表於2020-11-16

本文只考慮centos7

本文編寫時間:2020-11-16
remi是一個php安裝倉庫。是rpm包。

本文各軟體版本

centos 7
php 7.4.12
nginx 1.18
mysql 8.0.22
redis 6.0.9
git 2.24.3 


首先,安裝阿里的 centos 倉庫。(centos 7)

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum makecache
yum repolist


安裝阿里的 epel 倉庫。(centos 7)

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum makecache
yum repolist


安裝阿里的 remi 的倉庫(centos 7)

yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm

sed -i  's/https*:\/\/rpms.remirepo.net/https:\/\/mirrors.aliyun.com\/remi/g'  /etc/yum.repos.d/remi*
sed -i 's/#baseurl/baseurl/g' /etc/yum.repos.d/remi*
sed -i 's|^mirrorlist|#mirrorlist|' /etc/yum.repos.d/remi*

yum makecache
yum repolist

yum -y install yum-utils


安裝 php(centos 7)

yum-config-manager --enable remi-php74

yum install -y php74 php74-php-devel  php74-php-fpm  php74-php-mbstring php74-php-memcache php74-php-memcached php74-php-redis  php74-php-mysqlnd  php74-php-pdo  php74-php-bcmath php74-php-xml php74-php-gd php74-php-gmp php74-php-igbinary php74-php-imagick   php74-php-mcrypt  php74-php-pdo_mysql php74-php-posix php74-php-simplexml  php74-php-opcache php74-php-xsl php74-php-xmlwriter php74-php-xmlreader php74-php-swoole php74-php-zip php74-php-phalcon  php74-php-yaml php74-php-yar php74-php-yaf php74-php-uuid

體驗到快如閃電的速度了吧!

安裝阿里的 composer 映象源(centos 7)

ln -s /usr/bin/php74 /usr/bin/php

curl -o /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar

chmod +x /usr/local/bin/composer

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 


安裝 nginx 並整合 php-fpm 服務(centos 7)

# 下面這個echo是一句命令,得一起復制

echo $'[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 ' > /etc/yum.repos.d/nginx.repo

# 上面是一條echo命令。

yum makecache
yum install -y nginx
systemctl enable nginx
systemctl enable php74-php-fpm
sed -i 's/user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i 's/group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i 's/listen\ =\ \/var\/opt\/remi\/php74\/run\/php-fpm\/www.sock/listen=9000/g' /etc/opt/remi/php74/php-fpm.d/www.conf

rm -f /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf

/etc/nginx/conf.d/default.conf 檔案內容如下

server {
    listen       80;
    server_name  localhost;
    charset utf-8 ;
    access_log  /var/log/nginx/host.access.log  main;
    root   /usr/share/nginx/html;
    index index.php  index.html index.htm;
    error_page 404  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

新增一個 php 檔案如下:

vi /usr/share/nginx/html/1.php

<?php
phpinfo();

啟動 php-fpm 和 nginx 並驗證安裝正確

systemctl start nginx
systemctl start php74-php-fpm

curl localhost/1.php
# 如果能看到很多的大量輸出,說明php和nginx正確安裝了。


安裝mysql 8(centos 7)

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo

# 下面這句安裝mysql服務,因為總下載大約530M,沒有辦法,時間大概3到5分鐘左右。

yum --enablerepo=mysql80-community install mysql-community-server

systemctl enable mysqld
systemctl start mysqld

# 檢視初始密碼:
grep 'temporary password' /var/log/mysqld.log

# 用檢視到的密碼進入mysql 的 shell
mysql -uroot -p

下面,整套設定新使用者流程,先改初始,再加新使用者並授權,再刪除老使用者。

set global validate_password.policy=LOW;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'aaaa1234';
flush privileges;
create user 'root'@'%' identified by 'root1234';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root1234';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
drop user root@localhost;
flush privileges;

退出shell,重新進入。

現在就可以直接進入shell

mysql -uroot -proot1234

# 這句話檢視使用者的加密方式。
select user, host, plugin from mysql.user\G;

# plugin: caching_sha2_password 表示老的MySQL客戶端無法連線!


安裝阿里映象源 ius 內的 git(centos 7)

安裝這個的理由是 centos7 帶的 git 大版本是 1,真的太老了。
另外這裡也一定要薅到阿里的羊毛~

yum install -y https://mirrors.aliyun.com/ius/ius-release-el7.rpm
sed -i  's/https:\/\/repo.ius.io/https:\/\/mirrors.aliyun.com\/ius/g'  /etc/yum.repos.d/ius*
yum makecache
yum install -y git224


安裝 redis 6 以及其他常用庫(centos 7)

yum --enablerepo=remi install -y redis
yum install -y  wget vim zip unzip p7zip rsync crontabs supervisor net-tools python3
systemctl enable redis
systemctl start redis

總結(centos 7)

用了國內映象會速度極快,下載包的速度:3MB/秒,驚人的快
mysql安裝有時也非常快,有時慢。本文只有mysql有點慢了。

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章