openSuse Leap 15.1: Apache is extremely slow

Hello.

I’ve been developing web apps with LAMP, the Apache is on my hard drive, wasn’t using virtual hosts, just a simlink to the htdocs folder. Everything was fast and good.

Then I’ve started playing with Laravel for some time, virtual box, vagrant, virtual hosts etc. Laravel seemed pretty fast, maybe because I haven’t made heavy DBs.

Now I went back to my localhost and find it extreeeeeeemly slow. It takes about 10 s to load any page from my local site which used to load in 1-2 s before. I thought it might be something to do with the virtual hosts and all. So I’ve removed them all, I’ve even reinstalled Apache and PHP, I’ve deleted ALL settings and configs, removed all rewrites etc. - same thing, the server is very slow. I tried the sites in Chromium - same slow.

I have not touched any MySql settings or configs ever, so it should not be the cause.

Would you have any ideas what might have caused this and how I can fix this?

Thank you.

First,
You might reboot and see if that improves performance.
You can also run top and free to monitor system resource usage.

You should also know that Apache, particularly as part of a LAMP configuration can require tuning.
A lot will depend on the type of website code you’re running.
If you’re running a website that serves non-interactive content, a script-based webserver like nginx, or many from your choice of coding (nodejs, ruby, python, etc) can perform better and might not require any tuning.

There’s a ton of articles written about Apache tuning, and there are many tools that can test various settings.

Bottom line,
This is a topic that’s hard to discuss in a Forum.
Every situation is individual to the hardware you’re running on, other software running and your website.

Troubleshooting SOP should be same as everything else,
Try to narrow down your problem bit by bit which is why I suggest the reboot and system monitoring to start… try to first determine if something in your system other than your LAMP might be the cause before you start looking at your webserver/website itself.

TSU

That’s exactly the reason why I wrote here because I’ve exhausted all other options, i.e. rebooting, reinstalling, tuning and all. I’m basically running a fresh install of LAMP here but it’s still slow.

As I said, everything was running fast and ok a few weeks ago.

I’m wondering what might have caused it to run much slower with the exactly same code (I haven’t touched any of the server files, as I said I was playing with Laravel from my home folder and virtual hosts, the site file remain in the htdocs unchanged). Because it’s never happened before on Linux. I haven’t had a single problem with openSuse for years, this post is like the first one in 5 years. That’s why I’m so puzzled.

It may not even be LAMP, maybe something else on Linux. What should I check for?

I’ve checked the memory usage, it’s got a few mysql, 6 Web processes, a dozen of httpd-prefork - are these quantities normal? WebExtensions take >300,000 K. I have 16 GB of RAM though.

I’ve disabled all desktop search stuff and cleared everything with the Sweeper. It improved the server speed a lot, now a simple page loads in 5 sec vs > 10 sec before. But this is still not enough, still too long. The pages opened within a second or two before. Something else is still interfering or slowing it down.

Review the apache docs for tuning/optimization…
http://httpd.apache.org/docs/2.4/misc/perf-tuning.html

and these may also be of guidance…
https://hostadvice.com/how-to/how-to-tune-and-optimize-performance-of-apache/
https://www.tecmint.com/apache-performance-tuning/

Apache is really fast even on the small i3-4130. The i7-6700K has:

erlangen:~ # systemctl status apache2.service 
● apache2.service - The Apache Webserver
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2020-06-15 05:04:08 CEST; 1h 52min ago
   Main PID: 755 (httpd-prefork)
     Status: "Processing requests..."
      Tasks: 6
     Memory: 8.1M
     CGroup: /system.slice/apache2.service
             ├─755 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>
             ├─827 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>
             ├─828 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>
             ├─829 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>
             ├─830 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>
             └─831 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache>

Jun 15 05:04:08 erlangen systemd[1]: Starting The Apache Webserver...
Jun 15 05:04:08 erlangen systemd[1]: Started The Apache Webserver.
erlangen:~ # 

Watch for additional messages in the journal. Tinkering with the network can have nasty side effects:

erlangen:~ # journalctl  -b -q --no-hostname -o short-monotonic -u apache2.service 
    3.946907] systemd[1]: Starting The Apache Webserver...
    4.106248] systemd[1]: Started The Apache Webserver.
