이 기사에서는 주로 Linux에 PHP를 설치하는 방법을 공유합니다. 이 기사는 도움이 되길 바라며 사진과 텍스트 형식으로 공유됩니다.
1.php 공식 홈페이지에서 해당 버전을 다운로드하세요
PHP 다운로드 페이지에는 최신 버전만 있고, 이전 버전은 더 이상 다운로드 페이지에서 찾을 수 없기 때문에, 수동으로 다음 URL을 통해 다운로드하세요.
http://cn.php.net/distributions/php-5.3.9.tar.bz2. 이 페이지에는 일부 이전 버전이 나열됩니다. 여기에서 다운로드하세요.
2. php
tar 패키지를 추출하고 압축이 풀린 패키지 디렉터리로 들어가세요. ./configure --prefix=/opt/local 명령을 실행하세요. /php, " /opt/local/php"는 설치 경로이며, 원하는 설치 경로로 변경하시면 됩니다.
(1) 이때 일부 필수 플러그인이 누락되었다는 메시지가 표시될 수 있습니다. yum 명령을 사용하여 설치하세요. 예를 들어, 구성 오류 xml2-config를 찾을 수 없습니다. . libxml2 설치를 확인하세요. 이때 실행 명령: yum -y install libxml2 libxml2-devel, 해당 플러그인 설치 등
모든 플러그인이 설치된 후 다시 실행하세요
<span style="font-size: 14px;">./configure --prefix=/opt/local/php<br/></span>
(2) 여기에 php-fpm 기능을 설치하려면 다음과 같은 추가 플러그인을 설치하려면 yum이 필요합니다. -mcrypt
libmcrypt libmcrypt-devel에서 패키지를 찾을 수 없다는 메시지가 나타날 수 있습니다. 이 경우 문제를 해결하려면 소스를 업데이트해야 합니다.
<span style="font-size: 14px;">yum -y install openssl openssl-devel bzip2 bzip2-devel curl curl-devel readline-devel fcgi php-mcrypt libmcrypt libmcrypt-devel<br/></span>
그 중 업데이트가 성공하기 전에 두 번 실행된 후 구성이 실행됩니다.
./configure --prefix=/opt/local/php5.3.29 --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear
通过后执行make
此时可能会出现以下提示
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
此处可暂进忽略,等之后再行安装,再次在php目录执行make all install
如果安装了php-fpm,则还需要执行以下命令,将php/etc目录下的配置文件拷贝一份
cp etc/php-fpm.conf.default etc/php-fpm.conf
将php/lib/php.ini拷贝到/etc/下
3.初装phar
这时可以执行
<span style="font-size: 14px;">wget http://pear.php.net/go-pear.phar<br/></span>
之后再执行
/opt/local/php/bin/php /opt/local/go-pear.phar
在出现的提示后,选1,选择phar安装目录,然后一路回车进行安装即可
最后制作php软链,让php全局可用
<span style="font-size: 14px;">ln -s /opt/local/php/bin/php /usr/bin/php<br/></span>
4.验证
执行php -v和sbin/php-fpm -v查看php版本以验证php是否已安装
5.启动php-fpm
php/sbin/php-fpm
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
示例:
php-fpm 关闭:
kill -INT `cat /opt/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /opt/local/php/var/run/php-fpm.pid`
如果找不到php-fpm.pid文件,可通过查找php-fpm进程号进行重启和关闭
例如
<span style="font-size: 14px;">[root@SH-DEV local]# ps -aux|grep php-fpm<br/>root 141735 0.0 0.0 201840 3892 ? <br/> Ss 16:27 0:00 php-fpm: master process (/opt/local/php5.3.29/etc/php-fpm.conf)<br/><br/>kill -USR2 141735<br/></span>
6.修改php-fpm配置
(1)如果在nginx.conf中使用了fastcgi_pass unix:/tmp/php-cgi.sock,则需要修改php-fpm.conf,找到如下码段:
<span style="font-size: 14px;">; The address on which to accept FastCGI requests.<br/>; Valid syntaxes are:<br/>; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on<br/>; a specific port;<br/>; 'port' - to listen on a TCP socket to all addresses on a<br/>; specific port;<br/>; '/path/to/unix/socket' - to listen on a unix socket.<br/>; Note: This value is mandatory.<br/>;listen = 127.0.0.1:9000<br/>listen = /tmp/php-cgi.sock<br/><br/>; Set listen(2) backlog. A value of '-1' means unlimited.<br/>; Default Value: 128 (-1 on FreeBSD and OpenBSD)<br/>;listen.backlog = -1<br/><br/>; Set permissions for unix socket, if one is used. In Linux, read/write<br/>; permissions must be set in order to allow connections from a web server. Many<br/>; BSD-derived systems allow connections regardless of permissions.<br/>; Default Values: user and group are set as the running user<br/>; mode is set to 0660<br/>listen.owner = nobody<br/>listen.group = nobody<br/>listen.mode = 0660<br/></span>
将原listen和listen.owner,listen.group段做如上修改,其中listen.owner,listen.group为nginx启动用户名,如此处不修改,会提示
nginx error connect to php-fpm.sock failed (13: Permission denied)
当然此处如果将sock放在内存中/dev/shm/php-fpm.sock会更快
(2)修改php-fpm线程数
<span style="font-size: 14px;">; Per pool prefix<br/>; It only applies on the following directives:<br/>; - 'slowlog'<br/>; - 'listen' (unixsocket)<br/>; - 'chroot'<br/>; - 'chdir'<br/>; - 'php_values'<br/>; - 'php_admin_values'<br/>; dynamic - the number of child processes are set dynamically based on the<br/>; following directives. With this process management, there will be<br/>; always at least 1 children.<br/>; pm.max_children - the maximum number of children that can<br/>; be alive at the same time.<br/>; pm.start_servers - the number of children created on startup.<br/>; pm.min_spare_servers - the minimum number of children in 'idle'<br/>; state (waiting to process). If the number<br/>; of 'idle' processes is less than this<br/>; number then some children will be created.<br/>; pm.max_spare_servers - the maximum number of children in 'idle'<br/>; state (waiting to process). If the number<br/>; of 'idle' processes is greater than this<br/>; number then some children will be killed.<br/>; ondemand - no children are created at startup. Children will be forked when<br/>; new requests will connect. The following parameter are used:<br/>; pm.max_children - the maximum number of children that<br/>; can be alive at the same time.<br/>; pm.process_idle_timeout - The number of seconds after which<br/>; an idle process will be killed.<br/>; Note: This value is mandatory.<br/>pm = dynamic<br/>#如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下面的参数决定<br/><br/>; The number of child processes to be created when pm is set to 'static' and the<br/>; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.<br/>; This value sets the limit on the number of simultaneous requests that will be<br/>; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.<br/>; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP<br/>; CGI. The below defaults are based on a server without much resources. Don't<br/>; forget to tweak pm.* to fit your needs.<br/>; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'<br/>; Note: This value is mandatory.<br/>pm.max_children = 8<br/>#子进程最大数<br/><br/>; The number of child processes created on startup.<br/>; Note: Used only when pm is set to 'dynamic'<br/>; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2<br/>pm.start_servers = 8<br/>#启动时的进程数<br/><br/><br/>; The desired minimum number of idle server processes.<br/>; Note: Used only when pm is set to 'dynamic'<br/>; Note: Mandatory when pm is set to 'dynamic'<br/>pm.min_spare_servers = 1<br/>#保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程<br/><br/>; The desired maximum number of idle server processes.<br/>; Note: Used only when pm is set to 'dynamic'<br/>; Note: Mandatory when pm is set to 'dynamic'<br/>pm.max_spare_servers = 8<br/>#保证空闲进程数最大值,如果空闲进程大于此值,此进行清理<br/></span>
相关推荐:
위 내용은 리눅스에 PHP를 설치하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

데이터베이스 스토리지 세션 사용의 주요 장점에는 지속성, 확장 성 및 보안이 포함됩니다. 1. 지속성 : 서버가 다시 시작 되더라도 세션 데이터는 변경되지 않아도됩니다. 2. 확장 성 : 분산 시스템에 적용하여 세션 데이터가 여러 서버간에 동기화되도록합니다. 3. 보안 : 데이터베이스는 민감한 정보를 보호하기 위해 암호화 된 스토리지를 제공합니다.

SessionHandlerInterface 인터페이스를 구현하여 PHP에서 사용자 정의 세션 처리 구현을 수행 할 수 있습니다. 특정 단계에는 다음이 포함됩니다. 1) CustomsessionHandler와 같은 SessionHandlerInterface를 구현하는 클래스 만들기; 2) 인터페이스의 방법 (예 : Open, Close, Read, Write, Despare, GC)의 수명주기 및 세션 데이터의 저장 방법을 정의하기 위해 방법을 다시 작성합니다. 3) PHP 스크립트에 사용자 정의 세션 프로세서를 등록하고 세션을 시작하십시오. 이를 통해 MySQL 및 Redis와 같은 미디어에 데이터를 저장하여 성능, 보안 및 확장 성을 향상시킬 수 있습니다.

SessionId는 웹 애플리케이션에 사용되는 메커니즘으로 사용자 세션 상태를 추적합니다. 1. 사용자와 서버 간의 여러 상호 작용 중에 사용자의 신원 정보를 유지하는 데 사용되는 무작위로 생성 된 문자열입니다. 2. 서버는 쿠키 또는 URL 매개 변수를 통해 클라이언트로 생성하여 보낸다. 3. 생성은 일반적으로 임의의 알고리즘을 사용하여 독창성과 예측 불가능 성을 보장합니다. 4. 실제 개발에서 Redis와 같은 메모리 내 데이터베이스를 사용하여 세션 데이터를 저장하여 성능 및 보안을 향상시킬 수 있습니다.

