博客
关于我
Linux 系统安装配置PHP服务(源码安装)
阅读量:801 次
发布时间:2023-02-01

本文共 3540 字,大约阅读时间需要 11 分钟。

Linux 系统安装配置PHP服务(源码安装)

PHP 是一款广泛应用于 Web 开发领域的开源脚本语言,语法灵活,学习成本低,是现代 Web 开发的核心技术之一。

PHP 依赖项安装

在安装 PHP 之前,首先需要安装一些必要的系统依赖包:

# 安装 gcc 及相关开发包yum -y install gcc gcc-c++ make

使用源码安装 PHP

下载并解压 PHP 源码

将 PHP 源码下载到标准目录并解压:

# 下载并解压cd /usr/local/srcwget https://ftp.php.net/apache/phips/php最新版本tar -xzf php-消费者版本

安装 PHP

/usr/local/src/php-消费者版本 目录下执行以下命令:

./configure \  --prefix=/usr/local/php \  --with-config-file-path=/usr/local/php/etc \  --with-pdo-mysql=/usr/local/mysql/bin/mysql_config \  --with-mysqli=/usr/local/mysql/bin/mysql_config \  --with-mysql-sock=/tmp/mysql.sock \  --with-pdo-mysql=/usr/local/mysql \  --with-gd \  --with-png-dir=/usr/local/libpng \  --with-jpeg-dir=/usr/local/jpeg \  --with-freetype-dir=/usr/local/freetype \  --with-xpm-dir=/usr/local/xpm \  --with-zlib-dir=/usr/local/zlib \  --with-iconv \  --enable-libxml \  --enable-xml \  --enable-bcmath \  --enable-shmop \  --enable-sysvsem \  --enable-inline-optimization \  --enable-opcache \  --enable-mbstring \  --enable-ftp \  --enable-gd-native-ttf \  --with-openssl \  --enable-pcntl \  --enable-sockets \  --with-xmlrpc \  --enable-zip \  --enable-soap \  --without-pear \  --with-gettext \  --enable-session \  --with-mcrypt \  --with-curl \  --enable-ctype
makemake install

配置 PHP

复制配置文件并设置符号链接

将 PHP 的配置文件和模板文件复制到安装目录,并创建符号链接:

# 复制 php.ini 文件cp php.ini-production /usr/local/php/etc/php.ini# 删除系统默认配置rm -rf /etc/php.ini# 创建符号链接ln -s /usr/local/php/etc/php.ini /etc/php.ini# 复制 php-fpm 配置文件并设置符号链接cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

修改 PHP 配置

编辑 PHP 配置文件 /usr/local/php/etc/php.ini,进行以下修改:

# 禁用危险函数disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
date.timezone = PRC
expose_php = Off
short_open_tag = On
opcache.enable=1opcache.enable_cli=0

在配置末尾添加:

zend_extension=opcache.so

启用 PHP-FPM 开机启动

复制 init script 并赋予执行权限:

cp /usr/local/src/php-消费者版本/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpm

设置开机启动:

chkconfig --levelpad 20 php-fpm:0:off 1:off 2:on 3:on 4:on 5:on 6:off

编辑 PHP 配置文件 /usr/local/php/etc/php-fpm.conf,确保以下内容存在:

pid = run/php-fpm.piduser = wwwgroup = www# 填写你的域名或IP地址listen=127.0.0.1:9000

Nginx 配置

创建 www 用户和组

# 查看用户组cat /etc/passwd | grep wwwcat /etc/group | grep www

修改 Nginx 配置文件

vim /usr/local/nginx/conf/nginx.conf

添加以下内容:

user www www;location / {    root html;    index index.html index.php;}location ~ .php$ {    root html;    fastcgi_pass 127.0.0.1:9000;    fastcgi_index index.php;    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    include fastcgi_params;}

启动服务

/etc/init.d/nginx start/etc/init.d/php-fpm start

测试 PHP 配置

进入默认网站根目录创建测试文件:

cd /usr/local/nginx/htmlrm -rf *vim index.php

设置目录权限:

chown -R www.www /usr/local/nginx/htmlchmod -R 755 /usr/local/nginx/html

访问服务器 IP 地址即可查看测试页面。

转载地址:http://vhwfk.baihongyu.com/

你可能感兴趣的文章
NervanaGPU 项目使用教程
查看>>
Nerves 项目教程
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
查看>>
nestesd exception is java .lang.NoSuchMethodError:com.goolge.common.collect
查看>>
nestJS学习
查看>>
net core 环境部署的坑
查看>>
NET Framework安装失败的麻烦
查看>>
Net 应用程序如何在32位操作系统下申请超过2G的内存
查看>>
Net.Framework概述
查看>>
NET3.0+中使软件发出声音[整理篇]<转>
查看>>
net::err_aborted 错误码 404
查看>>
NetApp凭借领先的混合云数据与服务把握数字化转型机遇
查看>>
NetAssist网络调试工具使用指南 (附NetAssist工具包)
查看>>
Netbeans 8.1启动参数配置
查看>>
NetBeans IDE8.0需要JDK1.7及以上版本
查看>>
NetBeans之JSP开发环境的搭建...
查看>>
NetBeans之改变难看的JSP脚本标签的背景色...
查看>>