Ubuntu 16.04 업그레이드 후 텍스트로 렌더링 된 PHP


20

Apache는 Ubuntu 16.04 업그레이드 후 PHP 파일을 텍스트로 렌더링합니다.

Apache가 설치되어 실행 중입니다. PHP7이 실행 중입니다. 다음 명령을 실행하면 올바른 출력을 얻습니다.

php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'

그러나 http : //localhost/info.php 또는 다른 PHP 파일에 액세스 하면 페이지 대신 파일 내용이 표시됩니다.

온라인 도움말의 대부분은 이전 버전의 Ubuntu와 PHP에 대한 것이므로, 이들이 신뢰할 수 있는지 확실하지 않습니다.

업데이트 : libapache2-mod-php7.0을 설치하고 php7.0을 활성화 한 후 Apache가 시작되지 않습니다. 출력 참조 :

douglas@douglas-acer:~$ sudo service apache2 restart
douglas@douglas-acer:~$ sudo apt-get install libapache2-mod-php
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libapache2-mod-php
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/2.960 B of archives.
After this operation, 15,4 kB of additional disk space will be used.
Selecting previously unselected package libapache2-mod-php.
(Reading database ... 263897 files and directories currently installed.)
Preparing to unpack .../libapache2-mod-php_1%3a7.0+35ubuntu6_all.deb ...
Unpacking libapache2-mod-php (1:7.0+35ubuntu6) ...
Setting up libapache2-mod-php (1:7.0+35ubuntu6) ...
douglas@douglas-acer:~$ sudo service apache2 restart
douglas@douglas-acer:~$ sudo a2enmod php7.0
Considering conflict php5 for php7.0:
Enabling module php7.0.
To activate the new configuration, you need to run:
  service apache2 restart
douglas@douglas-acer:~$ sudo service apache2 restart
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
douglas@douglas-acer:~$ sudo apt-get purge php5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'php5' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

의 출력 systemctl status apache2.service:

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Dom 2016-04-24 08:21:35 BRT; 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9216 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

Abr 24 08:21:35 douglas-acer apache2[9216]:  * The apache2 configtest failed.
Abr 24 08:21:35 douglas-acer apache2[9216]: Output of config test was:
Abr 24 08:21:35 douglas-acer apache2[9216]: [Sun Apr 24 08:21:35.235583 2016] [:crit] [pid 9226:tid 140666367190912] Apache is running a threade
Abr 24 08:21:35 douglas-acer apache2[9216]: AH00013: Pre-configuration failed
Abr 24 08:21:35 douglas-acer apache2[9216]: Action 'configtest' failed.
Abr 24 08:21:35 douglas-acer apache2[9216]: The Apache error log may have more information.
Abr 24 08:21:35 douglas-acer systemd[1]: apache2.service: Control process exited, code=exited status=1
Abr 24 08:21:35 douglas-acer systemd[1]: Failed to start LSB: Apache2 web server.
Abr 24 08:21:35 douglas-acer systemd[1]: apache2.service: Unit entered failed state.
Abr 24 08:21:35 douglas-acer systemd[1]: apache2.service: Failed with result 'exit-code'.

의 출력 journalctl -xe

