设为首页 收藏本站
查看: 1147|回复: 0

LNMP环境的基础搭建,即Linux、Nginx、MySQL、PHP环境

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-16 12:29:17 | 显示全部楼层 |阅读模式
LNMP环境的基础搭建,即Linux、Nginx、MySQL、PHP环境


注意:#用“//---//” 标记的部分不要。


参考内容:
lnmp环境搭建完全手册(四)——lnmp搭建(源码安装)
http://blog.iyunv.com/stuartjing/article/details/8124491




nginx的安装
http://www.cnblogs.com/kingtigerhu/articles/2271270.html




nginx php-fpm安装配置
http://linux.it.net.cn/e/server/nginx/2014/1208/9850.html





#查看linux版本
[iyunv@localhost ~]# lsb_release -a
LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description:    CentOS release 5.5 (Final)
Release:        5.5
Codename:       Final


#尝试用yum安装nginx,结果没有。
[iyunv@localhost ~]# yum -y install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.skyshe.cn
* base: mirrors.skyshe.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
addons                                                   | 1.9 kB     00:00     
base                                                     | 1.1 kB     00:00     
extras                                                   | 2.1 kB     00:00     
updates                                                  | 1.9 kB     00:00     
Setting up Install Process
No package nginx available.
Nothing to do


[iyunv@localhost ~]#




nginx: Linux packages
http://nginx.org/en/linux_packages.html#stable


选择CentOS 5的stable version


[iyunv@localhost ~]# cd /mnt/hgfs/sharefiles/nginx
[iyunv@localhost nginx]# ls
nginx-1.9.4.tar.gz  nginx-release-centos-5-0.el5.ngx.noarch.rpm
[iyunv@localhost nginx]# rpm -ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm
warning: nginx-release-centos-5-0.el5.ngx.noarch.rpm: Header V3 RSA/SHA1 signature: NOKEY, key ID 7bd9bf62
Preparing...                ########################################### [100%]
   1:nginx-release-centos   ########################################### [100%]
[iyunv@localhost nginx]# which nginx
/usr/bin/which: no nginx in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[iyunv@localhost nginx]#


[iyunv@localhost nginx-1.9.4]# ./configure


./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.




[iyunv@localhost nginx-1.9.4]# yum -y install pcre
Updated:
  pcre.i386 0:6.6-9.el5                                                         


Complete!


[iyunv@localhost nginx-1.9.4]# ./configure


./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.




nginx的安装
http://www.cnblogs.com/kingtigerhu/articles/2271270.html


[iyunv@localhost nginx-1.9.4]# yum -y install pcre-devel
Installed:
  pcre-devel.i386 0:6.6-9.el5                                                   


Complete!




[iyunv@localhost nginx-1.9.4]# yum -y install openssl-devel


....


Dependency Updated:
  e2fsprogs.i386 0:1.39-37.el5                                                  
  e2fsprogs-libs.i386 0:1.39-37.el5                                             
  krb5-libs.i386 0:1.6.1-80.el5_11                                             
  krb5-workstation.i386 0:1.6.1-80.el5_11                                       
  libselinux.i386 0:1.33.4-5.7.el5                                             
  libselinux-python.i386 0:1.33.4-5.7.el5                                       
  libselinux-utils.i386 0:1.33.4-5.7.el5                                       
  openssl.i686 0:0.9.8e-36.0.1.el5_11                                          
  zlib.i386 0:1.2.3-7.el5                                                      


Complete!




[iyunv@localhost nginx-1.9.4]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README




[iyunv@localhost nginx-1.9.4]# ./configure --prefix=/usr/local/nginx




[iyunv@localhost nginx-1.9.4]# make




[iyunv@localhost nginx-1.9.4]# make install


[iyunv@localhost nginx-1.9.4]# ls /usr/local/nginx/
conf  html  logs  sbin
[iyunv@localhost nginx-1.9.4]# /usr/local/nginx/sbin/nginx


[iyunv@localhost nginx-1.9.4]# netstat -antlp | grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      12310/nginx         
tcp        0      0 :::22                       :::*                        LISTEN      3804/sshd   
        
[iyunv@localhost nginx-1.9.4]#




#浏览器
http://127.0.0.1




网页显示:
Welcome to nginx!


If you see this page, the nginx web server is successfully installed and working. Further configuration is required.


For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.


Thank you for using nginx.




[iyunv@localhost /]# yum install mysql-server php php-devel php-mysql


Installed:
  mysql-server.i386 0:5.0.95-5.el5_9      php.i386 0:5.1.6-45.el5_11           
  php-devel.i386 0:5.1.6-45.el5_11        php-mysql.i386 0:5.1.6-45.el5_11     


Dependency Installed:
  mysql.i386 0:5.0.95-5.el5_9            perl-DBD-MySQL.i386 0:3.0007-2.el5     
  perl-DBI.i386 0:1.52-2.el5             php-cli.i386 0:5.1.6-45.el5_11         
  php-common.i386 0:5.1.6-45.el5_11      php-pdo.i386 0:5.1.6-45.el5_11         


Complete!


#首次启动mysql
[iyunv@localhost /]# service mysqld start
Initializing MySQL database:  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:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'


Alternatively you can run:
/usr/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 /usr ; /usr/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 /usr/bin/mysqlbug script!


The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
You have mail in /var/spool/mail/root




#mysql数据库端口
[iyunv@localhost /]# netstat -antlp ¦ grep 3306
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17863/mysqld        
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      3565/portmap        
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      12310/nginx         
tcp        0      0 0.0.0.0:821                 0.0.0.0:*                   LISTEN      3607/rpc.statd      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      3813/cupsd         
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3914/sendmail: acce
tcp        0      1 192.168.3.151:38521         74.125.203.190:443          SYN_SENT    12368/firefox      
tcp        0      0 :::22                       :::*                        LISTEN      3804/sshd           
tcp        0      0 ::ffff:192.168.3.151:22     ::ffff:192.168.3.10:55532   ESTABLISHED 4672/1              


#查看nginx配置
[iyunv@localhost /]# cat /usr/local/nginx/conf/nginx.conf


#配置主机名
[iyunv@localhost /]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.3.151   localhost.localdomain localhost


~
~
&quot;/etc/hosts&quot; 8L, 238C written


[iyunv@localhost /]#


#重启nginx
[iyunv@localhost sbin]#  /usr/local/nginx/sbin/nginx -s reload


#重启nginx失败了,只好重启linux
[iyunv@localhost /]# reboot




[iyunv@localhost /]#




#先检查一下是否有问题
[iyunv@localhost ~]# /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的启动脚本,并加入系统服务
#这个文件后来删掉了,因为发现随系统启动后,stop失败,也无法重启。只能reboot系统才行。




[iyunv@localhost ~]# vi /etc/init.d/nginx


编写nginx的启动脚本,并加入系统服务
vi /etc/init.d/nginx写入以下内容:
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN=&quot;/usr/local/nginx/sbin/nginx&quot;
NGINX_CONF=&quot;/usr/local/nginx/conf/nginx.conf&quot;
NGINX_PID=&quot;/usr/local/nginx/var/nginx.pid&quot;
RETVAL=0
prog=&quot;Nginx&quot;
start() {
        echo -n $&quot;Starting $prog: &quot;
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}
stop() {
        echo -n $&quot;Stopping $prog: &quot;
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}
reload(){
        echo -n $&quot;Reloading $prog: &quot;
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
restart(){
        stop
        start
}
configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case &quot;$1&quot; in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $&quot;Usage: $0 {start|stop|reload|restart|configtest}&quot;
        RETVAL=1
esac


exit $RETVAL








保存后,更改/etc/init.d/nginx的权限
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on




//-----------------------------------------------------------------//


#启动nginx
[iyunv@localhost ~]# service nginx start
Starting Nginx:                                            [  OK  ]


[iyunv@localhost ~]# netstat -antlp | grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4724/nginx.conf




#如果启动不了,请到/usr/local/nginx/logs/目录下查看nginx_error.log这个日志文件。若是没有这个日志文件,很有可能是那个目录没有写权限,请执行


chmod &#43;w /usr/local/nginx/logs/
service  nginx  restart


[iyunv@localhost ~]# chmod &#43;w /usr/local/nginx/logs/






//-----------------------------------------------------------------//
#发现问题,nginx启动后网页无法访问
#关键文件要备份啊,幸好我有个备份nginx (copy).conf,后来是采用还原nginx.conf这个文件,nginx就恢复了。


[iyunv@localhost local]# cd /usr/local/
[iyunv@localhost local]# cat error.log


#解决 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (2: No such file or directory) 问题


[iyunv@localhost local]# yum -y install gcc automake autoconf libtool make


[iyunv@localhost local]# yum -y install gcc gcc-c&#43;&#43; glibc




[iyunv@localhost local]# yum -y install libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-deve


#php版本
[iyunv@localhost sharefiles]# php -v
PHP 5.1.6 (cli) (built: Nov  6 2014 12:25:33)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies


#想打个补丁,不过失败了
[iyunv@localhost sharefiles]# gzip -cd php-5.2.17-fpm-0.5.14.diff.gz
//-----------------------------------------------------------------//








php-fpm介绍及配置
http://blog.iyunv.com/tonyxf121/article/details/7869187




#php-fpm配置


从php5.3.3版本开始就已经集成了fpm,不再是第三方的包了,如果使用的是php5.3.3以前的版本就得自己去安装fpm包了,对于php5.2.x的版本,fpm的配置文件还是xml&#26684;式,php5.3.x开始fpm配置文件


就已经支持ini&#26684;式了。




tar用法:
.tar.gz     &#26684;式解压为          tar   -zxvf   xx.tar.gz


.tar.bz2   &#26684;式解压为          tar   -jxvf    xx.tar.bz2


[iyunv@localhost local]#


#不打升级包了,直接更新php




[iyunv@localhost sharefiles]# tar -jxvf php-5.6.13.tar.bz2


[iyunv@localhost sharefiles]#ls


[iyunv@localhost sharefiles]#cd php-5.6.13


#一开始我是用./configure 和 make && make install安装,后来发现不行。
#./configure 后面一定要带参数


[iyunv@localhost php-5.6.13]# mkdir /etc/php /etc/php5.d
[iyunv@localhost php-5.6.13]# cp php.ini-production /etc/php
[iyunv@localhost php-5.6.13]#  chmod a&#43;x /etc/init.d/php-fpm


[iyunv@localhost php-5.6.13]# ./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt \
--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath \
--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \
--with-gd --with-jpeg-dir


[iyunv@localhost php-5.6.13]# make all install




nginx 服务器重启命令,关闭
http://blog.iyunv.com/uid-24960107-id-341855.html






[iyunv@localhost ~]# cd /usr/local/nginx/


[iyunv@localhost nginx]# ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp


[iyunv@localhost nginx]# cd sbin


[iyunv@localhost sbin]# ls
nginx
[iyunv@localhost sbin]# ./nginx


[iyunv@localhost sbin]# netstat -antlp ¦ grep 80
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      3564/portmap        
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4339/nginx         
tcp        0      0 0.0.0.0:820                 0.0.0.0:*                   LISTEN      3606/rpc.statd      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      3812/cupsd         
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3912/sendmail: acce
tcp        0      0 :::22                       :::*                        LISTEN      3803/sshd           
tcp        0    596 ::ffff:192.168.3.151:22     ::ffff:192.168.3.10:52560   ESTABLISHED 4293/1              




#停止niginx
[iyunv@localhost sbin]# ./nginx -s stop


#
[iyunv@localhost sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf











下面是对php-fpm运行用户进行设置


cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf  
修改
user = oracle
group = oracle


如果oracle用户不存在,那么先添加oracle用户
groupadd oracle
useradd -g oracle oracle




修改nginx配置文件以支持php-fpm


nginx安装完成后,修改nginx配置文件为:nginx.conf


其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}






#以防以后忘记了,这里把server这段内容贴出来
##开始
   server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   html;
            index  index.html index.htm;   (这里漏了加index.php,不过php页面也正确显示出来了。)




# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}




        }


