5

I just switched over to Ubuntu from Windows and am trying to get php 7 and Apache working.

I'm running php 7 and apache 2.4.18

PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Server version: Apache/2.4.18 (Ubuntu)

Apache localhost displays the "It works!" page, yet any other page with php shows plain text.

After trying to restart the service (sudo service apache2 restart) I get the following.

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

"systemctl status apache2.service" returns,

May 31 11:11:12 mike-N53Jq apache2[4926]:  * The apache2 configtest failed.
May 31 11:11:12 mike-N53Jq apache2[4926]: Output of config test was:
May 31 11:11:12 mike-N53Jq apache2[4926]: [Tue May 31 11:11:12.775675 2016] [:crit] [pid 4936:tid 140137086609280] Apache is running a threa
May 31 11:11:12 mike-N53Jq apache2[4926]: AH00013: Pre-configuration failed
May 31 11:11:12 mike-N53Jq apache2[4926]: Action 'configtest' failed.
May 31 11:11:12 mike-N53Jq apache2[4926]: The Apache error log may have more information.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Control process exited, code=exited status=1
May 31 11:11:12 mike-N53Jq systemd[1]: Failed to start LSB: Apache2 web server.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Unit entered failed state.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Failed with result 'exit-code'.

And journalctl -xe returns,

May 31 11:11:12 mike-N53Jq apache2[4926]: Output of config test was:
May 31 11:11:12 mike-N53Jq apache2[4926]: [Tue May 31 11:11:12.775675 2016] [:crit] [pid 4936:tid 140137086609280] Apache is running a threa
May 31 11:11:12 mike-N53Jq apache2[4926]: AH00013: Pre-configuration failed
May 31 11:11:12 mike-N53Jq apache2[4926]: Action 'configtest' failed.
May 31 11:11:12 mike-N53Jq apache2[4926]: The Apache error log may have more information.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Control process exited, code=exited status=1
May 31 11:11:12 mike-N53Jq 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.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Unit entered failed state.
May 31 11:11:12 mike-N53Jq systemd[1]: apache2.service: Failed with result 'exit-code'.
May 31 11:11:12 mike-N53Jq sudo[4920]: pam_unix(sudo:session): session closed for user root
May 31 11:11:18 mike-N53Jq pkexec[4951]: pam_unix(polkit-1:session): session opened for user root by (uid=1000)
May 31 11:11:18 mike-N53Jq pkexec[4951]: pam_systemd(polkit-1:session): Cannot create session: Already running in a session
May 31 11:11:18 mike-N53Jq pkexec[4951]: mike: Executing command [USER=root] [TTY=unknown] [CWD=/home/mike] [COMMAND=/usr/lib/update-notifie
May 31 11:17:01 mike-N53Jq CRON[5011]: pam_unix(cron:session): session opened for user root by (uid=0)
May 31 11:17:01 mike-N53Jq CRON[5012]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May 31 11:17:01 mike-N53Jq CRON[5011]: pam_unix(cron:session): session closed for user root

Does anyone have any suggestions on where to go from here? This is all pretty new to me.

Thanks.

Aptorian
  • 51
  • 1
  • 1
  • 2
  • 1
    Get the output from 'tail /var/log/apache/error.log' and see if you see anything pertaining to loading a configuration file. –  May 31 '16 at 18:27
  • Hmmm, I've been troubleshooting this for a few hours and one of the suggestions I found recommended deleting the entries in the error.log. When I do the above command, the file is empty and there is no result. – Aptorian May 31 '16 at 18:31
  • I could be wrong on the path, it might be apache2/error.log In any case, browse to /var/log/ and look for apache, or httpd, enter that directory and then look for an error log. Deleting any lines from error.log won't do anything, that file is only written to, and not read from. In fact, you can delete the entire log and apache will simply recreate it. –  May 31 '16 at 18:39
  • I used 'tail /var/log/apache2/error.log' and still receive nothing. This is after running 'sudo service apache2 restart' again. Should this be populating my error log? – Aptorian May 31 '16 at 18:46
  • Do 'sudo apache2ctl -t' and paste the output –  May 31 '16 at 18:52
  • [Tue May 31 11:54:53.768114 2016] [:crit] [pid 6025:tid 139812484601728] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed Action '-t' failed. The Apache error log may have more information. – Aptorian May 31 '16 at 18:55
  • Check here, it's for 14.04, so the php5 commands would be changed to php7, but there are a few options to fix it. http://askubuntu.com/questions/453377/how-to-enable-event-mpm-apache-2-4-on-ubuntu-14-04-with-thread-safe-php –  May 31 '16 at 18:59
  • Thank you! What ended up working was 'sudo a2dismod mpm_event', then 'sudo a2enmod mpm_prefork', then a 'sudo service apache2 restart'. At this point I have no idea why, but I'm happy I can move on the the next config step. Thanks again! – Aptorian May 31 '16 at 19:06
  • prefork basically is compatible with everything, event is not, it uses threads but your php isn't compatible without fixing it. As you look to gain performance, you should probably switch over to event, but you're good to go. :) –  May 31 '16 at 19:08
  • 1
    Possible duplicate of [PHP rendered as text after Ubuntu 16.04 upgrade](http://askubuntu.com/questions/760787/php-rendered-as-text-after-ubuntu-16-04-upgrade) – oerdnj May 31 '16 at 20:00

2 Answers2

11

Run the following command in terminal

sudo apt-get install libapache2-mod-php

vatz88
  • 211
  • 6
  • 9
1
sudo apt install php libapache2-mod-php
sudo apt install php7.0-mbstring
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
service apache2 restart

after that

gedit /etc/apache2/apache2.conf

add the following line

Include /etc/phpmyadmin/apache.conf

service apache2 restart

libapache2-mod-php server-side, HTML-embedded scripting language (Apache 2 module) so we have to add this