-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has finished shutting down.
Abr 24 08:37:59 douglas-acer systemd[1]: Starting LSB: Apache2 web server...
-- Subject: Unit apache2.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has begun starting up.
Abr 24 08:37:59 douglas-acer apache2[10261]:  * Starting Apache httpd web server apache2
Abr 24 08:37:59 douglas-acer apache2[10261]:  *
Abr 24 08:37:59 douglas-acer apache2[10261]:  * The apache2 configtest failed.
Abr 24 08:37:59 douglas-acer apache2[10261]: Output of config test was:
Abr 24 08:37:59 douglas-acer apache2[10261]: [Sun Apr 24 08:37:59.748900 2016] [:crit] [pid 10271:tid 139911432607616] Apache is running a threa
Abr 24 08:37:59 douglas-acer apache2[10261]: AH00013: Pre-configuration failed
Abr 24 08:37:59 douglas-acer apache2[10261]: Action 'configtest' failed.
Abr 24 08:37:59 douglas-acer apache2[10261]: The Apache error log may have more information.
Abr 24 08:37:59 douglas-acer systemd[1]: apache2.service: Control process exited, code=exited status=1
Abr 24 08:37:59 douglas-acer systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit apache2.service has failed.
-- 
-- The result is failed.
Abr 24 08:37:59 douglas-acer systemd[1]: apache2.service: Unit entered failed state.
Abr 24 08:37:59 douglas-acer systemd[1]: apache2.service: Failed with result 'exit-code'.
Abr 24 08:37:59 douglas-acer sudo[10258]: pam_unix(sudo:session): session closed for user root
Abr 24 08:38:02 douglas-acer sudo[10276]:  douglas : TTY=pts/18 ; PWD=/home/douglas ; USER=root ; COMMAND=/bin/journalctl -xe
Abr 24 08:38:02 douglas-acer sudo[10276]: pam_unix(sudo:session): session opened for user root by (uid=0)
Abr 24 08:38:38 douglas-acer sudo[10276]: pam_unix(sudo:session): session closed for user root
Abr 24 08:39:01 douglas-acer CRON[10297]: pam_unix(cron:session): session opened for user root by (uid=0)
Abr 24 08:39:01 douglas-acer CRON[10299]: (root) CMD (  [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean)
Abr 24 08:39:01 douglas-acer CRON[10297]: pam_unix(cron:session): session closed for user root
Abr 24 08:39:01 douglas-acer CRON[10298]: pam_unix(cron:session): session opened for user root by (uid=0)
Abr 24 08:39:01 douglas-acer CRON[10300]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
Abr 24 08:39:02 douglas-acer CRON[10298]: pam_unix(cron:session): session closed for user root
Abr 24 08:39:51 douglas-acer sudo[10122]: pam_unix(sudo:session): session closed for user root
Abr 24 08:39:53 douglas-acer sudo[10368]:  douglas : TTY=pts/5 ; PWD=/home/douglas ; USER=root ; COMMAND=/bin/journalctl -xe
Abr 24 08:39:53 douglas-acer sudo[10368]: pam_unix(sudo:session): session opened for user root by (uid=0) 

오류와 관련하여 https://wiki.archlinux.org/index.php/Apache_HTTP_Server 에서이 문제와 관련하여 Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP도움 이되었지만 파일 경로가 우분투의 경로와 일치하지 않으므로 적용하려고하지 않았습니다. 권장 수정.

답변:


27

php명령은 php7.0-cliUbuntu 16.04의 패키지에서 제공됩니다 . CLI 실행은 웹 서버 구성과 직교합니다.

웹 SAPI 중 하나 인 apache2, fpm 또는 cgi를 설치하고 구성해야합니다. 가장 쉬운 방법은 apache2 SAPI를 설치하는 것입니다.

  1. apache2 SAPI를 설치하려면 다음을 실행하십시오 apt-get install libapache2-mod-php(현재 기본 PHP 버전을 가져옵니다 libapache2-mod-php7.0). 패키지는 자체적으로 활성화되고 지원되는 유일한 MPM 인 apache2 prefork MPM으로 전환해야합니다. 그렇지 않은 경우 실행 a2enmod php7.0하고 오류를 찾으십시오. 설치가 자동으로 prefork의의 MPM에 이벤트 MPM 전환해야하지만 그렇지 않은 경우, 당신은 수행하여 수동으로 전환 할 수 있습니다 sudo a2dismod mpm_event다음에 sudo a2enmod mpm_prefork.

  2. FPM SAPI를 설치하려면을 실행 apt-get install php-fpm하고 FPM을 활성화하십시오 a2enconf php7.0-fpm. FPM SAPI는 더 안전하지만 올바르게 구성하기가 어렵습니다.

  3. CGI SAPI를 설치하려면을 실행 apt-get install php-cgi한 다음 CGI를 활성화하십시오 a2enconf php7.0-cgi. CGI가 PHP를 실행하는 방법으로 권장되지는 않지만 특별한 배포에는 유용 ​​할 수 있습니다.


자세한 내용을 제공하기 위해 질문을 편집했습니다.
machadoug

@machadoug는 MPM을 전환하는 방법을 설명하기 위해 답변을 편집했습니다
oerdnj

그것을 고치는 방법에 대한 아이디어가 있습니까?
machadoug

1
@machadoug 예, 추가했습니다. "설치가 이벤트 MPM에서 프리 포크 MPM으로 자동 전환되어야하지만, 그렇지 않은 경우 sudo a2dismod mpm_event 다음에 sudo a2enmod mpm_prefork를 수행하여 수동으로 전환 할 수 있습니다."
oerdnj

1
옵션 2에서 누락 된 단계가 있습니까? apache2와 php-fpm을 설치하고 a2enconf 명령을 실행합니다. 모두 성공했고 두 서비스가 모두 실행 중이지만 PHP 파일이 PHP를 처리하지 않고 직접 출력됩니다. Apache 또는 PHP-FPM의 로그에 오류가 없습니다.
앤드류 Ensley

1

libapache2-mod-php7.0을 설치하여 다시 실행했습니다. 도움이 되었기를 바랍니다.


0

또한이 문제로 다른 방법으로 물었습니다.

기본적으로 PHP 스크립트는 사용자 디렉토리에서 실행되지 않습니다. 따라서 서버가 사용자의 홈 폴더에서 public_html을 지원하고 사용자가 PHP를 실행하게하려면 해당 부분을 제거해야 php7.0.conf합니다.


0

최신 Apache 2.0에서 Ubuntu 16.04.2의 경우 Apache가 스레드를 사용하도록 사전 구성되어 있지만 기본 PHP 7은 그렇지 않습니다. PHP가 스레드 세이프로 컴파일되지 않은 경우 스레드를 사용하지 않는 프리 포크 MPM으로 전환해야합니다.

이렇게하려면 먼저 비활성화하십시오.

sudo a2dismod mpm_event 

그런 다음 다음을 활성화하십시오.

sudo a2enmod mpm_prefork 

상호 배타적이므로 올바른 순서로이 작업을 수행해야합니다.

그런 다음 Apache를 다시 시작하십시오.

sudo service apache2 restart

당신은 지금 문제없이 갈 수 있어야합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.