##结束








启动php-fpm和nginx


#重启nginx
[iyunv@localhost nginx]# ./sbin/nginx  -s stop
[iyunv@localhost nginx]# ./sbin/nginx




#找php-fpm目录
[iyunv@localhost php]# ls
bin  etc  include  lib  man  php  php.ini  sbin  var
[iyunv@localhost php]# cd /usr/local/php/
[iyunv@localhost php]# ls
bin  etc  include  lib  man  php  php.ini  sbin  var
[iyunv@localhost php]# cd sbin/
[iyunv@localhost sbin]# ls
php-fpm


#启动php-fpm
[iyunv@localhost sbin]# ./php-fpm
[iyunv@localhost sbin]#




浏览器:http://127.0.0.1/index.php
页面显示:PHP Version 5.6.13






mysql 的设置和LAMP中的设置一样,设置用户密码,删除匿名用户。
测试PHP与mysql连接。
这里就不再重复了。








不过以后要记得LNMP需要启动的服务:


./nginx
./php-fpm
/etc/init.d/mysqld start (mysql登录: mysql -u root)


  

  

  结束测试:
  [iyunv@localhost ~]# halt


Broadcast message from root (pts/4) (Fri Sep 11 06:48:59 2015):


The system is going down for system halt NOW!




  总结:
  1. 手动启服务
  #启动mysql
[iyunv@localhost /]# service mysqld start

  
  #nginx启动
[iyunv@localhost sbin]# ./nginx

  

  #停止niginx
  [iyunv@localhost sbin]# ./nginx -s stop

  

  #启动php-fpm
[iyunv@localhost sbin]# ./php-fpm

  

  

  
  

  2.检查nginx
  #检查nginx是否有问题
[iyunv@localhost ~]# /usr/local/nginx/sbin/nginx  -t

  

  3.配置文件:
  nginx配置文件:/etc/init.d/nginx

  

  //-----------------------------------------------------------------------------------------------------//
  
  
  本文只是简单搭建了一个测试环境。如果需要用好nginx还需要不断学习和研究。

详解Nginx配置文件结构
  http://www.iyunv.com/Linux/2013-11/92594.htm


























  #nginx启动
[iyunv@localhost sbin]# ./nginx

  

  #停止niginx
  [iyunv@localhost sbin]# ./nginx -s stop

  

  #启动php-fpm
[iyunv@localhost sbin]# ./php-fpm

  

  #启动mysql
  /etc/init.d/mysqld start


         版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139907-1-1.html 上篇帖子: LNMP 一键安装后的 地址 下篇帖子: [Web服务器搭建][LNMP]Centos6.3x64+nginx1.6+php5.5(fastcgi)+mysql5.5搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表