centos7 编译php环境记录

2023-09-05 16:12:06 浏览数 (1)

CentOs7 php

安装编译工具

代码语言:javascript复制
yum -y install gcc gcc-c   autoconf automake make

安装依赖

代码语言:javascript复制
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel pcre-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel sqlite-devel libsqlite3-dev oniguruma-devel

下载安装包

代码语言:javascript复制
wget http://php.net/distributions/php-7.4.0.tar.gz
tar -zxvf php-7.4.0.tar.gz
cd php-7.4.0

创建用户组

代码语言:javascript复制
groupadd www
useradd -g www www

编译参数

根据自己需求更改--prefix--with-config-file-path

代码语言:javascript复制
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir --enable-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm --enable-mbstring
代码语言:javascript复制
make
make install

文件配置修改与路径

  • 路径
代码语言:javascript复制
/usr/local/php/etc
/usr/local/php/bin/php
/usr/local/php/sbin/php-fpm
  • 配置文件修改
代码语言:javascript复制
cp php.ini.develop php.ini
cp php-fpm.conf.default php-fpm.conf
cp www.conf.default www.conf

注意 php-fpm.conf 中的pid记得要打开配置好,比如我的pid = /usr/local/php/var/run/php-fpm.pid

查看状态

代码语言:javascript复制
ps aux | grep php-fpm

重启

代码语言:javascript复制
killall php-fpm
/usr/local/php/bin/php-fpm

安装其他扩展

在编译的过程中我发现加了--enable-mbstring参数会报错,于是决定先安装其他扩展,回过头再单独安装,但是总是编译报错,后来发现是没有make clean:

  1. make clean
  2. 进入源码的ext/mbstring/目录
  3. 执行/usr/local/php/bin/phpize生成configure
  4. ./configure --with-php-config=/usr/local/php/bin/php-config
  5. make && make install
  6. 在php.ini中添加extension=mbstring(extension_dir用默认的就行)

nginx

根据实际情况选择nginx版本下载源码

根据自己需求更改--prefix 以及其他参数

代码语言:javascript复制
wget http://nginx.org/download/nginx-1.17.9.tar.gz
tar zxvf nginx-1.17.9.tar.gz
./configure --prefix=/usr/local/nginx --user=nginx--group=nginx
make
make install

启动和停止

代码语言:javascript复制
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop
killall nginx

mysql8.0 (yum 安装)

  • 安装
代码语言:javascript复制
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum update
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum list mysql
yum -y install mysql-community-server
systemctl start mysqld
  • 获取初始密码并修改
代码语言:javascript复制
grep 'temporary password' /var/log/mysqld.log
msyql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your passowrd';
FLUSH PRIVILEGES;
  • 创建可远程用户(可选)
代码语言:javascript复制
create user 'litblc'@'%' identified by 'your pwd';
grant all privileges on fmock.* to 'litblc'@'%' with grant option;
  • 更改认证方式(可选)
代码语言:javascript复制
vi /etc/my.cnf
default_authentication_plugin=mysql_native_password

相关文章Centos7 mini 配置 php7 nginx mysql 最详细过程,为linux小白送福利

0 人点赞