天天看點

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

記一次http啟動失敗

環境:centos7.4 

原裝環境:zabbix-server3.4(10051);zabbix-agent(10050);mariadb10.0(3306);httpd(Apache/2.4.6)(80,443)

新增環境:nginx-1.11.7(8081,8032,8033);php-fpm-5.3.28(9000)

[[email protected] conf.d]# mysql -V

mysql Ver 15.1 Distrib 10.0.32-MariaDB, for Linux (x86_64) using readline 5.1

[[email protected] conf.d]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59

[[email protected] conf.d]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.11.7

[[email protected] conf.d]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.11.7
[[email protected] conf.d]# /usr/local/php/sbin/php-fpm -v
PHP 5.3.28 (fpm-fcgi) (built: Sep 13 2018 17:36:18)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
           

早上新增環境後,8032,8033端口對應的web服務都能正常打開,但下午,想檢查一下zabbix-server界面,發現打不開。

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

期初,我以為是nginx和apache環境沖突,但其實兩者都可以共存。但此時,發現httpd服務端口已經停用,當試圖重新開機httpd服務時,報錯。

[[email protected] conf.d]# systemctl restart httpd.service

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
           

檢視報錯内容

[[email protected] conf.d]# systemctl status httpd.service -l

● httpd.service - The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

   Active: failed (Result: exit-code) since 六 2018-09-15 12:44:35 CST; 5min ago

     Docs: man:httpd(8)

           man:apachectl(8)

  Process: 20949 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)

  Process: 20947 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)

 Main PID: 20947 (code=exited, status=1/FAILURE)

9月 15 12:44:35 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...

9月 15 12:44:35 localhost.localdomain httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

9月 15 12:44:35 localhost.localdomain httpd[20947]: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

9月 15 12:44:35 localhost.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE

9月 15 12:44:35 localhost.localdomain kill[20949]: kill: cannot find process ""

9月 15 12:44:35 localhost.localdomain systemd[1]: httpd.service: control process exited, code=exited status=1

9月 15 12:44:35 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.

9月 15 12:44:35 localhost.localdomain systemd[1]: Unit httpd.service entered failed state.

9月 15 12:44:35 localhost.localdomain systemd[1]: httpd.service failed.
           

提示:/etc/httpd/conf.d/php.conf檔案31行有文法錯誤

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

好吧,檢查。貌似因為這個文法錯誤導緻之後的“php_value”子產品加載不出來。既然加載不出來,那麼就嘗試着注釋掉它。

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

重新開機服務成功檢查端口,端口存活

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

檢查zabbix界面

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

看來是失敗了。

在zabbix.conf中繼續注釋php_value所訓示的塊

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

重新開機服務,過濾端口,成功

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

檢查web界面

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

依舊錯誤

此時懷疑是php-fpm環境與原裝php環境沖突,畢竟zabbix3.0以上版本對php環境的最低要求是php5.4,而新裝的php-fpm版本是5.3,是以這是我最懷疑的。而通過php -v查詢預設的php版本

[[email protected] conf.d]# php -v

Zend Guard Loader requires Zend Engine API version 220090626.

The Zend Engine API version 220100525 which is installed, is newer.

Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Guard Loader.

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
           

預設版本也确實是php 5.4,是以這個原因排除。

仔細上網百度,發現國内各網站都沒有針對這個問題作出詳細解釋。而無意間發現一個針對這個問題的讨論:https://serverfault.com/questions/515417/error-start-apache-php-value

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

可以看到,問題幾乎一模一樣,可慚愧的是,人家5年前搞的東西,錯誤至今還在犯。

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

按照他所提示的,将mod_php添加至httpd.conf。首先将注釋掉的php_value還原

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:
http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

在httpd.conf最後添加“LoadModule php5_module ../modules/libphp5.so”

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

重新開機httpd,重新開機成功,端口都在

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

檢查web界面

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

錯誤。繼續往下走,四年後的回答。。

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

貌似同樣的配置是在不同的檔案中。他寫到由于錯誤的配置導緻php_value指令無效,即不可調用。

首先,找到/etc/httpd/conf.modules.d/10-php.conf檔案,檢查,正确

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

再找到/etc/httpd/conf.modules.d/00-mpm.conf檔案,檢查

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

很直覺,因為隻有prefork定義的mpm子產品才可以在linux上運作,而這個配置檔案裡指定的是mpm_worker,将其注釋,是上面的mpm_prefork生效

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

儲存退出,重新開機httpd服務,重新開機正常,端口正常

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

檢查web界面

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

正常。

問題得到解決,但意識到對php的配置檔案作用了解很不夠。要繼續努力啊

普及一下:MPM( ( Multi-Processing Module )多路處理子產品

檢查,正常的應該如下,mem機制支援:/usr/sbin/httpd(即prefork模式)

http啟動失敗:httpd[20947]: AH00526: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:

是以,當php配置檔案有文法錯誤時,也要想一想支援文法格式的子產品是否正确。

繼續閱讀