编译安装LNMP及报错解决

 

 本文来自杜文的投稿

系统: rhel6.5

配置实验环境

 

关掉NetworkManager,并停止掉开机自启动

 

[[email protected] ~]# service NetworkManagerstop

[[email protected] ~]# chkconfig -- listNetworkManager

[[email protected] ~]# chkconfig NetworkManageroff

 

关掉iptables

 

[[email protected] ~]# iptables -F     //清空防火墙

[[email protected] ~]# service iptables save

 

[[email protected] ~]# chkconfig iptables off

 

关掉selinux

 

[[email protected] ~]# getenforce

Enforcing

[[email protected] ~]# setenforce

usage: setenforce [ Enforcing | Permissive | 1 | 0 ]

[[email protected] ~]# setenforce 0  临时关seLinux

[[email protected] ~]#

[[email protected] ~]# vim /etc/selinux/config    //从配置文件永久关闭selinux

 

打开这个档案以后你可以看到如下的内容,把黄色显示的改成disabled就好

# This file controls the state of SELinuxon the system.

# SELINUX= can take one of these threevalues:

#    enforcing - SELinux security policy is enforced.

#    permissive - SELinux prints warnings instead of enforcing.

#    disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these twovalues:

#    targeted - Targeted processes are protected,

#    mls - Multi Level Security protection.

SELINUXTYPE=targeted

 

 

配置本地yum源

 

[[email protected] ~]# mount /dev/sr0 /mnt/     将光驱挂载到mnt上

mount: block device /dev/sr0 iswrite-protected, mounting read-only

[[email protected] ~]# df -h | tail -1    查看最后一样,是否挂载

/dev/sr0        3.6G 3.6G     0 100% /mnt

[[email protected] ~]# echo "/dev/sr0/mnt/ iso9660 defaults 0 0" >> /etc/fstab   设置开机自动挂载

[[email protected] ~]# rm -rf/etc/yum.repos.d/*

[[email protected] ~]# cat >/etc/yum.repos.d/rhel6.repo <<EOF    //配置yum

> [rhel6-source]

> name=rhel6-source

> baseurl=file:///mnt

> enabled=1

> gpgcheck=0

> EOF

 

检测依赖环境,包括gcc,gcc-c++,autoconf,automake,zlib ,zlib-devel, openssl ,openssl-devel ,pcre-devel,

 

[[email protected] ~]# yum install -y gcc  gcc-c++ autoconf automake   //安装好所需要的环境

 

为了方便从xshell上传软件包,这里安装一个命令  rz

[[email protected] ~]#  rpm/mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm -ih

warning:/mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm: Header V3 RSA/SHA256Signature, key ID fd431d51: NOKEY

###########################################[100%]

###########################################[100%]

[[email protected] ~]#

//上传软件包,黄色显示

 

[[email protected] ~]# ls

   nginx-1.6.0.tar.gz 

mysql-5.5.30.tar.gz  php-5.4.14.tar.bz2 

 

正式开始安装MySQL了

解压到指定目录/usr/local/src/

[[email protected] ~]#

[[email protected] ~]# tar -zxfmysql-5.5.30.tar.gz -C /usr/local/src/   //-C表示指定目录

建一个mysql用户,这里把这个用户显示出来

[[email protected] ~]# tail -1 /etc/passwd

mysql:x:500:500::/home/mysql:/sbin/nologin

 

//安装cmake

[[email protected] ~]# yum install -y cmake

建立mysql的目录

[[email protected] /]# mkdir /server

[[email protected] ~]#  cd /usr/local/src/mysql-5.5.30/

 

[[email protected] mysql-5.5.30]# cmake-DCMAKE_INSTALL_PREFIX=/server/mysql-5.5 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSERS=all-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINT=1 -DENABLED_LOCAL_INFILE=1-DMYSQL_DATADIR=/server/mysql/data -DMYSQL_USER=mysql

 

 

//报错信息如下;

 0?wx_fmt=png

//这个错误就是ncurses这个依赖没有装

       0?wx_fmt=png

[[email protected] ~]# tar zxf ncurses.tar.gz

 

//其实我想说这个 真难装

//还是yum好使,这里我用的yum

[[email protected] ncurses-5.9]# yum -y installncurses-devel

 

//本来我是装了那个ncurses依赖就直接装了的,还是报错,就只好把这个CMakeCache.txt找出来干掉了

[[email protected] mysql-5.5.30]# find / -nameCMakeCache.txt

/usr/local/src/mysql-5.5.30/CMakeCache.txt

[[email protected] mysql-5.5.30]# rm -rf   /usr/local/src/mysql-5.5.30/CMakeCache.txt

//OK,现在重新cmake

 

0?wx_fmt=png

 

//呐开心不,没有报错了呢!!!

 

现在make &&make install,过程就不写了

配置运行环境

[[email protected] mysql-5.5.30]# cd /server/

[[email protected] server]# ls

mysql-5.5

[[email protected] server]# chown -Rmysql:mysql /server/mysql-5.5/

 

复制mysql配置文件

[[email protected] server]# cd /etc/

[[email protected] etc]# ll my.cnf

-rw-r--r--. 1 root root 251 8月   9 2013 my.cnf

[[email protected] etc]# mv ./my.cnf ./my.cnf.back

[[email protected] etc]# cp/usr/local/src/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnf

 

这个步骤是加入开机启动项

[[email protected] init.d]# cp/usr/local/src/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld5.5

[[email protected] init.d]# chmod +x./mysqld5.5

[[email protected] init.d]# pwd

/etc/init.d

[[email protected] init.d]#

//这里要改下,大概在第70行

[[email protected] init.d]# vim/etc/init.d/mysqld5.5

[[email protected] init.d]# head -71  /etc/init.d/mysqld5.5 |tail -7

then

 basedir=/server/mysql-5.5

 bindir=/server/mysql-5.5/bin

  iftest -z "$datadir"

 then

   datadir=/server/mysql-5.5/data

  fi

[[email protected] init.d]#

 //加入开机启动项

[[email protected] init.d]# chkconfig mysqld5.5  on  设置开机启动

[[email protected] init.d]# chkconfig --listmysqld5.5

mysqld5.5          0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭

 

 

初始化mysql

[[email protected] init.d]#  cd /usr/local/src/mysql-5.5.30/scripts/

[[email protected] scripts]# chmod +xmysql_install_db

[[email protected] scripts]# ./mysql_install_db--defaults-file=/etc/my.cnf --basedir=/server/mysql-5.5--datadir=/server/mysql-5.5/data --user=mysql

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have tocopy

support-files/mysql.server to the right placefor your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

To do so, start the server, then issue thefollowing commands:

 

/server/mysql-5.5/bin/mysqladmin -u rootpassword 'new-password'

/server/mysql-5.5/bin/mysqladmin -u root -hduwensql password 'new-password'

 

Alternatively you can run:

/server/mysql-5.5/bin/mysql_secure_installation

 

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd /server/mysql-5.5 ;/server/mysql-5.5/bin/mysqld_safe &

 

You can test the MySQL daemon withmysql-test-run.pl

cd /server/mysql-5.5/mysql-test ; perlmysql-test-run.pl

 

Please report any problems with the/server/mysql-5.5/scripts/mysqlbug script!

 

[[email protected] scripts]#

开启mysql

[[email protected] scripts]#/etc/init.d/mysqld5.5 start

Starting MySQL...                                          [确定]

[[email protected] scripts]#

测试MySQL

 

//我这里最开始在家目录输入mysql显示没有命令,是因为没有加入环境变量的缘故啦,这里就不写出来了,直接到绝对路径去测试

[email protected] mysql-test]# cd /server

[[email protected] server]# ls

mysql-5.5

[[email protected] server]# cd mysql-5.5/

[[email protected] mysql-5.5]# ls

bin COPYING  data  docs include  INSTALL-BINARY  lib man  mysql-test  README scripts  share  sql-bench support-files

[[email protected] mysql-5.5]# cd bin/

0?wx_fmt=png

ctrl + c 退出

给他加个环境变量吧

[[email protected] ~]# echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[[email protected] ~]#PATH="$PATH":/server/mysql-5.5/bin/

