安装源
wget http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
php安装
yum install php72w-fpm php72w-opcache php72w-cli php72w-pecl php72w-pear php72w-devel
yum install libzstd-devel -y
yum install glibc-headers gcc gcc-c++ cmake make -y
yum install openssl openssl-devel -y
yum install php72w-mysqlnd -y
php扩展模块安装
pecl install igbinary
pecl install libzstd
pecl install redis
pecl install swoole
############################################php7.4套件###############################################
本文各软件版本 参考:https://learnku.com/articles/51600
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客户端无法连接!
php源码安装参考
yum安装过程
- 安装 EPEL 软件包
1yum install epel-release -y - 安装 remi 源
1yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm - 安装 yum 扩展包
1yum -y install yum-utils - 启用 remi 仓库
1
2yum-config-manager --enable remi-php72
yum update - 安装php7.2
1yum install -y php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache - 设置开机自启
1systemctl enable php72-php-fpm.service源码安装
- 安装系统依赖
1
2yum install epel-release -y
yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y - 下载源码
1
2
3curl -O -L https://github.com/php/php-src/archive/php-7.2.3.tar.gz
tar -zxvf php-7.2.3.tar.gz
cd php-src-php-7.2.3 - 编译安装
1
2
3
4
5./buildconf --force
./configure --prefix=/usr/local/php --enable-fpm --disable-short-tags --with-openssl --with-pcre-regex --with-pcre-jit --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-gd --enable-intl --enable-mbstring --with-mysqli --enable-pcntl --with-pdo-mysql --enable-soap --enable-sockets --with-xmlrpc --enable-zip --with-webp-dir --with-jpeg-dir --with-png-dir
make clean
make
make install - php-fpm setup
1
2
3cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp php.ini-development /usr/local/php/etc/php.ini - 修改配置
1
2
3
4
5
6
7
8
9vim /usr/local/php/etc/php.ini
expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2
1
|
vim /usr/local/php/etc/php-fpm.d/www.conf
|
1
|
vim /usr/local/php/etc/php-fpm.conf
|
- php加入系统环境
1
2
3vim /etc/bashrc
export PHP_PATH=/usr/local/php
export PATH=$PHP_PATH/bin:$PATH -
启动php-fpm
1/usr/local/php/sbin/php-fpm -
修改执行 php-fpm 的权限
1
2
3
4vi /etc/opt/remi/php72/php-fpm.d/www.conf
# 设置用户和用户组为 nginx
user = nginx
group = nginx - 路径整理
1/etc/opt/remi/php72
php 5.3.3 以后的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,所以不要再看这种老掉牙的命令了
-
使用信号控制
1
2
3
4INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块 -
查看php-fpm的master进程
1ps aux | grep php-fpm | grep -v grep- 重启php-fpm
1
2# 最后的一串数字就是master进程的id
kill -USR2 44551
- 重启php-fpm
报错m4
解决参考 https://cloud.tencent.com/developer/article/1840123