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

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

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

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

PHP 依赖项安装

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

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

使用源码安装 PHP

下载并解压 PHP 源码

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

# 下载并解压
cd /usr/local/src
wget 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
make
make 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.conf
ln -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=1
opcache.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-fpm
chmod 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.pid
user = www
group = www
# 填写你的域名或IP地址
listen=127.0.0.1:9000

Nginx 配置

创建 www 用户和组

# 查看用户组
cat /etc/passwd | grep www
cat /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/html
rm -rf *
vim index.php

设置目录权限:

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

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

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

你可能感兴趣的文章
nodejs 开发websocket 笔记
查看>>
nodejs 的 Buffer 详解
查看>>
nodejs 读取xlsx文件内容
查看>>
nodejs 运行CMD命令
查看>>
Nodejs+Express+Mysql实现简单用户管理增删改查
查看>>
nodejs+nginx获取真实ip
查看>>
nodejs-mime类型
查看>>
NodeJs——(11)控制权转移next
查看>>
NodeJS、NPM安装配置步骤(windows版本)
查看>>
NodeJS、NPM安装配置步骤(windows版本)
查看>>
nodejs与javascript中的aes加密
查看>>
nodejs中Express 路由统一设置缓存的小技巧
查看>>
nodejs中express的使用
查看>>
Nodejs中的fs模块的使用
查看>>
NodeJS使用淘宝npm镜像站的各种姿势
查看>>
nodejs包管理工具对比:npm、Yarn、cnpm、npx
查看>>
NodeJs单元测试之 API性能测试
查看>>
nodejs图片转换字节保存
查看>>
nodejs在Liunx上的部署生产方式-PM2
查看>>
nodejs字符与字节之间的转换
查看>>