Jump to content

Primary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Secondary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Squares Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to PHPFox Camp
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
cheap dedicated servers
Photo

Server Questions Optimizing Examples


  • Please log in to reply
47 replies to this topic

#1
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
Feel free to ask questions in this thread if you have your site setup on your own server or VPS.

Best things to check first to make sure your site is optimized is:
AdminCP --> Search for "Feed Limit Days" and set it to 3
Also, find out what your max PHP memory is, and then go to /public_html/include/init.inc.php and change 64M to the amount of your max PHP memory.

phpFox works best using the following:
Apache + Nginx ~or~ Nginx as your webserver
FastCGI
php-fpm
APC + Memcache ~or~ Xcache + Memcache or just APC or Xcache

Make sure you run msqltuner.pl to check your mySQL configuration.

Here is an optimized /etc/my.cnf for those of you with servers having 4-8gb of RAM

[myisamchk]
read_buffer=16M
key_buffer=64M
sort_buffer=64M
write_buffer=16M

[mysqld]
myisam_sort_buffer_size=256M
open_files_limit=30000
query_cache_type=1
query_cache_size=64M
query_cache_limit=64M
thread_cache_size=256
thread_concurrency=16
max_allowed_packet=1024M
sort_buffer=2M
interactive_timeout=500
table_definition_cache=10000
table_open_cache=10000
local-infile=0
default-storage-engine=MyISAM
wait_timeout=3000
connect_timeout=3000
tmp_table_size=256M
max_connections=300
key_buffer=64M
log-slow-queries="/var/lib/mysql/slow_queries.log"
long_query_time = 1
join_buffer=4M
max_heap_table_size=256M
low_priority_updates=1

[mysqldump]
max_allowed_packet=1024M
quick

[mysqld_safe]
open_files_limit=30000
nice=-5

Edited by destiny, 07 August 2012 - 01:02 AM.
Pinned by Destiny



#2
roldan

roldan

    Home Developer

  • Campers
  • 65 posts
I have a VPS 2GB RAM, Can you make a config for me ?

#3
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts

I have a VPS 2GB RAM, Can you make a config for me ?


Rename your existing my.cnf to my.cnf.old or back it up somewhere.
Try this out. Best thing is to download mysqltuner.pl and run it and it will tell you what settings to change, but this will work very well regardless.

[myisamchk]
read_buffer=16M
key_buffer=64M
sort_buffer=64M
write_buffer=16M

[mysqld]
myisam_sort_buffer_size=128M
open_files_limit=30000
query_cache_type=1
query_cache_size=64M
query_cache_limit=64M
thread_cache_size=256
thread_concurrency=16
max_allowed_packet=1024M
sort_buffer=2M
interactive_timeout=500
table_definition_cache=10000
table_open_cache=10000
local-infile=0
default-storage-engine=MyISAM
wait_timeout=3000
connect_timeout=3000
tmp_table_size=128M
max_connections=200
key_buffer=64M
log-slow-queries="/var/lib/mysql/slow_queries.log"
long_query_time = 1
join_buffer=4M
max_heap_table_size=128M
low_priority_updates=1

[mysqldump]
max_allowed_packet=1024M
quick

[mysqld_safe]
open_files_limit=30000
nice=-5


#4
azer

azer

    Home Developer

  • Campers
  • 81 posts
  • Locationparis
hello thanks for you tips
is there any benchmark to see the result of your settings and aslo speed of ning versus apache ?

#5
roldan

roldan

    Home Developer

  • Campers
  • 65 posts
yap, I'm already using mysqltuner last few months.
What else do you recommend ?

#6
roldan

roldan

    Home Developer

  • Campers
  • 65 posts
Kindly check my modified code:


[myisamchk]
read_buffer=16M
key_buffer=64M
sort_buffer=64M
write_buffer=16M

[mysqld]
local-infile=0
max_connections = 180
wait_timeout = 25800
interactive_timeout = 25800
query_cache_size = 16M
join_buffer_size = 1M
thread_cache_size = 4
table_cache = 96
innodb_buffer_pool_size = 256M
key_buffer_size = 64M
tmp_table_size = 512M
max_heap_table_size = 512M


myisam_sort_buffer_size=128M
open_files_limit=30000
query_cache_type=1
query_cache_size=64M
query_cache_limit=64M
thread_cache_size=256
thread_concurrency=16
max_allowed_packet=1024M
sort_buffer=2M
interactive_timeout=500
table_definition_cache=10000
table_open_cache=10000
local-infile=0
default-storage-engine=MyISAM
wait_timeout=3000
connect_timeout=3000
tmp_table_size=128M
max_connections=200
key_buffer=64M
log-slow-queries="/var/lib/mysql/slow_queries.log"
long_query_time = 1
join_buffer=4M
low_priority_updates=1

