wget http://am1.php.net/distributions/php-7.4.8.tar.gz
tar -zxvf php-7.4.8.tar.gz
yum install epel-release
yum install -y libxml2*
yum install -y openssl*
yum install -y libcurl*
yum install -y libjpeg*
yum install -y libpng*
yum install -y freetype*
yum install -y libmcrypt*
yum -y install gmp-devel
yum -y install readline-devel
yum install sqlite-devel
yum install oniguruma-devel
yum install gcc
yum install gcc-c++
yum install autoconf
yum install make
yum install libxml2-devel
yum install bzip2-devel.x86_64 -y
groupadd www
useradd -g www www
--prefix=/usr/usrsevice/php7.4 --with-config-file-path=/usr/usrsevice/php7.4/etc
以上两段代码后的路径为你要想要安装php的路径,如果没有,就得先创建路径
./configure --prefix=/usr/usrsevice/php7.4 --with-config-file-path=/usr/usrsevice/php7.4/etc --enable-inline-optimization --disable-debug --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-rpath --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-mbstring --with-onig --enable-shared --enable-opcache --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --with-iconv --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-zip --enable-wddx --with-pear
make ##编译
make test ##测试编译是否成功
make install ##安装
编辑/etc/profile文件,加入以下代码:
export PATH="/usr/usrsevice/php7.4/bin":$PATH #引号里的为php安装路径
刷新环境变量:
source /etc/profile
需要把/usr/usrsevice/php7.4/etc/php-fpm.d目录中的www.conf.default重命名为www.conf
需要在/usr/usrsevice/php7.4/etc 把默认的配置文件php-fpm.conf.default改成php-fpm.conf
php7编译安装好后会发现没有php.ini配置文件,需要在解压包的根目录中复制php.ini-production或php.ini-development并重命名为php.ini到php编译好的安装目录中的/usr/local/php/etc文件夹即可。
启动PHP,进入php安装目录下的sbin目录内,执行以下代码:
./php-fpm
可以使用以下命令查看php是否成功启动:
ps -ef |grep php
先将php关闭:
pkill php-fpm
进入/usr/lib/systemd/system目录下,新建php.servcie文件,文件内容如下:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm(你的php-fpm路径) --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf(你的php-fpm配置文件路径)
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
启动服务:
curl -s https://raw.githubusercontent.com/oscm/shell/master/os/user/www.sh | bash
systemctl start php
常用服务命令:
1.systemctl status php; ##查看php状态
2.systemctl start php; ##启动php服务
3.systemctl enable php; ##设置php为开机自启
4.systemctl disable php; ###关闭php开机自启