[[email protected] ~]# mysqladmin -urootpassword '123456'

[[email protected] ~]# mysql -u root -p123456

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.5.30-log Sourcedistribution

 

Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql>

 

ctrl + c 退出

MySQL安装完了

 

 

 

来安装nginx吧

解压

[[email protected] ~]# tar -zxfnginx-1.6.0.tar.gz

编译

[[email protected] nginx-1.6.0]# ./configure--prefix=server/nginx-1.6.0 --user=nginx --group=nginx --with-http_dav_module --with-http_stub_status_module--with-http_addition_module --with-http_sub_module --with-http_flv_module--with-http_mp4_module

结果太多就不写了,放一个图

0?wx_fmt=png

make&&make install

[[email protected] nginx-1.6.0]# make -j 4&& make install

开始配置

[[email protected] nginx-1.2.8]# pwd

/server/nginx-1.2.8

[[email protected] nginx-1.2.8]# vimconf/nginx.conf

第二行加

user nginx nginx;

然后加下面的内容,黄色的括号前面有空格

location ~ \.php${

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /server/nginx-1.2.8/html$fastcgi_script_name;

include fastcgi_params;

}

大概的位置如下图

0?wx_fmt=png

启动服务

[[email protected] nginx-1.2.8]#/server/nginx-1.2.8/sbin/nginx

把服务加入开机启动

[[email protected] nginx-1.2.8]# echo'/server/nginx-1.2.8/sbin/nginx & ' >> /etc/rc.local

[[email protected] nginx-1.2.8]#

 

测试下

 0?wx_fmt=png

 

测试配置文件和重新加载配置文件

[[email protected] nginx-1.2.8]#/server/nginx-1.2.8/sbin/nginx -t

nginx: the configuration file/server/nginx-1.2.8/conf/nginx.conf syntax is ok

nginx: configuration file/server/nginx-1.2.8/conf/nginx.conf test is successful

[[email protected] nginx-1.2.8]#/server/nginx-1.2.8/sbin/nginx -s reload

 

 

来安装PHP

给PHP添加扩展模块:libmcrypt-2.5.8.tar.gz

1、 让 PHP 编译支持这个功能

2、 生成扩展模块

3、--with-mcrypt=/usr/local/

安装libmcrypt库

[[email protected] ~]# tar -zxflibmcrypt-2.5.8.tar.gz

[[email protected] ~]# cd libmcrypt-2.5.8

[[email protected] libmcrypt-2.5.8]#./configure --prefix=/usr/local/

[[email protected] libmcrypt-2.5.8]# echo $?

0

[[email protected] libmcrypt-2.5.8]# make -j 4&& make install

[[email protected] libmcrypt-2.5.8]# yum -yinstall php-pear

解压以及编译

[[email protected] ~]# tar jxfphp-5.4.14.tar.bz2 -C /usr/local/src/

[[email protected] ~]# cd/usr/local/src/php-5.4.14/

[[email protected] php-5.4.14]# ./configure--prefix=/server/php-5.4-nginx --with-config-file-path=/server/php-5.4-nginx--with-mysql=/server-5.5/ --with-mysqli=/server/mysql-5.5/bin/mysql_config--with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

 

报错1

Configuring extensions

checking size of long... (cached) 8

checking size of int... (cached) 4

checking for int32_t... yes

checking for uint32_t... yes

checking for sys/types.h... (cached) yes

checking for inttypes.h... (cached) yes

checking for stdint.h... (cached) yes

checking for string.h... (cached) yes

checking for stdlib.h... (cached) yes

checking for strtoll... yes

checking for atoll... yes

checking for strftime... (cached) yes

checking which regex library to use... php

checking whether to enable LIBXML support... yes

checking libxml2 install dir... /usr

checking for xml2-config path...

configure: error: xml2-config not found. Please checkyour libxml2 installation.

[[email protected] php-5.4.14]#

安装依赖环境

[[email protected] php-5.4.14]# yum -y installlibxml2*

 

重新

./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli=/server/mysql-5.5/bin/mysql_config --with-iconv-dir--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错2

checking if we should use cURL for urlstreams... yes

