centos安装php8,nginx,mysql
安装php8
1、下载PHP,解压到目录
2、安装依赖
yum install -y --setopt=protected_multilib=false gcGc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel sqlite-devel oniguruma oniguruma-devel libzip libzip-devel openssl-devel sqlite-devel
#以上依赖已安装,略过本步骤,3、安装gcc:yum install -y gcc
4、生成编译文件
./configure --prefix=/home/php/php8 --with-config-file-path=/home/php/php8/etc --with-mysqli=shared,mysqlnd --with-pdo-mysql --enable-opcache --enable-gd --with-iconv --with-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg --with-freetype --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-fast-install --disable-fileinfo
5、如果有错:1、No package ‘oniguruma’ found
yum install -y epel-release
yum install -y oniguruma oniguruma-devel
2 .Requested ‘libzip >= 0.11’ but version of libzip is 0.10.1 libzip 版本太低
yum remove libzip libzip-devel
wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
6、编译安装:make && make install
7、配置
添加www用户并禁止登录
# useradd www -M -s /sbin/nologin
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
8、打开 php.ini:
# vim /usr/local/php/php.ini
定位到 cgi.fix_pathinfo= 并将其修改为如下所示:
cgi.fix_pathinfo=0
9、配置,启动服务
修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。
# vim /usr/local/etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www-data
group = www-data
复制 php-fpm 的启动脚本(在php安装文件中)
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
增加执行权限
# chmod 744 /etc/rc.d/init.d/php-fpm
启动 php-fpm
/etc/init.d/php-fpm start 或者 service php-fpm start
开启服务
# chkconfig --add php-fpm
# chkconfig php-fpm on
启动 php-fpm 服务,如果启动失败尝试重启
/usr/local/bin/php-fpm
*************************************************************************
安装NGINX
1、安装环境
如果还没装GCC,检查GCC版本# gcc --version
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2、配置nginx
curl -O http://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
cd /usr/local/nginx-1.22.1
./configure
3、安装
make && make install
4、查看安装路径
whereis nginx
5、设置开机自启
vi /lib/systemd/system/nginx.service
增加
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
重载配置
systemctl daemon-reload
设置开机启动
systemctl enable nginx.service
查询进程
ps -ef|grep nginx
6、直接使用输入nginx查看状态
方法1:
vim /etc/profile
export PATH=$PATH: /usr/local/nginx/sbin //nginx的位置
source /etc/profile
方法2
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin
7设置站点后,403错误
查看目录权限
查看/usr/sbin/sestatus -v 状态
如果是enabled
setenforce 0 临时挂你
或者修改/etc/selinux/config 文件,将SELINUX=enforcing改为SELINUX=disabled,重启机器
*********************************************************************************************
安装PHP7.4
************
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum update
yum install -y php php-cli php-fpm php-common
yum install -y php-mysqlnd
php -v
***************************************************
配置nginx支持php
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ =404;
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
root /home/www/web3/public ;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000 #systemctl start php-fpm
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
***************************************************
安装REDIS
***********************
方法1:
yum install redis
***********************
安装PHP的redis扩展
1、下载扩展包:http://pecl.php.net/package/redis
2、加压,并进入目录,cdredis-5.3.7
3、查找phpize构建安装环境,find /-name phpize
4、执行/etc/php/bin/phpize(根据自己的PHP安装目录)
如果提示:Can't find PHP headers in /usr/include/php
安装对应版本的php-devel
5、执行成功之后,可以看见当前 igbinary 目录下会多了一些配置文件,说明环境构建成功。
6、初始化配置
查看路径: whereis php-config 结果是:php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
--php-config目录也是php的安装目录。
./configure --with-php-config=/usr/bin/php-config
或者
./configure --with-php-config=/usr/bin/php-config --enable-redis-igbinary=yes --enable-redis-lzf=yes --enable-redis-zstd=yes
7、编译安装
make -j && make install
修改php.ini,增加
extension=redis.so
验证是否安装成功
通过命令 php -m
***************************************************
安装MYSQl
***********************
新建MYSQL目录,进入目录,执行安装
yum install https://repo.mysql.com//mysql84-community-release-el7-1.noarch.rpm
安装MYSQL服务
yum install -y mysql-community-server
启动MYSQL服务
systemctl start mysqld
查看默认密码
cat /var/log/mysqld.log
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
设置开机启动
systemctl enable mysqld