LNMP环境编译安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP环境编译安装相关的知识,希望对你有一定的参考价值。
安装nginx
[[email protected] src]# tar -xf nginx-1.6.2.tar.gz
[[email protected] src]# ls
nginx-1.6.2 nginx-1.6.2.tar.gz
[[email protected] nginx-1.6.2]#
[[email protected] nginx-1.6.2]# useradd -s /sbin/nologin -M nginx
[[email protected] 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
[[email protected] local]# ln -s /usr/local/nginx1.6.2/ /usr/local/nginx
[[email protected] 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
[[email protected] 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
[[email protected] local]# ./nginx/sbin/nginx 启动nginx
[[email protected] 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
[[email protected] conf]# grep html nginx.conf
root html; 默认站点
[[email protected] 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
配置虚拟主机
[[email protected] conf]# mkdir ../html/{www,blog,bbs}
[[email protected] conf]# for i in www blog bbs;do echo "http://$i.bier.org" >../html/$i/index.html;done
[[email protected] 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;
}
}
[[email protected] 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
[[email protected] nginx]# ./sbin/nginx -s reload 加载配置文件
配置好hosts,浏览器测试访问
安装mysql
安装mysql(二进制包安装方式,直接解压,初始化数据库即可,无需编译)
[[email protected] local]# useradd mysql -s /sbin/nologin –M
[[email protected] local]#tar -xf mysql-5.5.32-linux2.6-x86_64.tar.gz
[[email protected] local]#mv mysql-5.5.32-linux2.6-x86_64 mysql
[[email protected] local]# chown -R mysql.mysql ./mysql/data
拷贝启动脚本
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig --list |grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] mysql]# chkconfig mysqld on
拷贝配置文件
[[email protected] mysql]# cp support-files/my-small.cnf /etc/my.cnf
初始化数据库
[[email protected] 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
[[email protected] mysql]# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!
[[email protected] mysql]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 35035 mysql 10u IPv4 48207 0t0 TCP *:mysql (LISTEN)
连接数据库
[[email protected] mysql]# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[[email protected] mysql]# find /usr/local/ -type f -name "mysql"
/usr/local/mysql/bin/mysql
[[email protected] mysql]# cp /usr/local/mysql/bin/mysql /usr/local/sbin/
[[email protected] 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的配置文件
[[email protected] php-5.3.27]# pwd
/usr/local/src/php-5.3.27
[[email protected] 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
[[email protected] 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的模式
[[email protected] etc]# pwd
/usr/local/php/etc
[[email protected] 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
[[email protected] etc]# mv php-fpm.conf.default php-fpm.conf
改一下他默认的配置文件,然后启动,
把php-fpm.conf.default 变成php-fpm.conf
[[email protected] etc]# mkdir /app/logs –p
检测重启
[[email protected] 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
[[email protected] 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复制配置粘贴到下面更改
[[email protected] 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;
}
}
检测
[[email protected] 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配置文件
[[email protected] nginx]# ./sbin/nginx -s reload
[[email protected] bbs]# pwd
/usr/local/nginx/html/bbs
[[email protected] bbs]# cat info.php
<?php
phpinfo();
?>
访问测试
http://bbs.bier.org/info.php
PHP测试连接mysql
[[email protected] 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();
}
?>
浏览器访问测试 (不需要重启服务)
或者这样子测试
[[email protected] bbs]# /usr/local/php/bin/php mysql.php
mysql successful by bier !
到此lnmp安装完成。
本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884106
以上是关于LNMP环境编译安装的主要内容,如果未能解决你的问题,请参考以下文章