CentOS服务器安装php和mysql网站服务的笔记

1、确认apache 是否安装(CentOS系统是否自带)
cat /etc/redhat-release //查看centOS版本
rpm -qa 显示所有安装了的软件
rpm –qa vnc 查看是否已经安装了vncserver
rpm -q httpd //查看是否安装apache

# yum -y install httpd ← 在线安装httpd
2、安装php
#yum -y install php ← 在线安装PHP
#yum install php-gd //安装GD
3、安装Zend Optimizer
#cd /usr/local/src
#wget http://downloads.zend.com/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glib...
#tar -xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
#./ZendOptimizer-3.3.3-linux-glibc23-i386/install.sh
根据提示操作
# cd ← 回到root根目录
# rm -rf ZendOptimizer* ← 删除安装后遗留的源文件及目录
4、配置httpd安全
# vi /etc/httpd/conf/httpd.conf ← 编辑Apache的配置文件

ServerTokens OS ← 找到这一行,将“OS”改为“Prod”(在出现错误页的时候不显示服务器操作系统的名称)

ServerSignature On ← 找到这一行,将“On”改为“Off”, 在错误页中不显示Apache的版本

ServerAdmin root@localhost ← 将管理员邮箱设置为自己常用的邮箱

AllowOverride None ← 找到这一行,将“None”改为“All”, 变为此状态,允许.htaccess

#AddDefaultCharset UTF-8 ← 不使用UTF-8作为网页的默认编码
AddDefaultCharset GB2312 ← 并接着添加这一行(添加GB2312为默认编码)

← 找到这一个标签,并在标签中更改相应选项
Options Indexes MultiViews← 找到这一行,将“Indexes”删除
所有节点中的 Indexes 都删除

5、删除测试页
# rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
Apache欢迎页面放到在该目录下welcome.conf #/etc/httpd/conf.d/welcome.conf
6、安装mysql
# yum -y install mysql-server ← 安装MySQL
# yum -y install php-mysql ← 安装php-mysql

7、启动MySQL,并让MySQL在系统重新启动后随系统自动启动。
# chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
# chkconfig --list mysqld ← 确认MySQL自启动
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2--5为on的状态就OK
# /etc/rc.d/init.d/mysqld start ← 启动MySQL服务

8、Mysql初始化设置
# mysql -u root ← 用root用户登录MySQL服务器
mysql> select user,host,password from mysql.user; //查看用户信息
mysql> set password for root@localhost=password('在这里填入 root密码'); //设置root密码
Query OK, 0 rows affected (0.01 sec)
mysql> set password for root@'sample.centospub.com'=password('在这里填入root密码'); //设置root密码
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host,password from mysql.user;

测试一下root密码有没有生效:

# mysql -u root ← 通过空密码用root登录
# mysql -u root -h sample.com ← 通过空密码用root登录
以上提示拒绝登陆 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

# mysql -u root -p ← 通过密码用root登录
# mysql -u root -h sample.com -p ← 通过密码用root登录

安全性:
mysql>delete from mysql.user where user=''; ← 删除匿名用户
mysql>drop database test; ← 删除名为test的空数据库,删除测试用数据库

新建用户和对应其可操作的数据库
mysql>grant all privileges on newdb.* to admin@localhost identified by '在这里定义密码'; ← 建立对newdb数据库有完全操作权限的名为admin的用户
mysql> select user from mysql.user where user='admin'; ← 确认admin用户是否被新建

最后,重新启动一次HTTP服务,让php-mysql反映到HTTP服务中。
# /etc/rc.d/init.d/httpd restart ← 重新启动HTTP服务

9、phpmyadmin 安装
查看 http://www.phpmyadmin.net/home_page/version.php 新版本

#wget http://jaist.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.3.4-...
# tar zxvf phpMyAdmin-3.3.4-all-languages.tar.gz
# mv phpMyAdmin-3.3.4-all-languages/ /var/www/html/php_admin

# yum -y install php-mbstring ← 在线安装php-mbstring
# yum -y install php-mcrypt ← 在线安装php-mcrypt

# cp /var/www/html/php_admin/config.sample.inc.php /var/www/html/php_admin/config.inc.php
← 复制默认配置文件模板-->建立到应用配置文件config.inc.php

# vi /var/www/html/php_admin/config.inc.php
$cfg['blowfish_secret'] = '在 此填入口令'; ← 找到此行,并设置相应的口令(这个口令只是程序内部使用,并非登录相关的口令。口令长度限制在46个字符以内。)

# /etc/rc.d/init.d/httpd restart ← 重新启动HTTP服务,使以上设置生效

10、php升级到5.2
http://wiki.centos.org/HowTos/PHP_5.1_To_5.2

新建 # /etc/yum.repos.d/CentOS-Testing.repo ,文件内容如下:

# CentOS-Testing:
# !!!! CAUTION !!!!
# This repository is a proving grounds for packages on their way to CentOSPlus and CentOS Extras.
# They may or may not replace core CentOS packages, and are not guaranteed to function properly.
# These packages build and install, but are waiting for feedback from testers as to
# functionality and stability. Packages in this repository will come and go during the
# development period, so it should not be left enabled or used on production systems without due
# consideration.
[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
includepkgs=php*

保存后,运行:
# yum update
# service httpd restart

11、虚拟主机,多域
# vi /etc/httpd/conf/httpd.conf
#NameVirtualHost *:80 ← 找到这一行,去掉行首的#

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common

重启httpd
#service httpd restart

12、安装ftp server
#yum install vsftpd
#touch /etc/vsftpd/vsftpd.chroot_list
#service vsftpd start
#useradd ftpuser -d /var/www/html -s /sbin/nologin //添加FTP用户
#passwd ftpuser //设定密码

#chown -R ftpuser /var/www/html //目录权限

#echo 'ftpuser'>>/etc/vsftpd/vsftpd.chroot_list
//把用户加到/etc/vsftpd/vsftpd.chroot_list里,这样用户就可以正常登陆并且不能跳出自己的目录
#service vsftpd restart

13、服务器性能测试
#yum -y install gcc //安装GCC
#yum -y install gcc-c++

# wget http://byte-unixbench.googlecode.com/files/unixbench-5.1.2.tar.gz
# tar -zxvf unixbench-5.1.2.tar.gz
# cd unixbench-5.1.2/
# make
# ./Run
# ./Run 8

posted on 2011-07-04 02:43  Drupal  阅读(528)  评论(0编辑  收藏  举报