您的位置:首页 > 其它

编译安装LNMP环境,搭建wordpress博客

2013-07-24 00:06 656 查看
2013年6月27日―编译安装LNMP环境,搭建wordpress博客安装目录:1.系统环境:.........................................22.安装前系统设置:...................................23.安装gcc编译器及相关工具和依赖库......................2 3.1安装pcre库....................................33.2安装PHP所需的支持库................................3 3.2.1安装freeType................................3 3.2.2安装jpeg....................................3 3.3.3安装fontconfig.............................3 3.3.4安装libpng..................................4 3.3.5安装zlib....................................4 3.3.6安装ncurses.................................4 3.3.7安装libmcrypt...............................4 3.3.8安装libxml..................................4 3.3.9安装libiconv.................................5 3.3.10安装gd库..................................54.安装nginx...........................................5 测试nginx的web是否可用...........................55.安装mysql数据库.....................................56.安装php.............................................7 6.1配置php-fp.....................................87.整合nginx和php.......................................9 7.1测试php.......................................12 7.2测试mysql.....................................12操作步骤:系统环境:1.看下主机名、内核版本以及系统版本的信息
[root@tyk ~]# uname -a
Linux tyk 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@tyk ~]# lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.8 (Final)
Release:        5.8
Codename:       Final
2.安装前提环境,配置网络yum源
[root@tyk ~]# cd /etc/yum.repos.d/
[root@tyk yum.repos.d]# /bin/mv CentOS-Base.repo CentOS-Base.repo.ori
[root@tyk yum.repos.d]# wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo [root@tyk yum.repos.d]# /bin/mv CentOS-Base-sohu.repo CentOS-Base.repo
做服务器的时间同步
[root@tyk ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1
注意:最好关闭iptables防火墙和selinux不然后边有可能出现问题。##升级一下yum源[root@tyk ~]# yum update -y yum安装gcc编译器及相关工具和依赖库:
[root@tyk ~]# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
编译安装pcre库
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正规表达式。Pcre的作用主要是使nginx支持HTTP rewrite模块。
创建一个指定放置压缩包的目录
[root@tyk ~]# mkdir -p /taokey/tools
[root@tyk ~]# cd /taokey/tools/
[root@tyk tools]# unzip pcre-8.33.zip
[root@tyk tools]# cd pcre-8.33
[root@tyk pcre-8.33]# ./configure
[root@tyk pcre-8.33]# make && make install
安装PHP所需的支持库:
编译安装FreeType
FreeType库是一个完全免费(开源)的、高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件。
[root@tyk tools]# tar -jxvf freetype-2.4.12.tar.bz2
[root@tyk tools]# cd freetype-2.4.12
[root@tyk freetype-2.4.12]# ./configure --prefix=/usr/local/freetype
[root@tyk freetype-2.4.12]# make && make install
编译安装jpegJpeg是一个基本的图像压缩方式
[root@tyk tools]# tar -zxvf jpegsrc.v7.tar.gz
[root@tyk tools]# cd jpeg-7/
[root@tyk jpeg-7]# mkdir /usr/local/jpeg
[root@tyk jpeg-7]# mkdir /usr/local/jpeg/bin
[root@tyk jpeg-7]# mkdir /usr/local/jpeg/lib
[root@tyk jpeg-7]# mkdir /usr/local/jpeg/include
[root@tyk jpeg-7]# mkdir /usr/local/jpeg/man
[root@tyk jpeg-7]# mkdir /usr/local/jpeg/man/man1
[root@tyk jpeg-7]# ./configure --prefix=/usr/local/jpeg --with-freetype=/usr/local/freetype --enable-shared --enable-static
[root@tyk jpeg-7]# make && make install
安装fontconfig
fontconfig是提供系统范围内字体设置,定制和允许应用程序访问的函数库,Fontconfig负责字体的安装确认和匹配。
[root@tyk tools]# tar -zxvf fontconfig-2.4.2.tar.gz
[root@tyk tools]# cd fontconfig-2.4.2
[root@tyk fontconfig-2.4.2]# ./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config  --with-expat-lib=/usr/lib64
[root@tyk fontconfig-2.4.2]#make && make install
注意:在这里要是64位系统,就必须加上参数” --with-expat-lib=/usr/lib64 ”安装libpng:
ibpng软件包包含 libpng 库.这些库被其他程式用于读写png文件
[root@tyk tools]# tar -jxf libpng-1.4.3.tar.bz2
[root@tyk tools]# cd libpng-1.4.3
[root@tyk libpng-1.4.3]# ./configure --prefix=/usr/local/libpng --enable-static --enable-shared
[root@tyk libpng-1.4.3]# make && make install
安装zlib:
zlib能使用一个gzip数据头,zlib数据头或者不使用数据头压缩数据。
[root@tyk tools]# tar -zxvf zlib-1.2.3.tar.gz
[root@tyk tools]# cd zlib-1.2.3
[root@tyk zlib-1.2.3]# ./configure --prefix=/usr/local/zlib
[root@tyk zlib-1.2.3]# make && make install
安装ncurses:
NCURSES不仅仅只是封装了底层的终端功能,而且提供了一个相当稳固的工作框架(Framework)用 以产生漂亮的界面。它包含了一些创建窗口的函数。
[root@tyk tools]# tar -zxf ncurses-5.6.tar.gz
[root@tyk tools]# cd ncurses-5.6
[root@tyk ncurses-5.6]# ./configure --prefix=/usr/local/ncurses
[root@tyk ncurses-5.6]# make && make install
安装libmcrypt
libmcrypt是加密算法扩展库。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法。
[root@tyk tools]# tar -zxvf libmcrypt-2.5.7.tar.gz
[root@tyk libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt --enable-shared --enable-static --enable-dynamic-loading
[root@tyk libmcrypt-2.5.7]# make && make install
安装libxml
libxml是一个用来解析XML文档的函数库。它用C语言写成, 并且能为多种语言所调用,例如C语言,C++,XSH。C#,Python,Kylix/Delphi,Ruby,和PHP等。Perl中也可以使用XML::LibXML模块。libXML 代码可移植性非常好,因为它基于标准的ANSI C库, 并采用MIT许可证。
[root@tyk tools]# tar -zxvf libxml2-2.7.8.tar.gz
[root@tyk tools]# cd libxml2-2.7.8
[root@tyk libxml2-2.7.8]# ./configure --prefix=/usr/local/libxml2 --enable-shared --enable-static
[root@tyk libxml2-2.7.8]# make && make install
安装libiconv
对文本进行编码间的转换,用它来处理中文各种编码之间的转换。
[root@tyk tools]# tar -zxvf libiconv-1.14.tar.gz
[root@tyk tools]# cd libiconv-1.14
[root@tyk libiconv-1.14]# ./configure --prefix=/usr/local/libiconv-1.14
[root@tyk libiconv-1.14]# make && make install
安装gd库
[root@tyk tools]# tar -zxvf gd-2.0.33.tar.gz
[root@tyk tools]# cd gd-2.0.33
[root@tyk gd-2.0.33]# ./configure --prefix=/usr/local/gd --with-zlib=/usr/local/zlib --with-png=/usr/local/libpng --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/fontconfig
[root@tyk gd-2.0.33]# make && make install
4.安装nginx
[root@tyk tools]# useradd -s /sbin/nologin -M nginx
[root@tyk tools]# groupadd ngnix
[root@tyk tools]# tar -zxvf nginx-1.3.1.tar.gz
[root@tyk tools]# cd nginx-1.3.1
[root@tyk nginx-1.3.1]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.3.1 --with-http_stub_status_module --with-http_ssl_module --with-pcre=/taokey/tools/pcre-8.33
[root@tyk nginx-1.3.1]# make && make install
[root@tyk nginx-1.3.1]# ln -s /usr/local/nginx-1.3.1 /usr/local/nginx
[root@tyk nginx-1.3.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.3.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.3.1/conf/nginx.conf test is successful
[root@tyk nginx-1.3.1]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      15988/nginx
[root@tyk nginx-1.3.1]# ps -ef | grep nginx
root     15988     1  0 23:13 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx    15989 15988  0 23:13 ?        00:00:00 nginx: worker process
root     15995 26971  0 23:14 pts/1    00:00:00 grep nginx
5.安装mysql数据库
首先创建mysql用户和组
[root@tyk tools]# groupadd mysql
[root@tyk tools]# useradd -s /sbin/nologin -g mysql -M mysql
编译安装mysql数据库
[root@tyk tools]# tar -zxvf mysql-5.1.65.tar.gz
[root@tyk tools]# cd mysql-5.1.65
删除configure目录下的第52297行$RM "$cfgfile",不然会报错。
[root@tyk mysql-5.1.65]# ./configure --prefix=/application/mysql5.1.65 --with-unix-socket-path=/application/mysql5.1.65/tmp/mysql.sock --localstatedir=/application/mysql5.1.65/data --enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --enable-assembler --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase --with-plugin-PLUGIN --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
[root@tyk mysql-5.1.65]# make && make install
需要拷贝一个mysql的主配置文件,这个是必须拷贝的,我这里复制了一个small
[root@tyk mysql-5.1.65]# cp support-files/my-small.cnf /etc/my.cnf
[root@tyk mysql-5.1.65]# ln -s /application/mysql5.1.65 /application/mysql
[root@tyk mysql-5.1.65]# mkdir -p /application/mysql/data
[root@tyk mysql-5.1.65]# /application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
[root@tyk mysql-5.1.65]# cp support-files/mysql.server /etc/init.d/mysqld
[root@tyk mysql-5.1.65]# chmod 700 /etc/init.d/mysqld
[root@tyk mysql-5.1.65]# chown -R root.mysql /application/mysql/bin/mysql
[root@tyk mysql-5.1.65]# echo "/application/mysql/lib/mysql" >> /etc/ld.so.conf
[root@tyk mysql-5.1.65]# ldconfig
[root@tyk mysql-5.1.65]# /application/mysql/bin/mysqld_safe --user=mysql &
[root@tyk mysql-5.1.65]# netstat -anpt | grep mysqld
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      26725/mysqld
[root@tyk mysql-5.1.65]# chmod +x /etc/init.d/mysqld
[root@tyk mysql-5.1.65]# chkconfig --add mysqld
[root@tyk mysql-5.1.65]# chkconfig mysqld on
[root@tyk mysql-5.1.65]# export PATH=$PATH:/application/mysql/bin
[root@tyk mysql-5.1.65]# echo "PATH=$PATH:/application/mysql/bin" >>/etc/profile
[root@tyk mysql-5.1.65]# source /etc/profile
[root@tyk mysql-5.1.65]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.65 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> exit
Bye
6.安装php环境
[root@tyk tools]# tar -jxvf php-5.4.6.tar.bz2
[root@tyk php-5.4.6]# ./configure  --prefix=/usr/local/php5.4.6  --with-mysql=/application/mysql  --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-iconv=/usr/local/libiconv-1.14 --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir=/usr/local/libxml2 --enable-gd-native-ttf --enable-zip --enable-fastcgi --enable-fpm
[root@tyk php-5.4.6]# make && make install
在make编译时,出现报错:
In file included from /usr/local/src/php-5.4.6/ext/gd/gd.c:103:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_putc’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:51: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_putbuf’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:58: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_stream_ctxfree’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:67: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:68: 错误:‘struct gdIOCtx’没有名为‘data’的成员
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:69: 错误:‘struct gdIOCtx’没有名为‘data’的成员
In file included from /usr/local/src/php-5.4.6/ext/gd/gd.c:103:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c: 在函数‘_php_image_output_ctx’中:
/usr/local/src/php-5.4.6/ext/gd/gd_ctx.c:153: 错误:‘gdIOCtx’没有名为‘data’的成员
make: *** [ext/gd/gd.lo] 错误 1
解决方法:
修改gd安装目录下的include/gd_io.h文件。
[root@spp php-5.4.15]# vi /usr/local/gd/include/gd_io.h修改为文件中的结构体为:
typedef struct gdIOCtx
{
int (*getC) (struct gdIOCtx *);
int (*getBuf) (struct gdIOCtx *, void *, int);

void (*putC) (struct gdIOCtx *, int);
int (*putBuf) (struct gdIOCtx *, const void *, int);

int (*seek) (struct gdIOCtx *, const int);

long (*tell) (struct gdIOCtx *);

void (*gd_free) (struct gdIOCtx *);
void (*data);
}
gdIOCtx;
其中红色部分为添加的修改,其他不变。
5.1 配置php-fpm:
[root@tyk php-5.4.6]# cd /usr/local/php5.4.6/etc/
[root@tyk etc]# cp php-fpm.conf.default php-fpm.conf
[root@tyk etc]# egrep -v ";|^$" php-fpm.conf
[global]
error_log = /var/log/php-fpm.log
log_level = notice
pid = /var/log/php/php-fpm.pid
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
[root@tyk etc]# mkdir /var/log/php
[27-Jun-2013 00:17:06] NOTICE: configuration file /usr/local/php5.4.6/etc/php-fpm.conf test is successful
[root@tyk etc]# ../sbin/php-fpm
[root@tyk etc]# ps -ef | grep php-fpm
root     19087     1  0 00:17 ?        00:00:00 php-fpm: master process (/usr/local/php5.4.6/etc/php-fpm.conf)
nginx    19088 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19089 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19090 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19091 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19092 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19093 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19094 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19095 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19096 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19097 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19098 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19099 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19100 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19101 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19102 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19103 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19104 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19105 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19106 19087  0 00:17 ?        00:00:00 php-fpm: pool www
nginx    19107 19087  0 00:17 ?        00:00:00 php-fpm: pool www
root     19109 26971  0 00:18 pts/1    00:00:00 grep php-fpm
[root@tyk local]# cat nginx/conf/nginx.conf
user  nginx;
worker_processes  8;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
error_log /app/logs/nginx_error.log crit;
#pid        logs/nginx.pid;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
log_format  commonlog  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log  logs/access.log  main;
sendfile        on;
#tcp_nopush     on;
#keepalive_timeout  0;
keepalive_timeout  65;
#gzip  on;
server {
listen       80;
server_name  www.beyond.com;
#charset koi8-r;
#access_log  logs/host.access.log  main;
location / {
root   /data/www/www;
index  index.php index.html index.htm;
}
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
location ~ .*\.(php|php5)?$ {
root /data/www/www;
fastcgi_pass    127.0.0.1:9000;
fastcgi_index   index.php;
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
include         fastcgi_params;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;
#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;
#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;
#    ssl_session_timeout  5m;
#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers   on;
#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
}
[root@tyk local]# nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.3.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.3.1/conf/nginx.conf test is successful
[root@tyk local]# nginx/sbin/nginx -s reload
[root@tyk php-5.4.6]# grep short_open_tag /usr/local/php5.4.6/php.ini
; short_open_tag
short_open_tag = On
测试下php和数据库是否成功
[root@tyk www]# cat test.php
<?
phpinfo();
?>
[root@tyk www]# cat testdb.php
<?php
$link=mysql_connect('localhost','root','');
if ($link)
echo "successful";
else
echo "Faile";
mysql_close();
?>
[root@tyk nginx]# sbin/nginx -s reload
[root@tyk nginx]# sbin/nginx -s reload
此时页面会出现successful的字样,说明成功了。
下载wordpress,然后解压,在数据库上创建一个数据库,账号和密码,然后给用户赋予权限,就可以安装wordpress博客了。









试验到此结束,谢谢大家!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: