多语言展示
当前在线:491今日阅读:26今日分享:39

centos6下配置apache+php+mysql

个人分享经验,在vultr网站上选购SSD cloud server固态硬盘云共享服务器时,设置apache+php+mysql环境。本人选购的是2G内存的配置。
工具/原料

windows上安装Putty

方法/步骤

打开putty,连接服务器,设置服务器的IP和Port,默认是root,login as: rootpasswd: 你的密码

方法/步骤2
1

连接入服务器后,先安装apachesudo yum updatesudo yum install httpd

2

编译一下httpdvim /etc/httpd/conf/httpd.confKeepAlive Off      StartServers        4     MinSpareServers     20     MaxSpareServers     40     MaxClients          200     MaxRequestsPerChild 4500 

3

设置apache虚拟服务器vim /etc/httpd/conf.d/vhost.conf      ServerAdmin admin@example.org     #联系E-MAIL ServerName example.org     #域名 ServerAlias www.example.org     #关联域名www DocumentRoot /var/www/html/      #设置网页路径ErrorLog /var/www/logs/error.log     #错误日志 CustomLog  /var/www/logs/access.log combined  #登陆日志

4

建立网页路径目录和日志目录sudo mkdir -p /var/www/html/ sudo mkdir -p /var/www/logs/

方法/步骤3
1

安装mysql数据库sudo yum install mysql-server

2

设置mysql密码sudo /usr/bin/mysql_secure_installationEnter current password for root (enter for none): #键入你的密码然后出现OK, successfully used password, moving on...按照下面提示键入yBy default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them.  This is intended only for testing, and to make the installation go a bit smoother.  You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y                                             ... Success! Normally, root should only be allowed to connect from 'localhost'.  This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y       ... Success! By default, MySQL comes with a database named 'test' that anyone can access.  This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y       - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y       ... Success! Cleaning up... All done!  If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!

3

配置mysqlvim /etc/my.cnf修改以下几行提高效率max_connections = 3000  #数据库最大连接数max_connect_errors = 6000   #数据库最大错误连接数thread_cache_size = 300 #进程缓存query_cache_size = 64M #MyISAM引擎优化中缓存query_cache_limit = 4M #指定单个查询能够使用的缓冲区大小tmp_table_size = 256M #临时表大小key_buffer_size = 1024M #索引缓存大小read_rnd_buffer_size = 16M #随机读取缓存bulk_insert_buffer_size = 64M  #插入缓存myisam_sort_buffer_size = 128M  #MyISAM引擎排序缓存myisam_max_sort_file_size = 10G  #重建索引最大允许的临时文件大小innodb_additional_mem_pool_size = 16M #InnoDB 存储的数据目录信息和其它内部数据结构的内存池大小innodb_buffer_pool_size = 1024M #InnoDB 存储缓存区大小

4

开启mysql服务器sudo service mysqld start设置apache服务器为开机自启动sudo chkconfig mysql on

方法/步骤4
1

安装phpsudo yum install php php-mysql重启apache服务器sudo service httpd restart

2

新建一个php文件,检查一下服务器是否安装完成?sudo nano /var/www/html/index.php添加以下几行然后再浏览器里打卡页面http://你的域名

推荐信息