博客
关于我
Linux 系统安装配置PHP服务(源码安装)
阅读量:790 次
发布时间: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/

你可能感兴趣的文章
linux sed 批量替换字符串
查看>>
linux sed命令详解
查看>>
linux sed命令详解
查看>>
linux shell wc 命令
查看>>
Linux Shell脚本处理JSON字符串
查看>>
Linux Shell脚本通过参数名传递参数
查看>>
Linux Shell语言并发执行多条命令
查看>>
Linux signal
查看>>
Linux SNMP支持IPv6配置实战
查看>>
Linux Socket学习--域和套接口简介
查看>>
linux sort 用法
查看>>
linux SSL发送邮件出错 ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:748)
查看>>
Linux sudo命令详解
查看>>
Linux tail 命令详解
查看>>
linux tar 备份命令
查看>>
Linux tcpdump -any抓的包转换成标准的pcap
查看>>
Linux Terminator
查看>>
linux tex文件编译,用latexmk编译XeLaTeX tex文件
查看>>
Linux top
查看>>
Linux top 命令详解
查看>>