和 CentOS
的命令一样
一些其他辅助命令
Nginx
安装基本编译环境
sudo yum -y install gcc gcc-c++ # nginx编译时依赖gcc环境
sudo yum -y install pcre pcre-devel # 让nginx支持重写功能
sudo yum -y install zlib zlib-devel # zlib库提供了很多压缩和解压缩的方式,nginx使用zlib对http包内容进行gzip压缩
sudo yum -y install openssl openssl-devel # 安全套接字层密码库,用于通信加密
下载源码包
下载 pcre2
下载 zlib
源码包放到 /usr/local/src
下解压
解压三个源码压缩包
编译Nginx
cd nginx-1.23.3
./configure --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/logs/nginx.pid --with-http_ssl_module --with-pcre=../pcre2-10.42 --with-zlib=../zlib-1.2.13
make #编译
make install #安装
如果后面遇到某个功能没有,只要修改 configure
中的参数就行了,重复执行 make
make install
即可
配置启动Nginx
/usr/local/nginx/sbin/nginx #启动服务
/usr/local/nginx/sbin/nginx -s reload #重新加载服务
/usr/local/nginx/sbin/nginx -s stop #停止服务
ps -ef | grep nginx #查看服务进程
更改配置
开始设置开启启动项
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启用开机启动服务
最终的启动运行命令
PHP 8
安装基本编译环境
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel sqlite-devel gmp-devel oniguruma-devel readline-devel libxslt-devel
安装CMake
wget https://github.com/Kitware/CMake/releases/download/v3.25.2/cmake-3.25.2.tar.gz
tar -zxvf cmake-3.25.2.tar.gz
cd cmake-3.25.2
./bootstrap
gmake
ln -s /usr/local/src/cmake-3.25.2/bin/cmake /usr/bin/cmake
cmake --version
安装libzip 必须先安装CMake
下载 libzip
yum remove libzip
wget https://libzip.org/download/libzip-1.9.2.tar.gz
tar -zxvf libzip-1.9.2.tar.gz
cd libzip-1.9.2
mkdir build
cd build
cmake ..
make
make install
安装完成后,查看是否存在/usr/local/lib64/pkgconfig目录,如果存在,执行如下命令来设置PKG_CONFIG_PATH:
下载源码包
cd /usr/local/src
wget https://www.php.net/distributions/php-8.2.3.tar.gz # 下载
tar -zxvf php-8.2.3.tar.gz # 解压缩
编译安装
cd php-8.2.3
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-ftp --enable-gd --enable-gd-jis-conv --enable-mysqlnd --enable-pdo --enable-sockets --enable-fpm --enable-xml --enable-soap --enable-pcntl --enable-cli --enable-bcmath --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --with-zlib --with-iconv --with-curl --with-zip --with-gettext
make #编译
make install #安装
修改配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
find /usr/local/src/php-8.2.3 -name php.ini*
cp /usr/local/src/php-8.2.3/php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
将 ;cgi.fix_pathinfo=1
改为 cgi.fix_pathinfo=0
将 expose_php = On
改为 expose_php = Off
隐藏版本号
将 [global]
下的 pid = run/php-fpm.pid
启用, 后面 php-fpm.service
中的 PIDFile
必须设成一样的路径,否则会出现找不到php-fpm.pid
的情况
将
user = nobody group = nobody
改为
user = www group = www
需要先添加 www
用户和 www
组
初始命令
/usr/local/php/sbin/php-fpm -R # 这里后面带个 -R 表示用root 用户启动
/usr/bin/pkill -9 php-fpm
pstree -p | grep php
设置开机启动项
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/usr/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
可以使用systemctl命令管理php-fpm:
systemctl start php-fpm.service #启动
systemctl stop php-fpm.service #停止
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload
搭配Nginx运行PHP站点
配置 Nginx
在 http
下添加
client_max_body_size 200M; #配置客户端请求体最大值
client_body_buffer_size 50m; #配置请求体缓存区大小
server_tokens off; # 隐藏响应头中的版本号
gzip on;
gzip_min_length 1k; #不压缩临界值,大于1k的才压缩
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript text/css application/font-woff; # 需要压缩什么文件就加上文件类型,对于图片还是不要使用gzip压缩,直接在本地修改成其他图片格式效果更好
server {
server_name zodream.cn;
root /data/www/html; # 设置站点根目录
location / {
# root html;
index index.php index.html index.htm;
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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
## 配置 xxsqladmin 路径指向phpmyadmin
location ~ ^/xxsqladmin/.*\.php$ {
root /data/shop/phpmyadmin;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^/xxsqladmin(.+?\.php)(.*)$") {
set $real_script_name $1;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
include fastcgi_params;
}
## 配置 xxsqladmin 资源文件路径指向phpmyadmin
location ~ ^/xxsqladmin.* {
root /data/shop/phpmyadmin;
rewrite ^/xxsqladmin(.*)$ /$1 break;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
# 添加https支持
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/zodream.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/zodream.cn/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
修改完保存文件并重启Nginx服务器
MariaDB
安装
如果本地已安装 mayql 则会出现冲突 增加 参数即可 --allowerasing
启动和设置开机启动
设置修改密码
使用 Certbot 获取 letsencrypt 证书
如果出现 找不到 nginx
新增用户
赋予权限
PHP拓展安装
imagick
sudo yum -y install ImageMagick-devel
cd /usr/local/src
tar xvf imagick-3.7.0.tgz
cd imagick-3.7.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
php.ini
redis
安装 redis 主程序
cd /usr/local/src
wget https://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
make install
redis-server
现在,我们新建目录 /usr/local/redis ,把./redis.conf,src/redis-server,src/redis-cli 三个文件复制到该目录下
mkdir /usr/local/redis
cp redis.conf src/redis-server src/redis-cli /usr/local/redis/
cd /usr/local/redis
vi redis.conf
启动
安装 phpredis
cd /usr/local/src
tar xvf redis-5.3.7.tgz
cd redis-5.3.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
php.ini
安装多版本php 7
下载源码包
cd /usr/local/src
wget https://www.php.net/distributions/php-7.4.33.tar.gz # 下载
tar -zxvf php-7.4.33.tar.gz # 解压缩
编译安装
-–prefix
是安装目录,--with-config-file-path
是配置文件存放目录
cd php-7.4.33
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --enable-mbstring --enable-ftp --enable-gd --enable-gd-jis-conv --enable-mysqlnd --enable-pdo --enable-sockets --enable-fpm --enable-xml --enable-soap --enable-pcntl --enable-cli --enable-bcmath --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --with-zlib --with-iconv --with-curl --with-gettext
make #编译
make install #安装
修改配置文件
同原本的配置方法 [PHP8配置]()
注意将 /usr/local/php7/etc/php-fpm.d/www.conf
中的端口改成其他的,不要和原本的冲突
设置开机启动项
[Unit]
Description=php7-fpm
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm
ExecStop=/usr/bin/pkill -9 php7-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
可以使用systemctl命令管理php7-fpm:
配置站点
/usr/local/nginx/conf/nginx.conf
将 fastcgi_pass
配置成PHP7
监听的端口
server {
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
启动PHP7
,重启nginx
即可
转载请保留原文链接: https://zodream.cn/blog/id/233.html