lnmp(nginx1.4.5+mysql5.5+php5.4)编译版搭建论坛

1.搭建一个简单web即dns服务器
10.10.54.61
[root@gyf  html]# vim /etc/named.conf


options {
        listen-on port 53 {any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     {any; };
        recursion yes;
    

zone "." IN {
        type hint;
        file "named.ca";
};
zone "ssr.com" IN {
        type master;
        file "named.ssr.com";
     

};
zone "54.10.10.in-addr.arpa" IN {
        type master;
        file "named.10.10.54";
       
[root@gyf  html]# /etc/init.d/named restart
                             

[root@gyf  named]# vim /var/named/named.ssr.com

$TTL 86400
@       IN      SOA     ssr.com. root (
                                2014010802
                                1H
                                2M
                                1W
                                1D
                                        );

@                        IN     NS                  ssr.com.
ssr.com.              IN     A                     10.10.54.61
@                        IN     MX      3           master.ssr.com   #邮箱服务器
master.ssr.com.   IN     A                      10.10.54.61
slaver                   IN     A                     10.10.54.64
svn                       IN     A                     10.10.54.64
ftp                        IN     CNAME           master.ssr.com.
www.ssr.com.      IN      CNAME            ssr.com
bbs.ssr.comIN      IN      CNAME            ssr.com
[root@gyf  named]# vim /var/named/named.10.10.54

$TTL 86400
@       IN      SOA     ssr.com. root (
                                2014010802
                                1H
                                2M
                                1W
                                1D
                                        );
@                IN     NS              ssr.com.
61              IN      PTR             ssr.com.
61              IN      PTR             master.ssr.com.
61              IN      PTR             ftp.ssr.com.
64              IN      PTR             slaver.ssr.com.
64              IN      PTR             svn.ssr.com.
61               IN     PTR              www.ssr.com.
61               IN     PTR              bbs.ssr.com.
//在本机上解析测试
[root@gyf  ~]# dig ssr.com @127.0.0.1
[root@gyf  ~]# dig -x 10.10.54.61 @127.0.0.1
在10.10.54.60下测试
vim /etc/resolv.conf
nameserver 10.10.54.61
shell> dig bbs.ssr.com
####################
源码编译nginx1.4.5
1.下载
[root@gyf  soft]#wget http://nginx.org/download/nginx-1.4.5.tar.gz
[root@gyf  soft]# tar xvf nginx-1.4.5.tar.gz
2.编译
[root@gyf  nginx-1.4.5]# ./configure --prefix=/usr/local/nginx --user=apache --group=apache --with-http_stub_status_module   --with-http_gzip_static_module --with-http_ssl_module
///
--with-http_stub_status_module     enable ngx_http_stub_status_module     ---支持监控
--with-http_gzip_static_module     enable ngx_http_gzip_static_module     ---支持压缩

3.安装
[root@gyf  nginx-1.4.5]# make && make install
4.启动
[root@gyf  conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] getpwnam("apache") failed
[root@gyf  conf]# useradd apache

[root@gyf  conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@gyf  conf]# netstat -ntlp|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1572/httpd          
[root@gyf  conf]# apachectl stop
[root@gyf  conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5.关闭:给父进程发送一个TERM信号,试图杀死它和它的子进程。
[root@s01 logs]# cat /usr/local/nginx/logs/nginx.pid | xargs kill -TERM

6.重启
[root@s01 logs]# cat /usr/local/nginx/logs/nginx.pid | xargs kill -HUP

HUP      重启
TERM,INT 快速中止
USR1    从新打开日志文件,用于日志切割
USR2    平滑升级可执行程序
QUIT     从容关闭
WINCH    从容关闭工做进程

//测试配置文件
[root@s01 html]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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

//nginx配置文件格式:

user  apache apache;
worker_processes  2;   ---cpu核-1
....

event{}
http{
....
upstream {}
server{}

}
############################
编译安装mysql-5.5.30.tar.gz
1.安装依赖文件
yum install -y cmake.x86_64

2.建立mysql用户
有:
[root@tech03 softs]# cat /etc/passwd|grep mysql
mysql:x:501:501::/home/mysql:/sbin/nologin
没有时:
[root@gyf  mysql-5.5.30]# groupadd mysql
[root@gyf  mysql-5.5.30]# useradd -g mysql mysql

3.编译参数cmake编译

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \......自动建立的权限是root
-DMYSQL_DATADIR=/data/dbdata \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=yes


加-D表示当前路径
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql:MySQL安装目录,推荐安装到此目录
-DWITH_INNOBASE_STORAGE_ENGINE=1:安装InnoDB存储引擎
-DWITH_MYISAM_STORAGE_ENGINE=1:安装MyISAM存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1:安装内存存储引擎
-DDEFAULT_CHARSET=utf8:默认编码设置成utf8
-DDEFAULT_COLLATION=utf8_general_ci:默然校验规则是utf8_general_ci
-DWITH_EXTRA_CHARSETS=all:支持其余全部的编码
-DMYSQL_TCP_PORT=3306:MySQL端口指定为3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock:指定SOCK文件









CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- MySQL 5.5.30
-- Packaging as: mysql-5.5.30-Linux-x86_64
-- Could NOT find Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
  Curses library not found.  Please install appropriate package,

清除缓存:rm CMakeCache.txt。。。。编译后生成的文件
solution:
[root@tech2 mysql-5.1.70]# yum install ncurses-devel.x86_64 -y
[root@tech2 mysql-5.1.70]# yum install bision.x86_64 -y
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
solution:
yum -y install gcc-c++.x86_64 compat-gcc-34.x86_64
rm CMakeCache.txt

make
make install


4
##.建立目录
mkdir -p /data/dbdata
chown mysql.mysql /usr/local/mysql -R
级联修改目录用户和用户组为mysql
chown mysql.mysql /data/dbdata -R



5.复制mysql配置文件my.cnf
---window配置文件my.ini


 cp /soft/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnf

6.复制启动脚本
 cp /soft/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

7.初始化数据库文件


[root@tech03 dbdata]# /usr/local/mysql/scripts/mysql_install_db --user=mysql

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

解决方式:
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/
启动数据库
[root@gyf  dbdata]# /etc/init.d/mysqld start
err:
Starting MySQL.. ERROR! The server quit without updating PID file (/data/dbdata/gyf.pid).


[root@learn  data]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.. ERROR! The server quit without updating PID file (/data/dbdata/learn.pid).
[root@learn  data]# netstat -ntulp
[root@learn  data]# kill -9 1243
[root@gyf  dbdata]# vim /etc/my.cnf

[mysqld]
datadir=/data/dbdata
#skip-locking
long_query_time=0.5
slow_query_log
lower_case_table_names=1

[mysql]
prompt = \\u@\\d \\R:\\m>
//在/etc/my.cnf配置文件添加:
[mysqld]
innodb_file_per_table=1
skip-name-resolve
long_query_time=0.5
slow_query_log
lower_case_table_names=1

[mysql]
prompt = \\u@\\d \\R:\\m>

8.修改用户登陆密码

/usr/local/mysql/bin/mysqladmin -u root password 'aaa12345'

#################################
编译 php-5.4.25.tar.gz
1.下载 php-5.4.25.tar.gz
[root@gyf  soft]#  wget http://cn2.php.net/distributions/php-5.4.25.tar.gz
2.下载安装libmcrypt php模块
[root@gyf  soft]#  wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
[root@gyf  soft]# tar xvf libmcrypt-2.5.8.tar.gz
[root@gyf  soft]# cd libmcrypt-2.5.7
[root@gyf  soft]# ./configure
[root@gyf  soft]# make
[root@gyf  php-5.4.25]# cd pear/
[root@gyf  pear]# cp /soft/go-pear.php install-pear-nozlib.phar
[root@gyf  php-5.4.25]#  make install
3.下载mhash php模块
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
[root@gyf  soft]# tar -jxvf mhash-0.9.9.9.tar.bz2
[root@gyf  soft]# ./configure
[root@gyf  soft]# make && make install
4.下载mcrypt php依赖模块
[root@gyf  soft]#wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
[root@gyf  soft]#tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make
错误:
configure: error: *** libmcrypt was not found  www.2cto.com  
为了的到mcrypt.so库文件,前后安装编译了mhash和libmcrypt,可是到最后编译mcrypt时报错:
最后发现是由于环境变量的问题,gcc编译的时候根据自身定义的变量寻找相关函数库等文件,
libmcrypt也是刚安装的,在变量中没有定义出来,因此手动添加:
[root@gyf  mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
再次编译便可。
[root@gyf  mcrypt-2.6.8]# make
[root@gyf  mcrypt-2.6.8]# make install
安装依赖:
yum –y install libxml2-devel.x86_64 libcurl-devel.x86_64 libpng-devel.x86_64 openldap-devel.x86_64
5.编译php
咱们使用nginx调用php的时候使用fpm的方式,在php 5.4中加入了对php-fpm的支持,因此就不须要打补丁了.安装PHP:
[root@gyf  soft]# cd php-5.4.25
[root@gyf  php-5.4.25]# vim INSTALL

1.  gunzip apache_xxx.tar.gz
2.  tar -xvf apache_xxx.tar
3.  gunzip php-xxx.tar.gz
4.  tar -xvf php-xxx.tar
5.  cd apache_xxx
6.  ./configure --prefix=/www --enable-module=so
7.  make
8.  make install
9.  cd ../php-xxx

nginx编译
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap
错误:configure: error: Cannot find ldap libraries in /usr/lib
cp -frp /usr/lib64/libldap* /usr/lib/

make
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方法:
[root@gyf  php-5.4.25]# find /  -name 'libmysqlclient.so.18'
/usr/local/mysql/lib/libmysqlclient.so.18
[root@gyf  php-5.4.25]# vim /etc/ld.so.conf
/usr/local/mysql/lib
[root@gyf  php-5.4.25]# ldconfig
从新编译
chmod: cannot access `ext/phar/phar.phar': No such file or directory
make: [ext/phar/phar.phar] Error 1 (ignored)
[root@gyf  php-5.4.25]# cd ext/phar/
[root@gyf  phar]# cp ./phar.php ./phar.phar
从新编译
[root@gyf  php-5.4.25]# cd pear/
[root@gyf  pear]# cp /soft/go-pear.php install-pear-nozlib.phar

make install
6.为php建立配置文件
[root@gyf  php-5.4.25]# cp php.ini-production /usr/local/php/php.ini
7.启动php-fpm
[root@gyf  php-5.4.25]# /usr/local/php/sbin/php-fpm
或者
[root@gyf  php-5.4.25]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@gyf  init.d]# chmod +x php-fpm
[root@gyf  init.d]# chkconfig --add php-fpm
[root@gyf  init.d]# /etc/init.d/php-fpm start

8.配置php-fpm
[root@gyf  php-5.4.25]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@gyf  php-5.4.25]# cd /usr/local/php/etc/php-fpm.conf
:25  pid = run/php-fpm.pid
:148 user = nginx
     group = nginx
:159 listen = 127.0.0.1:9000

9.修改nginx配置文件
user  nginx nginx;
    server {
        listen     80;
        server_name  bbs.ssr.com;
        charset utf-8;
       access_log  logs/bbs.access.log  main;
        root  /var/www/bbs;
        location / {
        index index.html index.php;
        }
        ssl                  off;
#        ssl_certificate  /usr/local/nginx/conf/.ssl/server.crt;
#        ssl_certificate_key  /usr/local/nginx/conf/.ssl/server.key;
        location ~ \.php$ {
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            include        fastcgi_params;
            include        fastcgi.conf;
}
10.测试
[root@gyf  conf]# /etc/init.d/nginx test
nginx: [emerg] getpwnam("nginx") failed in /usr/local/nginx/conf/nginx.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
nginx test is error!  
[root@gyf  conf]# useradd nginx

[root@gyf  conf]# /etc/init.d/nginx restart
11.建网站
[root@gyf  conf]# mkdir /var/www/bbs
[root@gyf  bbs]# unzip Discuz_X3.0_SC_UTF8.zip
[root@gyf  bbs]# ls
Discuz_X3.0_SC_UTF8.zip  index.html  php.php  readme  upload  utility
[root@gyf  www]# chown -R nginx.nginx bbs

12.测试网站
[root@gyf  bbs]# /etc/init.d/php-fpm restart
[root@gyf  bbs]# /etc/init.d/nginx restart
[root@gyf  bbs]# /etc/init.d/mysqld restart
在ubuntu10.10.54.60下输入
http://bbs.ssr.com/upload/
13.受权
root@(none) 21:11>grant all on *.* to root@10.10.54.60 identified by 'aaa12345';
root@(none) 21:12>flush privileges;




php

相关文章
相关标签/搜索