[mysqldump]
max_allowed_packet=1024M
quick

[mysqld_safe]
open_files_limit=30000
nice=-5


#7
roldan

roldan

    Home Developer

  • Campers
  • 65 posts
My conf:


[mysqld]
local-infile=0
max_connections = 180
wait_timeout = 25800
interactive_timeout = 25800
query_cache_size = 16M
join_buffer_size = 2M
thread_cache_size = 4
table_cache = 96
innodb_buffer_pool_size = 256M
key_buffer_size = 64M
tmp_table_size = 128M
max_heap_table_size = 512M


sort_buffer_size = 2M
myisam_sort_buffer_size=64M
open_files_limit=15000
query_cache_type=1
query_cache_limit=32M
thread_concurrency=16
max_allowed_packet=1024M
sort_buffer=1M
table_definition_cache=5000
table_open_cache=5000
connect_timeout=3000
log-slow-queries="/var/lib/mysql/slow_queries.log"
long_query_time = 1
low_priority_updates=1

[mysqldump]
max_allowed_packet=1024M
quick

[mysqld_safe]
open_files_limit=30000
nice=-5



My result:


[root@server ~]# ./mysqltuner.pl

 >>  MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: admin
Please enter your MySQL administrative password:

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.63-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 129M (Tables: 290)
[--] Data in InnoDB tables: 188M (Tables: 153)
[--] Data in MEMORY tables: 248K (Tables: 3)
[!!] Total fragmented tables: 167

-------- Security Recommendations  -------------------------------------------
ERROR 1142 (42000) at line 1: SELECT command denied to user 'admin'@'localhost' for table 'user'
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 54s (1K q [27.556 qps], 83 conn, TX: 15M, RX: 443K)
[--] Reads / Writes: 82% / 18%
[--] Total buffers: 466.0M global + 3.6M per thread (180 max threads)
[OK] Maximum possible memory usage: 1.1G (62% of installed RAM)
[OK] Slow queries: 0% (0/1K)
[OK] Highest usage of available connections: 2% (4/180)
[OK] Key buffer size / total MyISAM indexes: 64.0M/43.9M
[OK] Key buffer hit rate: 97.6% (16K cached / 400 reads)
[OK] Query cache efficiency: 65.5% (766 cached / 1K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 81 sorts)
[!!] Joins performed without indexes: 63
[OK] Temporary tables created on disk: 12% (8 on disk / 62 total)
[OK] Thread cache hit rate: 95% (4 created / 83 connections)
[OK] Table cache hit rate: 95% (143 open / 150 opened)
[OK] Open file limit used: 0% (185/30K)
[OK] Table locks acquired immediately: 99% (1K immediate / 1K locks)
[OK] InnoDB data size / buffer pool: 189.0M/256.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Adjust your join queries to always utilize indexes
Variables to adjust:
    join_buffer_size (> 2.0M, or always use indexes with joins)