JWT 또는 쿠키를 사용하여 API와 같은 무국적 환경에서 세션을 관리 할 수 있습니다. 1. JWT는 무국적자 및 확장 성에 적합하지만 빅 데이터와 관련하여 크기가 크다. 2. 쿠키는보다 전통적이고 구현하기 쉽지만 보안을 보장하기 위해주의해서 구성해야합니다.

세션 관련 XSS 공격으로부터 응용 프로그램을 보호하려면 다음 조치가 필요합니다. 1. 세션 쿠키를 보호하기 위해 Httponly 및 Secure 플래그를 설정하십시오. 2. 모든 사용자 입력에 대한 내보내기 코드. 3. 스크립트 소스를 제한하기 위해 컨텐츠 보안 정책 (CSP)을 구현하십시오. 이러한 정책을 통해 세션 관련 XSS 공격을 효과적으로 보호 할 수 있으며 사용자 데이터가 보장 될 수 있습니다.

PHP 세션 성능을 최적화하는 방법 : 1. 지연 세션 시작, 2. 데이터베이스를 사용하여 세션을 저장, 3. 세션 데이터 압축, 4. 세션 수명주기 관리 및 5. 세션 공유 구현. 이러한 전략은 높은 동시성 환경에서 응용의 효율성을 크게 향상시킬 수 있습니다.

THESESSION.GC_MAXLIFETIMESETTINGINSTTINGTINGSTINGTERMINESTERMINESTERSTINGSESSIONDATA, SETINSECONDS.1) IT'SCONFIGUDEDINPHP.INIORVIAINI_SET ()

PHP에서는 Session_Name () 함수를 사용하여 세션 이름을 구성 할 수 있습니다. 특정 단계는 다음과 같습니다. 1. Session_Name () 함수를 사용하여 Session_Name ( "my_session")과 같은 세션 이름을 설정하십시오. 2. 세션 이름을 설정 한 후 세션을 시작하여 세션을 시작하십시오. 세션 이름을 구성하면 여러 응용 프로그램 간의 세션 데이터 충돌을 피하고 보안을 향상시킬 수 있지만 세션 이름의 독창성, 보안, 길이 및 설정 타이밍에주의를 기울일 수 있습니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