checking for cURL in default path... notfound

configure: error: Please reinstall thelibcurl distribution -

   easy.h should be in <curl-dir>/include/curl/

[[email protected] php-5.4.14]#

安装依赖环境:

[[email protected] php-5.4.14]#  yum -y install curl-devel

重新

./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli=/server/mysql-5.5/bin/mysql_config --with-iconv-dir--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错3

 

checking whether to enable JIS-mappedJapanese font support in GD... no

checking for fabsf... yes

checking for floorf... yes

configure: error: jpeglib.h not found

安装依赖:

[[email protected] php-5.4.14]# yum -y installlibjpeg*

 

再次

./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli=/server/mysql-5.5/bin/mysql_config --with-iconv-dir--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr--enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem--enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex--enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash--enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错4:

checking for jpeg_read_header in -ljpeg...yes

If configure fails try--with-vpx-dir=<DIR>

configure: error: png.h not found.

[[email protected] php-5.4.14]#

安装依赖环境:

[[email protected] php-5.4.14]# yum -y installlibpng*

 

再来./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli=/server/mysql-5.5/bin/mysql_config --with-iconv-dir--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错5:

configure: error: freetype.h not found.

安装一下环境依赖

[[email protected] php-5.4.14]# yum -y installfreetype*

再来./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli=/server/mysql-5.5/bin/mysql_config --with-iconv-dir--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错6:

checking for specified location of theMySQL UNIX socket... no

configure: error: Cannot find MySQL headerfiles under /server-5.5/.

Note that the MySQL client library is notbundled anymore!

 

这个应该是指定路径错误,改下

再来一次./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/ --with-mysqli=/server/mysql-5.5/bin/mysql_config--with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl--with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

报错7:

configure: error: wrong mysql libraryversion or lib not found. Check config.log for more information.

“=/server/mysql-5.5/bin/mysql_config”删掉试试

改好以后的执行:

./configure --prefix=/server/php-5.4-nginx--with-config-file-path=/server/php-5.4-nginx --with-mysql=/server/mysql-5.5/--with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization--with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring--with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip --enable-soap--with-mcrypt=/usr/local/

历经千辛万苦啊

 

0?wx_fmt=png

 

这里贴上一些参数的意思

 

--with-iconv-dir  #字符集转换需要的扩展模块

–without-iconv          关闭iconv函数,种字符集间的转换

–with-freetype-dir      打开对freetype字体库的支持

–with-jpeg-dir           打开对jpeg图片的支持

–with-png-dir              打开对png图片的支持

–with-libxml-dir           打开libxml2库的支持

–disable-rpath               关闭额外的运行库文件

–enable-bcmath        打开图片大小调整,用到zabbix监控的时候用到了这个模块

 

下面 是make  -j 4 && make install

 

[[email protected] php-5.4.14]# make -j 4&& make install

 

 

生成配置文件

[[email protected] ~]# cp/usr/local/src/php-5.4.14/php.ini-production /server/php-5.4-nginx/php.ini

生成php-fpm配置文件

[[email protected] ~]# cp/server/php-5.4-nginx/etc/php-fpm.conf.default/server/php-5.4-nginx/etc/php-fpm.conf

生成php-fpm启动脚本

[[email protected] ~]# cp /usr/local/src/php-5.4.14/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm

[[email protected] ~]# chmod +x/etc/init.d/php-fpm

 

[[email protected] ~]# /etc/init.d/php-fpmstart

Starting php-fpm  done

[[email protected] ~]# netstat -anptu | grep9000

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      76616/php-fpm      

[[email protected] ~]#

测试php

[[email protected] ~]# vim/server/nginx-1.2.8/html/a.php

[[email protected] ~]# cat/server/nginx-1.2.8/html/a.php

<?php

         phpinfo();

?>    

 

 

[[email protected] ~]#

 

0?wx_fmt=png

好了,到此已经安装完了,有没有感觉很麻烦,其实技术很是蛮简单的,难就难在有时间会有各种意想不到的错误,需要去排错。

 

本文来自小伙伴杜文的投稿,同时也欢迎大家踊跃投稿。