I bought a VPS. The RAM is 1GB. I installed apache, MySQL, etc. But when I put my site on it, apache or MySQL rapidly down or I get a 500 Internal Server. I don't know why. Did I config wrong, or a 1GB RAM is not enough? The site is the one in my signature which has about 10,000 daily visits and 40,000+ PV.
Okay now what are you lack off is you didnt optimized your VPS properly. Optimizing a VPS is important not only for VPS but for dedicated server itself too. I assume your VPS is unmanaged since you ask about it here. The 1st thing you might wanna do is checking your error log to get more info what cause the error. Ussually every error does tell what you need to add more ^^. Removing & Tweaking Unnecessary Services There’s a number of services that you can remove or tweak to increase performance. To remove any of these services log into WHM & go to Service Configuration > Service Manager or Cpanel > Plugins in the left menu. Clamd: This is a virus scanning service, it uses up a ton of memory do generally I’ll remove it. Entropy Chat: Disable this. Spamd: This uses a lot of processes & memory. You shouldn’t remove this, instead we can tweak it. Go to Cpanel > Plugins & install spamdconf, once done go to the bottom of WHM & click on Setup Spamd Startup Configuration. Change the maximum children to 1 or 2. This will stop spamd spawning too many child processes. If you use LxAdmin go to Server Mail Settings and untick both "Enable Spamdyke" & "Enable Virus Scan". Use google apps to recieve your email well a lots safer plus you dont have to scan for your incoming email ^^ you are totally safe. Okay now the 1st part is done let go to the next step ^^. Mysql Optimisation You can edit your mysql configuration (/etc/my.cnf) by typing vi /etc/my.cnf In order to add something in vi you need to hit insert, once completed hit esc then :wq to save & quit. If you want to save without quitting type :q! There’s a few important variables that we’re going to tweak: [*] max_connections [*] wait_timeout [*] thread_cache_size [*] table_cache [*] key_buffer_size [*] query_cache_size [*] tmp_table_size The settings below should work well for a server with 128MB Guaranteed RAM (also leaving you enough free for traffic spikes), if you have burstable then you can probably look at increasing the number of max_connections to 400 & possibly the key_buffer to 64M. This is my current setting for 192mb RAM burstable twice the guaranteed RAM. Take note that I do this setting based on suggestion by tuning-primer.sh and by looking on error log for which one I'm lack off. With this I can support 14k - 25k unique visit perday with 400-500 user online at the same time. [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock key_buffer = 4M long_query_time = 5 join_buffer_size = 1M read_buffer_size = 2M sort_buffer_size = 1M wait_timeout = 500 table_cache = 2000 max_connections = 50 max_allowed_packet = 1M read_buffer_size = 3M read_rnd_buffer_size = 1M net_buffer_length = 2K thread_stack = 64K thread_cache_size = 286 interactive_timeout = 25 query_cache_limit = 2M query_cache_size = 2M query_cache_type = 1 skip-bdb skip-innodb skip-locking [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash #safe-updates [safe_mysqld] open-files-limit = 577997 [isamchk] key_buffer = 8M sort_buffer_size = 8M [myisamchk] key_buffer = 8M sort_buffer_size = 8M [mysqlhotcopy] interactive-timeout [client] port = 3306 socket = /var/lib/mysql/mysql.sock Code (markup): Apache Optimisation Apache settings are located in httpd.conf, you can use ‘locate httpd.conf’ or ‘whereis httpd.conf’ to find it. Optimal settings for apache should look something like this, I like to keep the min & start servers slightly lower to stop too many child processes spawning & using memory. Below are my setting which for me is quite stable S # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 2000 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 1 ## ## Server-Pool Size Regulation (MPM specific) ## # prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # ServerLimit: maximum value for MaxClients for the lifetime of the server # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule prefork.c> StartServers 16 MinSpareServers 8 MaxSpareServers 24 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 500 </IfModule> Code (markup): Since I dont know which mpm you use so I assume you are using prefrok mpm which is the default setting. Save & restart both of your mysqld and httpd. You can use "service httpd restart" & "service mysqld restart" With above configuartion you should be able to achieve this on top. Take note that your result might be different if you use WHM/cPanel. I'm using LxAdmin to manage my VPS. Tasks: 50 total, 1 running, 49 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 393216k total, 135212k used, 258004k free, 0k buffers Swap: 0k total, 0k used, 0k free, 0k cached Code (markup): This is a result before optimization. *This is not a real data. It's almost similar like this. Tasks: 50 total, 5 running, 40 sleeping, 0 stopped, 5 zombie Cpu(s): 60.0%us, 0.0%sy, 0.0%ni,40.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 393216k total, 258004k used, 135212k free, 0k buffers Swap: 0k total, 0k used, 0k free, 0k cached Code (markup):
Hey CrumX, you are so helpful. I'm using unmanaged VPS and installed ISPConfig as control panel. Thank you for your Mysql and Apache Optimisation.