erlangen:~ # 

Here’s what I got:

systemctl status apache2.service
● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-06-15 13:15:33 +11; 3h 6min ago
 Main PID: 1683 (httpd-prefork)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 11
   CGroup: /system.slice/apache2.service
           ├─1683 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─1839 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─1844 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─3232 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─3677 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─4467 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─4954 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─4958 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─5203 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           ├─5320 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>
           └─5326 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache2/httpd.conf -c Include /etc/apache2/sysconfig.d//include.conf -DSYSTE>

Jun 15 13:15:27 linux-hvw6 systemd[1]: Starting The Apache Webserver...
Jun 15 13:15:30 linux-hvw6 start_apache2[1683]: AH00557: httpd-prefork: apr_sockaddr_info_get() failed for linux-hvw6
Jun 15 13:15:30 linux-hvw6 start_apache2[1683]: AH00558: httpd-prefork: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Jun 15 13:15:33 linux-hvw6 systemd[1]: Started The Apache Webserver.

@deano_ferrari](https://forums.opensuse.org/member.php/122-deano_ferrari), thank you for the references!

and this:

httpd -V
Server version: Apache/2.4.33 (Linux/SUSE)
Server built:   2020-04-28 05:50:17.000000000 +0000
Server's Module Magic Number: 20120211:76
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/srv/www"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="/var/log/apache2/error_log"
 -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf"

Reading what deano_ferrari](https://forums.opensuse.org/member.php/122-deano_ferrari) posted, they say “This MPM is not suitable for use with non-thread-safe modules like mod_php, for which a replacement such a PHP-FPM must be used instead”. I have the prefork module installed, the other two (worker and event) are not installed, and I’m using the mod-php. Could this be the problem? Should I uninstall the mpm and install either the worker or event? Or can I have all 3 installed? PHP-FPM i snot installed either. What’s the best combination of modules with Apache and PHP for my local dev machine (not production server)?

I have seen similar messages and fixed /etc/hosts:

erlangen:~ # cat /etc/hosts
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.
# Syntax:
#    
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#


# special IPv6 addresses


127.0.0.1       localhost
::1     localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
**192.168.178.2   erlangen.fritz.box     erlangen
192.168.178.3   erlangen.fritz.box     erlangen**

erlangen:~ # 

my hosts:

127.0.0.1       localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet 

ff00::0         ipv6-mcastprefix 
ff02::1         ipv6-allnodes 
ff02::2         ipv6-allrouters 
ff02::3         ipv6-allhosts 
192.168.1.2     dataserver dataserver

Which Apache modules should I enable and how? How can I swap prefork to event and mod-php to php-fpm?

erlangen:~ # grep MODULES /etc/sysconfig/apache2 
# * In the APACHE_MODULES variable, you can use mod_xyz or just xyz syntax.
# APACHE_MODULES="authz_host alias auth dir log_config mime setenvif"
# APACHE_MODULES="authz_host actions alias asis auth autoindex cgi dir imap include log_config mime negotiation setenvif status userdir"
APACHE_MODULES="actions alias auth_basic authn_core authn_file authz_host authz_groupfile authz_core authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl socache_shmcb userdir reqtimeout"
erlangen:~ # 

The above are defaults. You may need to add more.

I’ve deleted the apache-mod-php7 and apache prefork packages, followed this doc:
https://en.opensuse.org/SDB:Apache_FastCGI_and_PHP-FPM_configuration

But now Apache fails to start with:

systemctl  status apache2.service
● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2020-06-15 17:38:56 +11; 1s ago
  Process: 12100 ExecStop=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful-stop (code=exited, status=1/FAIL ... Cannot load /usr/lib64/apache2-worker/mod_proxy_fcgi.so into server: /usr/lib64/apache2-worker/mod_proxy_fcgi.so: undefined symbol: proxy_module
  Process: 12359 ExecStart=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k start (code=exited, status=1/FAILURE)
 Main PID: 12359 (code=exited, status=1/FAILURE)

Jun 15 17:38:56 linux-hvw6.suse systemd[1]: Starting The Apache Webserver...
Jun 15 17:38:56 linux-hvw6.suse start_apache2[12359]: httpd-worker: Syntax error in -C/-c directive: Syntax error on >
Jun 15 17:38:56 linux-hvw6.suse systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
Jun 15 17:38:56 linux-hvw6.suse systemd[1]: Failed to start The Apache Webserver.
Jun 15 17:38:56 linux-hvw6.suse systemd[1]: apache2.service: Unit entered failed state.
Jun 15 17:38:56 linux-hvw6.suse systemd[1]: apache2.service: Failed with result 'exit-code'.

BTW it says
zypper a2dismod php7
Unknown command ‘a2dismod’

The above was Tumbleweed. Checkout yast2 > sysconfig > apache2 for your defaults.

I’ve added proxy and proxy-ajp modules, this solved the failure.

Here are my Apache modules:

authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir env include log_config mime negotiation setenvif status asis imagemap proxy proxy_ajp rewrite ssl wsgi fcgid reqtimeout version authz_core http2 socache_shmcb proxy_fcgi authn_core

Now Apache restarts but it gives me a 503 error:
Service unavailable!

    The server is temporarily unable to service your     request due to maintenance downtime or capacity     problems. Please try again later.   

If you think this is a server error, please contact the webmaster.

Error 503

[localhost](http://localhost/)

Apache

and this:
httpd -V
bash: /usr/sbin/httpd: No such file or directory

Could be a broken link:

erlangen:~ # file /usr/sbin/httpd
/usr/sbin/httpd: symbolic link to /usr/sbin/httpd-prefork
erlangen:~ # 

it points to a /usr/sbin/httpd-prefork but I’ve uninstalled it and am using a worker now

Made a new link to a httpd2-worker - same 503 error

You may want to do a clean reinstall starting with removing everything:

erlangen:~ # zypper rm --clean-deps --type pattern lamp_server
Reading installed packages...
Resolving package dependencies...

The following 21 packages are going to be REMOVED:
  apache2 apache2-doc apache2-example-pages apache2-mod_php7 apache2-prefork apache2-utils git-web patterns-server-lamp_server perl-CGI php7 php7-ctype php7-dom php7-iconv php7-json php7-pdo php7-sqlite php7-tokenizer php7-xmlreader
  php7-xmlwriter system-user-wwwrun yast2-http-server

The following pattern is going to be REMOVED:
  lamp_server

21 packages to remove.
After the operation, 52.3 MiB will be freed.
Continue? [y/n/v/...? shows all options] (y): n
erlangen:~ # 

the error log says it’s trying to connect on port 8000 - why?

[Mon Jun 15 18:18:03.183894 2020] [proxy:error] [pid 16946:tid 139706659227392] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:8000 (*) failed
[Mon Jun 15 18:18:03.183922 2020] [proxy_fcgi:error] [pid 16946:tid 139706659227392] [client 127.0.0.1:49298] AH01079: failed to make connection to backend: localhost

My ServerName is set to localhost:80

is there another setting overriding the httpd.conf? I don’t have vhosts configs.

I’m getting close. I forgot I made a new /etc/php7/fpm/php-fpm.d/www.conf following that Howto where is says it’s listening for 127.0.0.1:9000. When I change it to port 80, it fails with: “unable to bind listening socket for address ‘127.0.0.1:80’: Address already in use”

any idea how to enable localhost:80?

I got it! FFS, I finally got it to work after 3 hours… It’s faster but still nothing like it used to be. Anyway, here are the steps if anyone find themselves in a similar situation or just want to change the mod:

Ref. this doc:
https://en.opensuse.org/SDB:Apache_FastCGI_and_PHP-FPM_configuration

and

  1. Delete apache2-prefork, apache2-mod_php7
  2. Install apache2-worker and/or apache2-event, apache-mod_fcgid, php7-fpm
  3. Do all from that doc above
  4. YAST > Sysconfig > Network > WWW > Apache2 >
    • APACHE_MODULES > add proxy proxy_ajp fcgid http2 proxy_fcgi
    • APACHE_MPM > choose worker or event
  5. In /usr/sbin/ create (overwrite) new link ‘httpd’ for either httpd2-worker or httpd2-event
  6. Change the line in /etc/apache2/conf.d/mod_fcgid.conf:
    SetHandler “proxy:fcgi://localhost:9000/” <- the server and host must match those in /etc/php7/fpm/php-fpm.d/www.conf