LNMP搭建
搭建LNMP服务要按照这个顺序来安装,不然就会安装失败。1.第一步安装Nginx服务。然后把LNMP压缩包拉倒linux系统里面,并且解压。
# lslnmp+memcached.zip# unzip lnmp+memcached.zip Archive:lnmp+memcached.zip creating: lnmp+memcached/inflating: lnmp+memcached/cmake-2.8.10.2.tar.gzinflating: lnmp+memcached/fastcgi.docxinflating: lnmp+memcached/libevent-2.0.21-stable.tar.gzinflating: lnmp+memcached/libiconv-1.13.tar.gzinflating: lnmp+memcached/libmcrypt-2.5.8.tar.gzinflating: lnmp+memcached/mem.phpinflating: lnmp+memcached/memcache-2.2.5.tgzinflating: lnmp+memcached/memcached-1.4.5.tar.gzinflating: lnmp+memcached/mhash-0.9.9.9.tar.gzinflating: lnmp+memcached/mysql-5.5.13.tar.gzinflating: lnmp+memcached/nginx-1.2.0.tar.gzinflating: lnmp+memcached/nginx.confinflating: lnmp+memcached/php-5.4.9.tar.gz# lslnmp+memcachedlnmp+memcached.zip
# cd lnmp+memcached# lscmake-2.8.10.2.tar.gz libiconv-1.13.tar.gz memcached-1.4.5.tar.gzmysql-5.5.13.tar.gzphp-5.4.9.tar.gzfastcgi.docx libmcrypt-2.5.8.tar.gzmem.php nginx-1.2.0.tar.gzlibevent-2.0.21-stable.tar.gzmemcache-2.2.5.tgz mhash-0.9.9.9.tar.gz nginx.conf
安装源码Nginx:
查看RHEL6.5系统是否有80端口在运行。安装编译的工具:
# yum-yinstallgccgcc-c++make
# netstat -untlap | grep :80停止http服务,并且加入开启动项,如果没有就不用管了。# service httpd stop;chkconfighttpd off
新建用户(www)为Nginx服务使用。# useradd-s/sbin/nologin-Mwww# tail-1/etc/passwdwww:x:500:500::/home/www:/sbin/nologin
现在开始编译安装Nginx服务
# tarzxfnginx-1.2.0.tar.gz # cdnginx-1.2.0# lsautoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc
安装相关的库文件:
# yum-yinstallpcre-devel# yum-yinstalllibsepol-devel# yum-yinstallopenssl-devel# yum-yinstallzlib-devel
执行配置脚本:
# shnginx-configure.shchecking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... foundchecking 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"
编译:#makegcc -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.cmake: Leaving directory `/root/桌面/lnmp+memcached/nginx-1.2.0'make -f objs/Makefile manpagemake: 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.8make: Leaving directory `/root/桌面/lnmp+memcached/nginx-1.2.0'
编译安装:#make install
现在启动Nginx服务:(安装目录:/usr/local/nginx/)# /usr/local/nginx/sbin/nginx 查看监听端口:# netstat -untlap | grep:80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28398/nginx
接下来我们测试Nginx是否可以正常使用:# yum-y installelinks#elinks --dump http://localhost Welcome to nginx!
2.第二步安装MySQL
首先要检查3306端口是否在运行,如果在运行就给杀掉,然后确保mysql-server和mysql软件包是否安装,如果安装就要删除但是要注意了,要忽略依赖关系删除建议使用(RPM)来删除。并且要查看系统是否是mysql这个用户如果没有就要创建,有的话就不要创建。# netstat -utnalp| grep :3306# rpm-qa | grep-imysql# mv /etc/my.cnf/etc/my.cnf.bak# grep mysql /etc/passwd# useradd -s/sbin/nologin-M mysql# grep mysql /etc/passwdmysql:x:501:501::/home/mysql:/sbin/nologin
安装配置工具cmake
# pwd/root/桌面/lnmp+memcached/cmake-2.8.10.2# tar zxfcmake-2.8.10.2.tar.gz # cdcmake-2.8.10.2# lsbootstrap CMakeLists.txt CTestConfigNaNake doxygen.configTestsChangeLog.manual CMakeLogo.gif CTestCustomNaNake.inExample Utilities。。。。。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#./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.
# makeScanning dependencies of target cmIML_test Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test.c.o。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。Linking C executable valgrind Built target pseudo_valgrind# makeinstall# /usr/local/cmake/bin/cmake--versioncmake version 2.8.10.2
使用camke配置安装源码mysql
# tar zxf mysql-5.5.13.tar.gz
安装库:# yum-y installncurses-devel# shmysql-configure.sh-- Check size of pthread_t-- Check size of pthread_t - done-- Performing Test HAVE_PEERCRED-- Performing Test HAVE_PEERCRED - SuccessWarning: Bison executable not found in PATH-- Configuring done-- Generating doneCMake 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
# makeScanning dependencies of target INFO_BIN Built target INFO_BINScanning dependencies of target INFO_SRC Built target mysqltest_embeddedScanning dependencies of target my_safe_process Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.oLinking CXX executable my_safe_process Built target my_safe_process# make install
初始化授权库:
# cd/usr/local/mysql/# lsbin datainclude libmysql-testscriptssql-benchCOPYINGdocsINSTALL-BINARYmanREADME share support-files# ./scripts/mysql_install_db --user=mysqlInstalling MySQL system tables...OKFilling help tables...OK
To start mysqld at boot time you have to copysupport-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 testdatabases and anonymous user created by default.This isstrongly 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.plcd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
# 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数据库的主配置文件:
# cd/root/桌面/lnmp+memcached/mysql-5.5.13/support-files/# cpmy-medium.cnf /etc/my.cnf
启动数据库服务:
# /usr/local/mysql/bin/mysqld_safe --user=mysql & 53972150217 23:10:31 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
# netstat -aunlpt| grep:3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54210/mysqld
使用数据库管理员从数据库服务器本机登录(没密码):
# /usr/local/mysql/bin/mysql -uroot -pEnter password: Welcome to the MySQL monitor.Commands end with ; or \g.Your MySQL connection id is 1Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quitBye
设置数据库管理员从本机登录的密码为(123):
# /usr/local/mysql/bin/mysqladmin -hlocalhost -uroot password "123"
# netstat -aunlpt| grep:3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54210/mysqld # pkill -9 mysqld+已杀死 /usr/local/mysql/bin/mysqld_safe --user=mysql(wd: ~/桌面/lnmp+memcached/mysql-5.5.13/support-files)(wd now: ~)# netstat -aunlpt| grep:3306# /usr/local/mysql/bin/mysqld_safe --user=mysql & 54284150217 23:19:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data# netstat -aunlpt| grep:3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54524/mysqld
把mysql命令所在的路径添加到系统环境变量PATH里:
# exportPATH=/usr/local/mysql/bin:$PATH# vim /etc/bashrcexportPATH=/usr/local/mysql/bin:$PATH《------加到这个文件的最后一行
给源码mysql服务编写启动脚本:
# cd/root/桌面/lnmp+memcached/mysql-5.5.13/support-files# cp mysql.server /etc/init.d/mysqldd# chmod +x /etc/init.d/mysqldd# chkconfig --add mysqldd# chkconfig --list mysqlddmysqldd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭# netstat -untlap| grep :3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 54524/mysqld # pkill-9mysqld+已杀死 /usr/local/mysql/bin/mysqld_safe --user=mysql(wd: ~)(wd now: ~/桌面/lnmp+memcached/mysql-5.5.13/support-files)
3.安装源码PHP1、安装php的扩展功能包(哈稀函数库)# cd /root/桌面/lnmp+memcached# lsmhash-0.9.9.9.tar.gz mhash-0.9.9.9.tar.gz# tarzxf mhash-0.9.9.9.tar.gz # cd mhash-0.9.9.9# ./configure# make# makeinstall
2、libiconv-1.13.tar.gz处理中文各种编码之间的转换# tarzxflibiconv-1.13.tar.gz# cd libiconv-1.13# ./configure# make# makeinstall
3、libmcrypt-2.5.8.tar.gz 提供加密功能的库文件# tarzxflibmcrypt-2.5.8.tar.gz # cdlibmcrypt-2.5.8# ./configure# make# makeinstall
# cd libltdl# pwd/root/桌面/lnmp+memcached/libmcrypt-2.5.8/libltdl# lsacinclude.m4config-h.inconfigure.inltdl.cMakefile.amREADMEaclocal.m4 configure COPYING.LIB ltdl.hMakefile.in
# ldconfig-v# ./configure --with-gmetad --enable-gexec --enable-ltdl-install#make#makeinstall
减压PHP# tarzxf php-5.4.9.tar.gz # cdphp-5.4.9
在这个文件里添加两行内容(/usr/local/mysql/include,/usr/local/mysql/lib)# vim /etc/ld.so.confinclude ld.so.conf.d/*.conf/usr/local/mysql/include/usr/local/mysql/lib# ldconfig-v # 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"# 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"
# ldconfig-v 安装库文件# yum-yinstalllibxml2-devel# yum-yinstalllibcurl-devel# yum-yinstalllibjpeg-turbo-devel # yum-yinstalllibpng-devel# yum-yinstallfreetype-devel# yum-yinstallldapjdk# yum-yinstallopenldap-devel# cp-frp/usr/lib64/libldap* /usr/lib/# shphp-configure.sh Thank you for using PHP.
config.status: creating php5.specconfig.status: creating main/build-defs.hconfig.status: creating scripts/phpizeconfig.status: creating scripts/man1/phpize.1config.status: creating scripts/php-configconfig.status: creating scripts/man1/php-config.1config.status: creating sapi/cli/php.1config.status: creating sapi/fpm/php-fpm.confconfig.status: creating sapi/fpm/init.d.php-fpmconfig.status: creating sapi/fpm/php-fpm.serviceconfig.status: creating sapi/fpm/php-fpm.8config.status: creating sapi/fpm/status.htmlconfig.status: creating main/php_config.hconfig.status: executing default commands
# make ZEND_EXTRA_LIBS='-liconv'# make install# cd/usr/local/php# pwd/usr/local/php
创建php程序的主配置文件 php.ini# cd /root/桌面/lnmp+memcached/php-5.4.9# cp php.ini-development /usr/local/php/etc/php.ini
让nginx能够解释php页面1、创建fast-cgi服务的主配置文件# cd /usr/local/php/etc/# cpphp-fpm.conf.default php-fpm.conf
2、启动fast-cgi服务(作用管理php程序)# cd /root/桌面/lnmp+memcached/php-5.4.9/sapi/fpm/# cpinit.d.php-fpm/etc/init.d/php-fpm# chmod +x /etc/init.d/php-fpm# chkconfig--add php-fpm# chkconfig --list php-fpmphp-fpm 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭# /etc/init.d/php-fpmstatusUsage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload}# /etc/init.d/php-fpm startStarting php-fpmdone# netstat-untlap |grep :9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1613/php-fpm
3让nginx把自己接收到的访问php文件的请求给本机的9000端口# 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_indexindex.php; 69 fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name; 70 include fastcgi_params; 71 }
# vim/usr/local/nginx/conf/fastcgi_params (添加如下一行)fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
现在检测语法是否正确:# /usr/local/nginx/sbin/nginx-t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
停止Nginx服务然后在启动:# /usr/local/nginx/sbin/nginx-sstop# /usr/local/nginx/sbin/nginx # netstat-untlap|grep :9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1613/php-fpm
测试1通过nginx服务器访问php代码文件:# vim/usr/local/nginx/html/test.php<?php echo"helloworld!!!";?>
在浏览器里访问 http://nginx-web-ip/test.php php.ini文件的作用:
# vim/usr/local/nginx/html/test2.php<%phpinfo();%>
#vim/usr/local/php/etc/php.iniasp_tags = On
# /etc/init.d/php-fpmstop# /etc/init.d/php-fpmstart
测试 php 能否连接mysql数据库:# /etc/init.d/mysqlddstartStarting MySQL SUCCESS! # netstat-untnalp | grep :3306tcp 000.0.0.0:3306 0.0.0.0:* LISTEN 2237/mysqld
#vim/usr/local/nginx/html/linkdb.php<?php$linkdb=mysql_connect("localhost","root","123");if($linkdb){ echo "linkdbok";
}else{ echo"linkdbno";}?>
现在在网页里测试一下:
页:
[1]