I run a single Wordpress site on my CentOS 7 droplet, using Apache 2.4.6.
Every couple of days, my site suddenly becomes unavailable. I have to restart Apache, and it works again.
No errors, just I get a notification from my monitoring service that my site is down, and when I try to load it, it just hangs. No errors or anything.
And not a high server load, so I don’t think it’s just trying to load the site for a very long time or anything.
But, no errors that I can find. I’ve checked /etc/httpd/logs/error_log, /etc/httpd/logs/ssl_error_log, and even /var/log/messages. Also checked MariaDB just to be sure.
There are no errors. The only thing Apache says is when I restarted it after the fact.
I’m not sure if it could be due to memory, but I’ve checked the memory usage right around when it happens, and haven’t noticed anything out of the ordinary.
I’m just not sure how to track this down. Any help would be appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Without some more information it can be hard to find a cause.
One cause I see a lot is Apache can get stuck if the memory limit is hit on all instances open and timeout is disabled or made really long. If ignore user exit is turned on in Wordpress or PHP it will keep running a script even if in a loop and the user leaves.
Is there any CPU spikes around the same time? You might want to install a server monitor of some kind like New Relic that will give you info on what happens when it happens.
W3TC will generate a file when it detects NGINX instead of Apache and you’ll essentially copy/paste the contents of that file in to your NGINX server block, then restart NGINX. The extra part I mentioned is because you have to manually do this anytime you make changes that would extend or remove any portion of the server block code that W3TC generates.
W3TC will generate changes made to your .htaccess file on the fly as long as it has the permissions to write to it. NGINX doesn’t work that way since all of your configuration goes inside the server block for your domain.
That being said, NGINX + PHP-FPM, in my experience, is more performant than Apache + mod_php or similar. It can be used as a standard HTTP server, reverse proxy, caching proxy, etc. Also, should the need arise, you can actually separate NGINX from PHP-FPM and run them on their own servers. You would then configure NGINX to proxy the request to the PHP-FPM server. I actually just setup testing for that exact configuration.
MySQL Configuration
First off, before modifying your my.cnf file, make a backup copy:
cp /etc/mysql/my.cnf /usr/local/src/my.cnf
Verify the above backup is a valid copy and then shutdown MySQL:
service mysql stop
Then simply delete the existing file, create a new one, and then paste the contents below in.
sudo rm -rf /etc/mysql/my.cnf \
&& nano /etc/mysql/my.cnf
[mysql]
max_allowed_packet = 32M
[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
back_log = 75
max_connections = 300
key_buffer_size = 32M
myisam_sort_buffer_size = 32M
myisam_max_sort_file_size = 2048M
join_buffer_size = 64K
read_buffer_size = 64K
sort_buffer_size = 128K
table_definition_cache = 4096
table_open_cache = 2048
thread_cache_size = 64
wait_timeout = 1800
connect_timeout = 10
tmp_table_size = 32M
max_heap_table_size = 32M
max_allowed_packet = 32M
max_seeks_for_key = 1000
group_concat_max_len = 1024
max_length_for_sort_data = 1024
net_buffer_length = 16384
max_connect_errors = 100000
concurrent_insert = 2
read_rnd_buffer_size = 256K
bulk_insert_buffer_size = 8M
query_cache_limit = 512K
query_cache_size = 16M
query_cache_type = 1
query_cache_min_res_unit = 2K
query_prealloc_size = 262144
query_alloc_block_size = 65536
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
default-storage-engine = InnoDB
log_warnings=1
slow_query_log=0
long_query_time=1
slow_query_log_file=/var/lib/mysql/slowq.log
log-error=/var/log/mysqld.log
innodb_large_prefix=1
innodb_purge_threads=1
innodb_doublewrite = 1
innodb_file_per_table = 1
innodb_open_files = 1000
innodb_data_file_path= ibdata1:10M:autoextend
innodb_buffer_pool_size = 48M
innodb_additional_mem_pool_size = 32M
innodb_log_files_in_group = 2
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 0
innodb_lock_wait_timeout=50
#innodb_flush_method = O_DIRECT
innodb_support_xa=1
# 200 * # DISKS
innodb_io_capacity = 100
innodb_read_io_threads = 2
innodb_write_io_threads = 2
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer = 32M
sort_buffer = 16M
read_buffer = 16M
write_buffer = 16M
[mysqlhotcopy]
interactive-timeout
Now start MySQL:
service mysql start
This is a bare minimum setup that should perform well for the time being. It enables query caching and provides tweaks to common configuration.
You shouldn’t run in to any issues with that setup as long as you’re running an up to date version of MySQL or MariaDB (a drop-in replacement for MySQL). If you do, that’s why we created a backup so that we can revert back without issue.
If you do hit a snag, make sure to copy the error and paste it in a reply.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.