리눅스에 PHP를 설치하는 방법
이 기사에서는 주로 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

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

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

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

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

PHP는 동적 웹 개발 및 서버 측 응용 프로그램에 사용되는 서버 측 스크립팅 언어입니다. 1.PHP는 편집이 필요하지 않으며 빠른 발전에 적합한 해석 된 언어입니다. 2. PHP 코드는 HTML에 포함되어 웹 페이지를 쉽게 개발할 수 있습니다. 3. PHP는 서버 측 로직을 처리하고 HTML 출력을 생성하며 사용자 상호 작용 및 데이터 처리를 지원합니다. 4. PHP는 데이터베이스와 상호 작용하고 프로세스 양식 제출 및 서버 측 작업을 실행할 수 있습니다.

PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

대 코드 시스템 요구 사항 : 운영 체제 : Windows 10 이상, MacOS 10.12 이상, Linux 배포 프로세서 : 최소 1.6GHz, 권장 2.0GHz 이상의 메모리 : 최소 512MB, 권장 4GB 이상의 저장 공간 : 최소 250MB, 권장 1GB 및 기타 요구 사항 : 안정 네트워크 연결, Xorg/Wayland (LINUX)

PHP의 핵심 이점에는 학습 용이성, 강력한 웹 개발 지원, 풍부한 라이브러리 및 프레임 워크, 고성능 및 확장 성, 크로스 플랫폼 호환성 및 비용 효율성이 포함됩니다. 1) 배우고 사용하기 쉽고 초보자에게 적합합니다. 2) 웹 서버와 우수한 통합 및 여러 데이터베이스를 지원합니다. 3) Laravel과 같은 강력한 프레임 워크가 있습니다. 4) 최적화를 통해 고성능을 달성 할 수 있습니다. 5) 여러 운영 체제 지원; 6) 개발 비용을 줄이기위한 오픈 소스.

PHP는 웹 개발 및 컨텐츠 관리 시스템에 적합하며 Python은 데이터 과학, 기계 학습 및 자동화 스크립트에 적합합니다. 1.PHP는 빠르고 확장 가능한 웹 사이트 및 응용 프로그램을 구축하는 데 잘 작동하며 WordPress와 같은 CMS에서 일반적으로 사용됩니다. 2. Python은 Numpy 및 Tensorflow와 같은 풍부한 라이브러리를 통해 데이터 과학 및 기계 학습 분야에서 뛰어난 공연을했습니다.

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

phphassignificallyimpactedwebdevelopmentandextendsbeyondit