[root@server ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1792        685       1106          0          0        324
-/+ buffers/cache:        360       1431
Swap:         2048         43       2004
[root@server ~]#


#8
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
Looks fine.

If you don't have your php.ini hardened, you might want to add these in your disable functions. They are all to protect against security violations.

disable_functions = "crack_check,crack_closedict,crack_getlastmessage,crack_opendict,psockopen,php_ini_scanned_files,hell-exec,system,dl,ctrl_dir,phpini,tmp,safe_mode,systemroot,server_software,get_current_user,HTTP_HOST,php_uname,ini_restore,popen,pclose,exec,shell_exec,suExec,passthru,proc_open,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellcmd,escapeshellarg,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_setegid,posix_seteuid,posix_setgid,posix_times,posix_ttyname,posix_uname,posix_access,posix_get_last_error,posix_mknod,posix_strerror,posix_initgroups,posix_setsidposix_setuid,show_source,allow_url_fopen"


#9
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts

hello thanks for you tips
is there any benchmark to see the result of your settings and aslo speed of ning versus apache ?


You can find a ton of benchmarks on www.webhostingtalk.com and tons of optimizing techniques. Just realize if it isn't broke, don't try and fix it. Nginx with Fastcgi and php-fpm is much faster than anything else out there. Litespeed webserver is a waste of money.

#10
azer

azer

    Home Developer

  • Campers
  • 81 posts
  • Locationparis

Looks fine.

If you don't have your php.ini hardened, you might want to add these in your disable functions. They are all to protect against security violations.

disable_functions = "crack_check,crack_closedict,crack_getlastmessage,crack_opendict,psockopen,php_ini_scanned_files,hell-exec,system,dl,ctrl_dir,phpini,tmp,safe_mode,systemroot,server_software,get_current_user,HTTP_HOST,php_uname,ini_restore,popen,pclose,exec,shell_exec,suExec,passthru,proc_open,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellcmd,escapeshellarg,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_setegid,posix_seteuid,posix_setgid,posix_times,posix_ttyname,posix_uname,posix_access,posix_get_last_error,posix_mknod,posix_strerror,posix_initgroups,posix_setsidposix_setuid,show_source,allow_url_fopen"


what do you mean by hardeneded?
is there any placement better to copy paste your line of disable functions?

#11
carrierlp

carrierlp

    Business Developer

  • Campers
  • 388 posts
hey i have 2 servers with 96gb ram ??? holy hell. can you PM your host and pricing plans?

#12
cozumel

cozumel

    Fox Fan Club

  • Campers
  • 1,584 posts
Keep on topic guys.

@Zed If you have a real question then post it here and benefit from Ant's vast experience, but please don't post crap like 'guise i haz server, give me code?'. Because the bottom line here is if you did actually have two servers with 96gb, you wouldn't be posting here! :P

Also, to everyone, if you're not capable of understanding this post then don't bother trying to change any of your code, just get your service provider to do it for you.

#13
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
use mysqltuner.pl and tuningprimer.sh and you will get precisely what I offer above.

#14
roldan

roldan

    Home Developer

  • Campers
  • 65 posts

Looks fine.

If you don't have your php.ini hardened, you might want to add these in your disable functions. They are all to protect against security violations.

disable_functions = "crack_check,crack_closedict,crack_getlastmessage,crack_opendict,psockopen,php_ini_scanned_files,hell-exec,system,dl,ctrl_dir,phpini,tmp,safe_mode,systemroot,server_software,get_current_user,HTTP_HOST,php_uname,ini_restore,popen,pclose,exec,shell_exec,suExec,passthru,proc_open,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,escapeshellcmd,escapeshellarg,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_setegid,posix_seteuid,posix_setgid,posix_times,posix_ttyname,posix_uname,posix_access,posix_get_last_error,posix_mknod,posix_strerror,posix_initgroups,posix_setsidposix_setuid,show_source,allow_url_fopen"


In which file should I add this?
still php.ini ?
Thanks !

Just added it, and then do:


[root@server ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd:
[root@server ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
[root@server ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd:
[root@server ~]#

Edited by roldan, 06 August 2012 - 05:56 AM.


#15
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
Good job Roldan. I'm not sure how proficient you are with Linux and so forth, but here's some easy commands to keep:

Optimize/Repair all databases and all tables
--------------------------------
REPAIR COMMAND
------------------
mysqlcheck -Ar -uroot

OPTIMIZE COMMAND
------------------
mysqlcheck -Ao -uroot


MySQL Command thru SSH
----------------------------------
mysql -u dbusername -p dbname < blah.sql


for taking backup,
----------------------------------
mysqldump -v DATABASE_NAME > BACKUP.sql


for restoring,
-----------------------------------
mysql -v DATABASE_NAME < BACKUP.sql


compress and then download
----------------------------------
tar -czvf backup.tar.gz nameofdbhere.sql

#16
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts

@carrierip

yes ! i have 2 servers with 96gb ram

?


If you really have that and you need help, your data center should help you with that, but if not, feel free to inbox me and we can schedule a time in which I will help you. With that amount of memory there are multiple things to do that will have you running supremely fast.

#17
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
Settings for Xcache in php.ini if you use Xcache and this works for any server with 1gb Ram on up

***Note: Change xcache.count="8" to however many Cores you have for your cpus, so if you have a dual core it would be "2", quad core "4" dual quad core "8" etc.

xcache.admin.enable_auth="on"
xcache.admin.pass="md5 password goes here not required"
xcache.admin.user="username not required"
xcache.cacher="On"
xcache.coredump_directory=""
xcache.count="8"
xcache.coveragedump_directory="/tmp/pcov/"
xcache.coverager="Off"
xcache.gc_interval="0"
xcache.mmap_path="/dev/zero"
xcache.optimizer="Off"
xcache.readonly_protection="Off"
xcache.size="128M"
xcache.slots="8K"
xcache.test="Off"
xcache.ttl="0"
xcache.var_count="1"
xcache.var_gc_interval="300"
xcache.var_maxttl="0"
xcache.var_size="64M"
xcache.var_slots="8K"
xcache.var_ttl="0"

Settings for APC in php.ini if you use APC and this works for any server with 1gb Ram on up

apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 128M
apc.optimization = 0
apc.num_files_hint = 512
apc.user_entries_hint = 1024
apc.ttl = 3600
apc.user_ttl = 3600
apc.gc_ttl = 600
apc.cache_by_default = 1
apc.filters = "-/home/username/public_html/apc/apc\.php$"
apc.slam_defense = 0
apc.use_request_time = 1
apc.mmap_file_mask = "/tmp/apc-accountname.XXXXXX"
;OR apc.mmap_file_mask = /dev/zero
apc.file_update_protection = 2
apc.enable_cli = 0
apc.max_file_size = 2M
apc.stat = 1
apc.write_lock = 1
apc.report_autofilter = 0
apc.include_once_override = 0
apc.rfc1867 = 0
apc.rfc1867_prefix = "upload_"
apc.rfc1867_name = "APC_UPLOAD_PROGRESS"
apc.rfc1867_freq = 0
apc.localcache = 1
apc.localcache.size = 512
apc.coredump_unmap = 0
apc.stat_ctime = 0


#18
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
If you use FastCGI and you allow video uploads, this needs to be in your Apache --> Pre Virtual Host Include (all versions)

<IfModule mod_fcgid.c>
 FcgidMaxRequestLen 1073741824
 FcgidIdleTimeout 3600
 FcgidProcessLifeTime 3600
 FcgidBusyTimeout 3600
 FcgidIOTimeout 3600
 FcgidConnectTimeout 20
</IfModule>


#19
DarkGoth

DarkGoth

    Moderator

  • Moderators
  • 1,236 posts
  • LocationUnknown
ant : we want more! we want more! haha

#20
hackerant

hackerant

    Pro Developer

  • Fox Fan Club
  • 729 posts
If you have installed Nginx on top of Apache, this is an optimal configuration. The only thing you might want to change is your client max size depending upon how big of files you allow to be uploaded. This is also already optimized for (d)dos mitigation with limit connects and limit requests.

user  nobody;
# no need for more workers in the proxy mode
worker_processes  2;
error_log  /var/log/nginx/error.log info;
worker_rlimit_nofile 20480;
events {
 worker_connections 5120; # increase for busier servers
 use epoll; # you should use epoll here for Linux kernels 2.6.x
}
http {
 server_name_in_redirect off;
 server_names_hash_max_size 10240;
 server_names_hash_bucket_size 1024;
 include    mime.types;
 default_type  application/octet-stream;
 server_tokens off;
 disable_symlinks if_not_owner;
 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout  3;
 gzip on;
 gzip_vary on;
 gzip_disable "MSIE [1-6]\.";
 gzip_proxied any;
 gzip_http_version 1.1;
 gzip_min_length  1000;
 gzip_comp_level  6;
 gzip_buffers  16 8k;
# You can remove image/png image/x-icon image/gif image/jpeg if you have slow CPU
 gzip_types    text/plain text/xml text/css application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg application/xml+rss text/javascript application/atom+xml;
 ignore_invalid_headers on;
 client_header_timeout  120m;
 client_body_timeout 120m;
 send_timeout	 120m;
 reset_timedout_connection on;
 connection_pool_size  256;
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
 client_max_body_size 256M;
 client_body_buffer_size 128k;
 request_pool_size  32k;
 output_buffers   4 32k;
 postpone_output  1460;
 proxy_temp_path  /tmp/nginx_proxy/;
 client_body_in_file_only on;
 log_format bytes_log "$msec $bytes_sent .";
 include "/etc/nginx/vhosts/*";
 include /etc/nginx/naxsi_core.rules;
#limit_zone limit_per_ip $binary_remote_addr 5m;
#limit_conn_zone limit_per_ip $binary_remote_addr 10m;
#limit_conn_zone limit_per_ip $binary_remote_addr zone=limit_per_ip:10m;
limit_req_zone $binary_remote_addr zone=allips:5m rate=200r/s;
limit_req zone=allips burst=200 nodelay;
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {

location /RequestDenied {
	 proxy_pass http://127.0.0.1:4242;
   }

	   location /etc/nginx/vhosts/ {
	  limit_conn addr 22;
	    set $limit_rate 100k;
	   }
}
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users