【centos6.5】
一、搭建Nginxfuwu
二、搭建Mysql数据库
三、安装PHP服务
四、在LNMP平台,部署SKYUC应用
五、phpwind论坛安装
一、搭建Nginx服务器
1、安装支持软件
[root@localhost ~]# rpm -q gcc gcc-c++ make zlib-devel pcre-devel
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
make-3.81-20.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
You have new mail in /var/spool/mail/root
2、创建程序用户和组
3、编译安装Nginx
4、编写Nginx服务控制脚本
5、添加Nginx到系统服务,并启动Nginx服务
6、修改nginx.conf主配置文件,添加俩个虚拟主机
7、创建测试页面,进行测试
二、搭建Mysql数据库
2.1、安装支持软件
[root@localhost ~]# rpm -q ncurses-devel
package ncurses-devel is not installed
[root@localhost ~]# yum -y install ncurses-devel
[root@localhost ~]# ls 【拉此包进来】
anaconda-ks.cfg cmake-2.8.6.tar.gz nginx-1.6.0.tar.gz 视频 下载
ansible install.log 公共的 图片 音乐
cc.sh install.log.syslog 模板 文档 桌面
[root@localhost ~]# tar xf cmake-2.8.6.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/cmake-2.8.6/
[root@localhost cmake-2.8.6]# ./configure && gmake && gmake install
2.2 编译安装Mysql数据库
[root@localhost ~]# ls 【拉此包进来】
anaconda-ks.cfg cmake-2.8.6.tar.gz mysql-5.5.22.tar.gz 模板 文档 桌面
ansible install.log nginx-1.6.0.tar.gz 视频 下载
cc.sh install.log.syslog 公共的 图片 音乐
[root@localhost ~]# tar xf mysql-5.5.22.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mysql-5.5.22/
【cmake配置,编译及安装】
【-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 主程序安装目录】
【-DDEFAULT_CHARSET=utf8 默认字符集为 utf8】
【-DDEFAULT_COLLATION=utf8_general_ci 默认的字符集校对规则】
【-DWITH_EXTRA_CHARSETS=all 安装所有字符集 】
【-DSYSCONFDIR=/etc 配置文件存放目录】
[root@localhost mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install
2.3 安装后调整优化
[root@localhost mysql-5.5.22]# cd
[root@localhost ~]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[root@localhost ~]# . /etc/profile
[root@localhost ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
【创建修改my.cny配置文件】
[root@localhost ~]# cat /usr/src/mysql-5.5.22/support-files/my-medium.cnf > /etc/my.cnf
[root@localhost ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
【添加系统服务】
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
2.4 初始化数据库
[root@localhost ~]# useradd -M -s /sbin/nologin mysql
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/ 【修改mysql安装目录的属主属组】
【执行mysql_install_db脚本初始化数据库】
【--basedir=/usr/local/mysql/ 指定安装目录(产品目录)】
【 --datadir=/usr/local/mysql/data/ 指定数据目录】
【--user=mysql 指定用户身份】
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
2.5 启动Mysql服务,并查看运行状态
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL... [确定]
[root@localhost ~]# netstat -anpt |grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 36126/mysqld
2.6 创建root用户密码
【设置数据库用户名名密码】
[root@localhost ~]# mysqladmin -uroot password "123123";history -c
【连接并登录到mysql操作环境】
[root@localhost ~]# mysql -uroot -p
Enter password: 123123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> bye
-> Ctrl-C -- exit! 【ctrl+c或者quit或者exit】
Aborted
三、安装PHP服务
【PHP 超文本预处理器,是一种通用开源脚本语言,语法吸收了c语言、java、perl的特点,主要用于web开发领域】
3.1 安装PHP服务
[root@localhost ~]# rpm -q gd libxml2-devel libjpeg-devel libpng-devel
package gd is not installed
package libxml2-devel is not installed
package libjpeg-devel is not installed
package libpng-devel is not installed
[root@localhost ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@localhost ~]# rpm -q gd libxml2-devel libjpeg-devel libpng-devel
gd-2.0.35-11.el6.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
package libjpeg-devel is not installed
libpng-devel-1.2.49-1.el6_2.x86_64
3.2 编译安装 PHP
[root@localhost ~]# ls 【拉此包进来】
anaconda-ks.cfg install.log.syslog php-5.3.28.tar.gz
ansible libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm 公共的
cc.sh libyaml-0.1.3-4.el6_6.x86_64.rpm 模板
cmake-2.8.6.tar.gz mysql-5.5.22.tar.gz 视频
install.log nginx-1.6.0.tar.gz
[root@localhost ~]# tar xf php-5.3.28.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/php-5.3.28/
[root@localhost ~]# cd /usr/src/php-5.3.28/
[root@localhost php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
[root@localhost php-5.3.28]# cd
3.3 安装后优化调整
【创建软连接】
[root@localhost ~]# cp -p /usr/src/php-5.3.28/php.ini-development /usr/local/php5/php.ini
[root@localhost ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@localhost ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
[root@localhost ~]# ll /usr/local/bin/
总用量 34356
-rwxr-xr-x. 1 root root 8240514 4月 24 05:22 ccmake
-rwxr-xr-x. 1 root root 8124602 4月 24 05:22 cmake
-rwxr-xr-x. 1 root root 8710940 4月 24 05:22 cpack
-rwxr-xr-x. 1 root root 10099608 4月 24 05:22 ctest
lrwxrwxrwx. 1 root root 24 4月 24 09:19 pear -> /usr/local/php5/bin/pear
lrwxrwxrwx. 1 root root 27 4月 24 09:19 peardev -> /usr/local/php5/bin/peardev
lrwxrwxrwx. 1 root root 24 4月 24 09:19 pecl -> /usr/local/php5/bin/pecl
lrwxrwxrwx. 1 root root 24 4月 24 09:19 phar -> /usr/local/php5/bin/phar
lrwxrwxrwx. 1 root root 29 4月 24 09:19 phar.phar -> /usr/local/php5/bin/phar.phar
lrwxrwxrwx. 1 root root 23 4月 24 09:19 php -> /usr/local/php5/bin/php
lrwxrwxrwx. 1 root root 30 4月 24 09:19 php-config -> /usr/local/php5/bin/php-config
lrwxrwxrwx. 1 root root 26 4月 24 09:19 phpize -> /usr/local/php5/bin/phpize
[root@localhost ~]# ll /usr/local/sbin/
总用量 0
lrwxrwxrwx. 1 root root 27 4月 23 22:12 nginx -> /usr/local/nginx/sbin/nginx
lrwxrwxrwx. 1 root root 28 4月 24 09:20 php-fpm -> /usr/local/php5/sbin/php-fpm
3.4 安装ZendGuardLoader (PHP的优化模块)
[root@localhost ~]# ls 【拉此包进来】
anaconda-ks.cfg
ansible
cc.sh
cmake-2.8.6.tar.gz
install.log
install.log.syslog
libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm
libyaml-0.1.3-4.el6_6.x86_64.rpm
mysql-5.5.22.tar.gz
nginx-1.6.0.tar.gz
php-5.3.28.tar.gz
ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
[root@localhost ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
[root@localhost ~]# cp /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php5/lib/php/
【echo服务是一种非常有用的用于调试和检测的工具。该协议接收到什么原样发回,TCP端口7检测有无消息】【ZendGuardLoader.so这个是外挂,起加速的作用】
[root@localhost ~]# echo -e echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini
[root@localhost ~]# tail -2 /usr/local/php5/php.ini
3.5 启用php-fpm进程
【php-fpm是从php5.3.3之后新加入的管理器,在更改php配置文件后不需要重启,且由于加入守护进程,所以及时被杀死之后也能快速重启】
[root@localhost ~]# cd /usr/local/php5/etc/
[root@localhost etc]# cp -p php-fpm.conf.default php-fpm.conf 【去掉后缀就会生效】
[root@localhost etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid 【确认pid文件位置】去掉分号
140 user = nginx 【程序用户】
141 group = nginx【程序组】
217 pm.max_children = 50【子进程的最大数】
222 pm.start_servers = 20【启动时开启的进程数】
227 pm.min_spare_servers = 5【最少进程空闲数】
232 pm.max_spare_servers = 35【最大空闲进程数】
[root@localhost etc]# php-fpm
[root@localhost etc]# netstat -anpt |grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 98089/php-fpm
3.6 修改/etc/init.d/ngin服务脚本
[root@localhost ~]# cp /etc/init.d/nginx{,.bak1}
[root@localhost etc]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig:2345 99 20
#description:Nginx Server Control Scripts shell
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0(start|stop|restart|reload|)"
exit 1
esac
exit 0
保存退出
【因编辑的文件里没有以下俩文件,所有需要创建】
[root@localhost ~]# touch /usr/local/php5/var/run/php-fpm.pid
[root@localhost ~]# touch /usr/local/nginx/logs/nginx.pid
[root@localhost ~]# chkconfig --del nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# /etc/init.d/nginx stop
[root@localhost ~]# /etc/init.d/nginx start
[root@localhost ~]# netstat -anpt |egrep "nginx|php-fpm"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 99225/nginx
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 99229/php-fpm
3.7 配置Nginx支持PHP解析
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.benet.cn;
charset utf-8;
access_log logs/benet.access.log main;
location / {
root /benet;
index index.html index.htm index.php; 【不添加此会报错403】
#auth_basic "secret";
#auth_basic_user_file /usr/local/nginx/passwd.db;
#deny 192.168.168.134;
allow 192.168.168.0/24;
deny all;
}
location ~ \.php$ {
root /benet; 【这儿路径是网页访问位置】
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
保存退出
[root@localhost ~]# nginx -t 【检查语法】
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /etc/init.d/nginx restart
3.8 PHP页面访问测试
【因为之前配置文件里的路径是/benet/所以在下面的路径必须是/benet/,而不是www.benet.cn】
[root@localhost ~]# vim /benet/test.php
<?php
$link=mysql_connect('localhost','root','123123');
if($link) echo "<h1>hao li long shi quan shi jie zui shuai de nan ren </h1>";
mysql_close();
?>
保存退出,以上全部手写
在wind7的网页访问成功(wend7 的hosts文件里是ip 和域名)
四、在LNMP平台,部署SKYUC应用
4.1 解压SKYUC,部署程序代码
[root@localhost ~]# rpm -q unzip
unzip-6.0-1.el6.x86_64
[root@localhost ~]# ls 【拉此包进来】
nginx-1.6.0.tar.gz
php-5.3.28.tar.gz
SKYUC.v3.4.2.SOURCE.zip
【unzip为.zip压缩文件的解压缩程序】
[root@localhost ~]# unzip SKYUC.v3.4.2.SOURCE.zip
[root@localhost ~]# cd SKYUC.v3.4.2.SOURCE
[root@localhost SKYUC.v3.4.2.SOURCE]# ls
Change Log.txt Readme.txt -??+??+?.txt URLRewrite.txt wwwroot
[root@localhost SKYUC.v3.4.2.SOURCE]# cp -rp wwwroot/ /benet/skyuc
[root@localhost SKYUC.v3.4.2.SOURCE]# cd /benet/skyuc/
[root@localhost skyuc]# chown -R nginx:nginx admincp/ data/ templates/ upload/
4.2 创建数据库
[root@localhost skyuc]# mysql -uroot -p123123; history -c
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database skyucdb; 【创建数据库】
Query OK, 1 row affected (0.11 sec)
【创建数据库账号里的用户和密码,】
mysql> grant all on skyucdb.* to runskyuc@localhost identified by 'admin123';
Query OK, 0 rows affected (0.13 sec)
mysql> quit
Bye
4.3 安装Wed应用
在wind7输入www.benet.cn/skyuc/install
下一步
用户名runskyuc密码admin123数据库类型Mysql 【用户和密码是之前创建的】
其中的电子邮件改为123456@qq.com 否则会创建失败
此时会显示首页和后台
进入后台密码123123,管理名haolilong
提示删除install文件
处于安全考虑,可以把install文件改名,权限改为只有超户可以查看
或者把install文件删除,强烈建议删除
[root@localhost ~]# cd /benet/skyuc/
[root@localhost skyuc]# ls
admincp article.php image.php message.php rss.php uc_client
affiche.php category.php includes netbar.php search.php upload
ajax.php clientscript index.php player.php show.php user.php
api data install pm.php show_script.php
archive global.php languages respond.php subject.php
article_cat.php htaccess.txt list.php robots.txt templates
[root@localhost skyuc]# mv install/ install.bak/
[root@localhost skyuc]# chmod 600 install.bak/
[root@localhost skyuc]# cd ../
[root@localhost benet]# ll skyuc/
drw-------. 9 root root 4096 5月 23 2014 install.bak
五、phpwind论坛安装
[root@www ~]# cd /usr/local/nginx/conf/
[root@www conf]# ls
fastcgi.conf mime.types scgi_params
fastcgi.conf.default mime.types.default scgi_params.default
fastcgi_params nginx.conf uwsgi_params
fastcgi_params.default nginx.conf.bak uwsgi_params.default
koi-utf nginx.conf.bak1 win-utf
koi-win nginx.conf.default
[root@www conf]# cp nginx.conf nginx.conf.bak2
root@www conf]# vi nginx.conf
user nginx nginx;
2 worker_processes 1;
3 error_log logs/error.log info;
4 pid logs/nginx.pid;
5
6 events {
7 use epoll;
8 worker_connections 1024;
9 }
10
11 http {
12 include mime.types;
13 default_type application/octet-stream;
14
15 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
16 '$status $body_bytes_sent "$http_referer" '
17 '"$http_user_agent" "$http_x_forwarded_for"';
18
19 access_log logs/access.log main;
20 sendfile on;
21 keepalive_timeout 65;
22 #gzip on;
23
24 server {
25 listen 8080;
26 server_name www.kgc.cn;
27 charset utf-8;
28 access_log logs/kgc.access.log main;
29 location / {
30 root /kgc;
31 index index.html index.htm;
32 #auth_basic "secret";
33 #auth_basic_user_file /usr/local/nginx/passwd.db;
34 #deny 192.168.168.134;
35 #allow 192.168.168.0/24;
36 #deny all;
37 }
38 error_page 500 502 503 504 /50x.html;
39 location = /50x.html {
40 root html;
41 }
42 }
43 server {
44 listen 80;
45 server_name www.benet.cn;
46 charset utf-8;
47 access_log logs/benet.access.log main;
48 location / {
49 root /benet;
50 index index.php index.html index.htm ;
51 #auth_basic "secret";
52 #auth_basic_user_file /usr/local/nginx/passwd.db;
53 #deny 192.168.168.134;
54 #allow 192.168.168.0/24;
55 #deny all;
56 }
57 location ~ \.php$ {
58 root /benet;
59 fastcgi_pass 127.0.0.1:9000;
60 fastcgi_index index.php;
61 include fastcgi.conf;
62 }
63 error_page 500 502 503 504 /50x.html;
64 location = /50x.html {
65 root html;
66 }
67 }
68 server {
69 listen 80;
70 server_name www.new.cn;
71 charset utf-8;
72 access_log logs/new.access.log main;
73 location / {
74 root /new;
75 index index.php index.html index.htm ;
76 #auth_basic "secret";
77 #auth_basic_user_file /usr/local/nginx/passwd.db;
78 #deny 192.168.168.134;
79 #allow 192.168.168.0/24;
80 #deny all;
81 }
82 location ~ \.php$ {
83 root /new;
84 fastcgi_pass 127.0.0.1:9000;
85 fastcgi_index index.php;
86 include fastcgi.conf;
87 }
88 error_page 500 502 503 504 /50x.html;
89 location = /50x.html {
90 root html;
91 }
92 }
93 }
保存退出,添加以上红色部分
[root@www conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@www conf]# service nginx restart
[root@www conf]# cat /benet/test.php
<?php
$link=mysql_connect('localhost','root','123123');
if($link) echo "<h1>hao li long shi quan shi jie zui shuai de nan ren </h1>";
mysql_close();
?>
[root@www conf]# mkdir /new
[root@www conf]# cat /benet/test.php > /new/new.php
[root@www conf]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.168.131 www.benet.cn www.new.cn
[root@www conf]# vim /etc/hosts
[root@www conf]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
补充:
1、直接在虚拟机的/etc/hosts文件里加入ip和域名也可实现访问网页,就不需要再修改本机的wind7 里的hosts文件了
2、网页后台路径/skyuc/admincp/index.php
http://192.168.168.131/skyuc/admincp/index.php
首页,http://192.168.168.131/skyuc/index.php
3、给网站里上传影视,地址生成方法:在/benet/skyuc/下创建libai目录,然后给libai目录里传视频,图片,音乐都可,然后在文件里改名,用wpd查看路径,粘贴到网页ip后,复制路径粘贴到视频地址栏http://192.168.168.131//skyuc/libai/a.mp4,地址里不用/benet/
4、不同域名端口不可一样,会冲突
5、即便不加ip也可用本地ip访问网页
上传,添加地址,如下
有时个别浏览器不支持,需要换其他浏览器测试
6、在网页测试时出现warning :....... warning.....提示没有资源,
把测试文件重新检查
实验补充:
1、出现chkconfig不支持服务,是chkconfig的运行级别不够
2、firefox开启火狐网页
3、启动php-fpm报错9000,killall php-fpm杀死进程重启就好了
4、[root@localhost ~]# nginx -t
nginx: [emerg] directive "location" has no opening "{" in /usr/local/nginx/conf/nginx.conf:58
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
出现这个报错,是 { 前面缺空格
5、最后访问www.benet.cn报错,只因配置文件里缺一个index.php,nginx找不到路径就会报错
6、因xshell不识别汉字。所以需要拉文件前把文件名改为数字。
7、show database 显示数据库 ; firefox火狐网页浏览器显示
8、进网页报403错误的原因:防火墙未关,搜索页找不到文件