首页 > 代码库 > LNMP环境编译安装
LNMP环境编译安装
安装nginx
[root@lnmp src]# tar -xf nginx-1.6.2.tar.gz
[root@lnmp src]# ls
nginx-1.6.2 nginx-1.6.2.tar.gz
[root@lnmp nginx-1.6.2]#
[root@lnmp nginx-1.6.2]# useradd -s /sbin/nologin -M nginx
[root@lnmp nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx1.6.2 --with-http_stub_status_module --with-http_ssl_module
Make&&make install
[root@lnmp local]# ln -s /usr/local/nginx1.6.2/ /usr/local/nginx
[root@lnmp local]# ll nginx/
total 16
drwxr-xr-x 2 root root 4096 Dec 8 15:56 conf
drwxr-xr-x 2 root root 4096 Dec 8 15:56 html
drwxr-xr-x 2 root root 4096 Dec 8 15:56 logs
drwxr-xr-x 2 root root 4096 Dec 8 15:56 sbin
重启nginx
[root@lnmp local]# ./nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1.6.2/conf/nginx.conf test is successful
[root@lnmp local]# ./nginx/sbin/nginx 启动nginx
[root@lnmp local]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 4584 root 6u IPv4 15901 0t0 TCP *:http (LISTEN)
nginx 4585 nginx 6u IPv4 15901 0t0 TCP *:http (LISTEN)
访问测试
配置nginx
[root@lnmp conf]# grep html nginx.conf
root html; 默认站点
[root@lnmp conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Dec 8 15:56 fastcgi.conf 动态位置文件
-rw-r--r-- 1 root root 1034 Dec 8 15:56 fastcgi.conf.default
-rw-r--r-- 1 root root 964 Dec 8 15:56 fastcgi_params
-rw-r--r-- 1 root root 964 Dec 8 15:56 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Dec 8 15:56 koi-utf
-rw-r--r-- 1 root root 2223 Dec 8 15:56 koi-win
-rw-r--r-- 1 root root 3957 Dec 8 15:56 mime.types
-rw-r--r-- 1 root root 3957 Dec 8 15:56 mime.types.default
-rw-r--r-- 1 root root 2656 Dec 8 15:56 nginx.conf 静态配置文件
-rw-r--r-- 1 root root 2656 Dec 8 15:56 nginx.conf.default
配置虚拟主机
[root@lnmp conf]# mkdir ../html/{www,blog,bbs}
[root@lnmp conf]# for i in www blog bbs;do echo "http://$i.bier.org" >../html/$i/index.html;done
[root@lnmp conf]# for i in www blog bbs;do cat ../html/$i/index.html;done
http://www.bier.org
http://blog.bier.org
http://bbs.bier.org
打开配置文件
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.bier.org;
root html/www;
index index.html index.htm;
}
server {
listen 80;
server_name blog.bier.org;
root html/blog;
index index.html index.htm;
index index.html index.htm;
}
server {
listen 80;
server_name bbs.bier.org;
root html/bbs;
index index.html index.htm;
}
}
[root@lnmp nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1.6.2/conf/nginx.conf test is successful
[root@lnmp nginx]# ./sbin/nginx -s reload 加载配置文件
配置好hosts,浏览器测试访问
安装mysql
安装mysql(二进制包安装方式,直接解压,初始化数据库即可,无需编译)
[root@lnmp local]# useradd mysql -s /sbin/nologin –M
[root@lnmp local]#tar -xf mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@lnmp local]#mv mysql-5.5.32-linux2.6-x86_64 mysql
[root@lnmp local]# chown -R mysql.mysql ./mysql/data
拷贝启动脚本
[root@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lnmp mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@lnmp mysql]# chkconfig --add mysqld
[root@lnmp mysql]# chkconfig --list |grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@lnmp mysql]# chkconfig mysqld on
拷贝配置文件
[root@lnmp mysql]# cp support-files/my-small.cnf /etc/my.cnf
初始化数据库
[root@lnmp mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &
启动mysql
[root@lnmp mysql]# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!
[root@lnmp mysql]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 35035 mysql 10u IPv4 48207 0t0 TCP *:mysql (LISTEN)
连接数据库
[root@lnmp mysql]# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@lnmp mysql]# find /usr/local/ -type f -name "mysql"
/usr/local/mysql/bin/mysql
[root@lnmp mysql]# cp /usr/local/mysql/bin/mysql /usr/local/sbin/
[root@lnmp mysql]# mysql 输入mysql登录数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
安装php
Lnmp下的php
Apache==>libphp5.so
Nginx php ===> fcgi php-fpm port 9000
安装准备
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
字符集
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
加密的库
tar -xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
tar -xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
加密扩展库
tar -xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
再安装一个包,不然编译的时候会出错
yum install libxslt* -y
开始安装php
tar -xf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/usr/local/php5.3.27 \
--with-mysql=/usr/local/mysql \
--with-libxml-dir=/usr \
--with-zlib \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-iconv-dir=/usr/local/libiconv \
--enable-xml \
--with-curl \
--with-curlwrappers \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
要这样子处理,不然会报错
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
make
make install
ln -s /usr/local/php5.3.27/ /usr/local/php
拷贝php的配置文件
[root@lnmp php-5.3.27]# pwd
/usr/local/src/php-5.3.27
[root@lnmp php-5.3.27]# ls -l php.ini-*
-rw-r--r-- 1 101 101 69606 Jul 10 2013 php.ini-development
-rw-r--r-- 1 101 101 69627 Jul 10 2013 php.ini-production
[root@lnmp php-5.3.27]# cp /usr/local/src/php-5.3.27/php.ini-production /usr/local/php/lib/php.ini
php的配置文件php.ini
启动模式是fcgi的模式
[root@lnmp etc]# pwd
/usr/local/php/etc
[root@lnmp etc]# ll
total 28
-rw-r--r-- 1 root root 1212 Dec 8 21:34 pear.conf
-rw-r--r-- 1 root root 21669 Dec 8 21:34 php-fpm.conf.default
[root@lnmp etc]# mv php-fpm.conf.default php-fpm.conf
改一下他默认的配置文件,然后启动,
把php-fpm.conf.default 变成php-fpm.conf
[root@lnmp etc]# mkdir /app/logs –p
检测重启
[root@lnmp php]# ./sbin/php-fpm -t
[08-Dec-2015 21:57:55] NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful
[root@lnmp php]# netstat -lnptu |grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 30227/php-fpm
配置php整合nginx
从nginx.conf.default复制配置粘贴到下面更改
[root@lnmp extra]# vim bbs.conf
server {
listen 80;
server_name bbs.bier.org;
root html/bbs;
index index.html index.htm;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
检测
[root@lnmp nginx]# ../php/sbin/php-fpm -t
[08-Dec-2015 22:14:15] NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful
加载nginx配置文件
[root@lnmp nginx]# ./sbin/nginx -s reload
[root@lnmp bbs]# pwd
/usr/local/nginx/html/bbs
[root@lnmp bbs]# cat info.php
<?php
phpinfo();
?>
访问测试
http://bbs.bier.org/info.php
PHP测试连接mysql
[root@lnmp bbs]# vi mysql.php
<?php
$link_id=mysql_connect(‘localhost‘,‘root‘,‘bier123‘) or mysql_error();
if($link_id){
echo "mysql successful by bier !";
}else{
echo mysql_error();
}
?>
浏览器访问测试 (不需要重启服务)
或者这样子测试
[root@lnmp bbs]# /usr/local/php/bin/php mysql.php
mysql successful by bier !
到此lnmp安装完成。
本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884106
LNMP环境编译安装