首先要准备一台RHEL6.5的虚拟机。
搭建LNMP服务要按照这个顺序来安装,不然就会安装失败。
1.第一步安装Nginx服务。
然后把LNMP压缩包拉倒linux系统里面,并且解压。
[root@localhost 桌面]# ls
lnmp+memcached.zip
[root@localhost 桌面]# unzip lnmp+memcached.zip
Archive: lnmp+memcached.zip
creating: lnmp+memcached/
inflating: lnmp+memcached/cmake-2.8.10.2.tar.gz
inflating: lnmp+memcached/fastcgi.docx
inflating: lnmp+memcached/libevent-2.0.21-stable.tar.gz
inflating: lnmp+memcached/libiconv-1.13.tar.gz
inflating: lnmp+memcached/libmcrypt-2.5.8.tar.gz
inflating: lnmp+memcached/mem.php
inflating: lnmp+memcached/memcache-2.2.5.tgz
inflating: lnmp+memcached/memcached-1.4.5.tar.gz
inflating: lnmp+memcached/mhash-0.9.9.9.tar.gz
inflating: lnmp+memcached/mysql-5.5.13.tar.gz
inflating: lnmp+memcached/nginx-1.2.0.tar.gz
inflating: lnmp+memcached/nginx.conf
inflating: lnmp+memcached/php-5.4.9.tar.gz
[root@localhost 桌面]# ls
lnmp+memcached lnmp+memcached.zip
[root@localhost 桌面]# cd lnmp+memcached
[root@localhost lnmp+memcached]# ls
cmake-2.8.10.2.tar.gz libiconv-1.13.tar.gz memcached-1.4.5.tar.gz mysql-5.5.13.tar.gz php-5.4.9.tar.gz
fastcgi.docx libmcrypt-2.5.8.tar.gz mem.php nginx-1.2.0.tar.gz
libevent-2.0.21-stable.tar.gz memcache-2.2.5.tgz mhash-0.9.9.9.tar.gz nginx.conf
安装源码Nginx :
查看RHEL6.5系统是否有80端口在运行。
安装编译的工具:
[root@localhost nginx-1.2.0]# yum -y install gcc gcc-c++ make
[root@localhost lnmp+memcached]# netstat -untlap | grep :80
停止http服务,并且加入开启动项,如果没有就不用管了。
[root@localhost lnmp+memcached]# service httpd stop ; chkconfig httpd off
新建用户(www)为Nginx服务使用。
[root@localhost lnmp+memcached]# useradd -s /sbin/nologin -M www
[root@localhost lnmp+memcached]# tail -1 /etc/passwd
www:x:500:500::/home/www:/sbin/nologin
现在开始编译安装Nginx服务
[root@localhost lnmp+memcached]# tar zxf nginx-1.2.0.tar.gz
[root@localhost lnmp+memcached]# cd nginx-1.2.0
[root@localhost nginx-1.2.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
安装相关的库文件:
[root@localhost nginx-1.2.0]# yum -y install pcre-devel
[root@localhost nginx-1.2.0]# yum -y install libsepol-devel
[root@localhost nginx-1.2.0]# yum -y install openssl-devel
[root@localhost nginx-1.2.0]# yum -y install zlib-devel
执行配置脚本:
[root@localhost nginx-1.2.0]# sh nginx-configure.sh
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
checking for gcc builtin atomic operations ... found
。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "/usr/local/nginx/client"
nginx http proxy temporary files: "/usr/local/nginx/proxy"
nginx http fastcgi temporary files: "/usr/local/nginx/fcgi"
nginx http uwsgi temporary files: "/usr/local/nginx/uwsgi"
nginx http scgi temporary files: "/usr/local/nginx/scgi"
编译:
[root@localhost nginx-1.2.0]# make
gcc -c -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/ngx_resolver.o \
src/core/ngx_resolver.c
make[1]: Leaving directory `/root/桌面/lnmp+memcached/nginx-1.2.0'
make -f objs/Makefile manpage
make[1]: Entering directory `/root/桌面/lnmp+memcached/nginx-1.2.0'
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/桌面/lnmp+memcached/nginx-1.2.0'
编译安装:
[root@localhost nginx-1.2.0]# make install
现在启动Nginx服务:(安装目录:/usr/local/nginx/)
[root@localhost nginx-1.2.0]# /usr/local/nginx/sbin/nginx
查看监听端口:
[root@localhost nginx-1.2.0]# netstat -untlap | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28398/nginx
接下来我们测试Nginx是否可以正常使用:
[root@localhost nginx-1.2.0]# yum -y install elinks
[root@localhost nginx-1.2.0]# elinks --dump http://localhost
Welcome to nginx!
2.第二步安装MySQL
首先要检查3306端口是否在运行,如果在运行就给杀掉,然后确保mysql-server和mysql软件包是否安装,如果安装就要删除但是要注意了,要忽略依赖关系删除建议使用(RPM)来删除。并且要查看系统是否是mysql这个用户如果没有就要创建,有的话就不要创建。
[root@localhost ~]# netstat -utnalp | grep :3306
[root@localhost ~]# rpm -qa | grep -i mysql
[root@localhost ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@localhost ~]# grep mysql /etc/passwd
[root@localhost ~]# useradd -s /sbin/nologin -M mysql
[root@localhost ~]# grep mysql /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
安装配置工具cmake
[root@localhost cmake-2.8.10.2]# pwd
/root/桌面/lnmp+memcached/cmake-2.8.10.2
[root@localhost lnmp+memcached]# tar zxf cmake-2.8.10.2.tar.gz
[root@localhost lnmp+memcached]# cd cmake-2.8.10.2
[root@localhost cmake-2.8.10.2]# ls
bootstrap CMakeLists.txt CTestConfigNaNake doxygen.config Tests
ChangeLog.manual CMakeLogo.gif CTestCustomNaNake.in Example Utilities
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
[root@localhost cmake-2.8.10.2]# ./bootstrap --prefix=/usr/local/cmake
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /root/桌面/lnmp+memcached/cmake-2.8.10.2
---------------------------------------------
CMake has bootstrapped. Now run gmake.
[root@localhost cmake-2.8.10.2]# make
Scanning dependencies of target cmIML_test
[ 1%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test.c.o
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Linking C executable valgrind
[100%] Built target pseudo_valgrind
[root@localhost cmake-2.8.10.2]# make install
[root@localhost cmake-2.8.10.2]# /usr/local/cmake/bin/cmake --version
cmake version 2.8.10.2
使用camke配置安装源码mysql
[root@localhost lnmp+memcached]# tar zxf mysql-5.5.13.tar.gz
安装库:
[root@localhost mysql-5.5.13]# yum -y install ncurses-devel
[root@localhost mysql-5.5.13]# sh mysql-configure.sh
-- Check size of pthread_t
-- Check size of pthread_t - done
-- Performing Test HAVE_PEERCRED
-- Performing Test HAVE_PEERCRED - Success
Warning: Bison executable not found in PATH
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
MYSQL_USER
-- Build files have been written to: /root/桌面/lnmp+memcached/mysql-5.5.13
[root@localhost mysql-5.5.13]# make
Scanning dependencies of target INFO_BIN
[ 0%] Built target INFO_BIN
Scanning dependencies of target INFO_SRC
[100%] Built target mysqltest_embedded
Scanning dependencies of target my_safe_process
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process
[root@localhost mysql-5.5.13]# make install
初始化授权库:
[root@localhost mysql-5.5.13]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
[root@localhost mysql]# ls -l /usr/local/mysql/data/mysql/
总用量 984
-rw-rw---- 1 mysql mysql 8820 2月 17 23:04 columns_priv.frm
-rw-rw---- 1 mysql mysql 0 2月 17 23:04 columns_priv.MYD
-rw-rw---- 1 mysql mysql 4096 2月 17 23:04 columns_priv.MYI
。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
创建mysql数据库的主配置文件:
[root@localhost ~]# cd /root/桌面/lnmp+memcached/mysql-5.5.13/support-files/
[root@localhost support-files]# cp my-medium.cnf /etc/my.cnf
启动数据库服务:
[root@localhost support-files]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 53972
150217 23:10:31 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@localhost support-files]# netstat -aunlpt | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54210/mysqld
使用数据库管理员从数据库服务器本机登录(没密码):
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.13-log Source distribution
Copyright (c) 2000, 2010, 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> quit
Bye
设置数据库管理员从本机登录的密码为(123):
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -hlocalhost -uroot password "123"
[root@localhost ~]# netstat -aunlpt | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54210/mysqld
[root@localhost ~]# pkill -9 mysqld
[1]+ 已杀死 /usr/local/mysql/bin/mysqld_safe --user=mysql (wd: ~/桌面/lnmp+memcached/mysql-5.5.13/support-files)
(wd now: ~)
[root@localhost ~]# netstat -aunlpt | grep :3306
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 54284
150217 23:19:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@localhost ~]# netstat -aunlpt | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54524/mysqld
把mysql命令所在的路径添加到系统环境变量PATH里:
[root@localhost ~]# export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# vim /etc/bashrc
export PATH=/usr/local/mysql/bin:$PATH 《------加到这个文件的最后一行
给源码mysql服务编写启动脚本:
[root@localhost ~]# cd /root/桌面/lnmp+memcached/mysql-5.5.13/support-files
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqldd
[root@localhost support-files]# chmod +x /etc/init.d/mysqldd
[root@localhost support-files]# chkconfig --add mysqldd
[root@localhost support-files]# chkconfig --list mysqldd
mysqldd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@localhost support-files]# netstat -untlap | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54524/mysqld
[root@localhost support-files]# pkill -9 mysqld
[1]+ 已杀死 /usr/local/mysql/bin/mysqld_safe --user=mysql (wd: ~)
(wd now: ~/桌面/lnmp+memcached/mysql-5.5.13/support-files)
3.安装源码PHP
1、安装php的扩展功能包(哈稀函数库)
[root@localhost ~]# cd /root/桌面/lnmp+memcached
[root@localhost lnmp+memcached]# ls mhash-0.9.9.9.tar.gz
mhash-0.9.9.9.tar.gz
[root@localhost lnmp+memcached]# tar zxf mhash-0.9.9.9.tar.gz
[root@localhost lnmp+memcached]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make
[root@localhost mhash-0.9.9.9]# make install
2、libiconv-1.13.tar.gz 处理中文各种编码之间的转换
[root@localhost lnmp+memcached]# tar zxf libiconv-1.13.tar.gz
[root@localhost lnmp+memcached]# cd libiconv-1.13
[root@localhost libiconv-1.13]# ./configure
[root@localhost libiconv-1.13]# make
[root@localhost libiconv-1.13]# make install
3、libmcrypt-2.5.8.tar.gz 提供加密功能的库文件
[root@localhost lnmp+memcached]# tar zxf libmcrypt-2.5.8.tar.gz
[root@localhost lnmp+memcached]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install
[root@localhost libmcrypt-2.5.8]# cd libltdl
[root@localhost libltdl]# pwd
/root/桌面/lnmp+memcached/libmcrypt-2.5.8/libltdl
[root@localhost libltdl]# ls
acinclude.m4 config-h.in configure.in ltdl.c Makefile.am README
aclocal.m4 configure COPYING.LIB ltdl.h Makefile.in
[root@localhost libltdl]# ldconfig -v
[root@localhost libltdl]# ./configure --with-gmetad --enable-gexec --enable-ltdl-install
[root@localhost libltdl]# make
[root@localhost libltdl]# make install
减压PHP
[root@localhost lnmp+memcached]# tar zxf php-5.4.9.tar.gz
[root@localhost lnmp+memcached]# cd php-5.4.9
在这个文件里添加两行内容(/usr/local/mysql/include,/usr/local/mysql/lib)
[root@localhost php-5.4.9]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/include
/usr/local/mysql/lib
[root@localhost php-5.4.9]# ldconfig -v
[root@localhost php-5.4.9]# ln -sv /usr/local/lib/libmcrypt.* /usr/lib/
"/usr/lib/libmcrypt.la" -> "/usr/local/lib/libmcrypt.la"
"/usr/lib/libmcrypt.so" -> "/usr/local/lib/libmcrypt.so"
"/usr/lib/libmcrypt.so.4" -> "/usr/local/lib/libmcrypt.so.4"
"/usr/lib/libmcrypt.so.4.4.8" -> "/usr/local/lib/libmcrypt.so.4.4.8"
[root@localhost php-5.4.9]# ln -sv /usr/local/lib/libmhash.* /usr/lib/
"/usr/lib/libmhash.a" -> "/usr/local/lib/libmhash.a"
"/usr/lib/libmhash.la" -> "/usr/local/lib/libmhash.la"
"/usr/lib/libmhash.so" -> "/usr/local/lib/libmhash.so"
"/usr/lib/libmhash.so.2" -> "/usr/local/lib/libmhash.so.2"
"/usr/lib/libmhash.so.2.0.1" -> "/usr/local/lib/libmhash.so.2.0.1"
[root@localhost php-5.4.9]# ldconfig -v
安装库文件
[root@localhost php-5.4.9]# yum -y install libxml2-devel
[root@localhost php-5.4.9]# yum -y install libcurl-devel
[root@localhost lnmp+memcached]# yum -y install libjpeg-turbo-devel
[root@localhost lnmp+memcached]# yum -y install libpng-devel
[root@localhost lnmp+memcached]# yum -y install freetype-devel
[root@localhost lnmp+memcached]# yum -y install ldapjdk
[root@localhost lnmp+memcached]# yum -y install openldap-devel
[root@localhost ~]# cp -frp /usr/lib64/libldap* /usr/lib/
[root@localhost php-5.4.9]# sh php-configure.sh
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands
[root@localhost php-5.4.9]# make ZEND_EXTRA_LIBS='-liconv'
[root@localhost php-5.4.9]# make install
[root@localhost php-5.4.9]# cd /usr/local/php
[root@localhost php]# pwd
/usr/local/php
创建php程序的主配置文件 php.ini
[root@localhost ~]# cd /root/桌面/lnmp+memcached/php-5.4.9
[root@localhost php-5.4.9]# cp php.ini-development /usr/local/php/etc/php.ini
让nginx能够解释php页面
1、创建fast-cgi服务的主配置文件
[root@localhost php-5.4.9]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
2、启动fast-cgi服务(作用管理php程序)
[root@localhost etc]# cd /root/桌面/lnmp+memcached/php-5.4.9/sapi/fpm/
[root@localhost fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# chmod +x /etc/init.d/php-fpm
[root@localhost fpm]# chkconfig --add php-fpm
[root@localhost fpm]# chkconfig --list php-fpm
php-fpm 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@localhost fpm]# /etc/init.d/php-fpm status
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload}
[root@localhost fpm]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@localhost fpm]# netstat -untlap | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1613/php-fpm
3 让nginx把自己接收到的访问php文件的请求给本机的9000端口
[root@localhost fpm]# vim /usr/local/nginx/conf/nginx.conf
#把这个文件里的(65--71行的注释去掉)然后保存退出
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi_params;
71 }
[root@localhost fpm]# vim /usr/local/nginx/conf/fastcgi_params (添加如下一行)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
现在检测语法是否正确:
[root@localhost fpm]# /usr/local/nginx/sbin/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
停止Nginx服务然后在启动:
[root@localhost fpm]# /usr/local/nginx/sbin/nginx -s stop
[root@localhost fpm]# /usr/local/nginx/sbin/nginx
[root@localhost fpm]# netstat -untlap | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1613/php-fpm
测试
1 通过nginx服务器访问php代码文件:
[root@localhost fpm]# vim /usr/local/nginx/html/test.php
<?php
echo "hello world!!!";
?>
在浏览器里访问 http://nginx-web-ip/test.php
php.ini 文件的作用:
[root@localhost fpm]# vim /usr/local/nginx/html/test2.php
<%
phpinfo();
%>
[root@localhost fpm]# vim /usr/local/php/etc/php.ini
asp_tags = On
[root@localhost fpm]# /etc/init.d/php-fpm stop
[root@localhost fpm]# /etc/init.d/php-fpm start
测试 php 能否连接mysql数据库:
[root@localhost fpm]# /etc/init.d/mysqldd start
Starting MySQL SUCCESS!
[root@localhost fpm]# netstat -untnalp | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2237/mysqld
[root@localhost fpm]# vim /usr/local/nginx/html/linkdb.php
<?php
$linkdb=mysql_connect("localhost","root","123");
if($linkdb){
echo "link db ok";
}else{
echo "link db no";
}
?>
现在在网页里测试一下:
本文出自 “Dragon” 博客,转载请与作者联系!