Chapter one:安装配置LNMP

  • 源码安装配置LNMP

更新时间:2016-08-02


系统环境:CentOS 6.5

软件环境:nginx 1.8.1、mysql 5.6.22、php 5.6.19

本机IP  :192.168.1.88、192.168.1.36

  • 关闭防火墙和安全机制

#service iptables stop

#setenforce 0

#getenforce

【nginx】

1. 创建用户

#groupadd nginx

#useradd -M -s /sbin/nologin nginx -g nginx

2. 编译安装

#yum -y install pcre-devel zlib-devel gcc                

# tar zvxf nginx-1.8.1.tar.gz -C /usr/src/

# cd /usr/src/nginx-1.8.1/

# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module

#make && make install

3. 创建软连接

 #ln -s /usr/local/nginx/sbin/* /usr/local/sbin/                    

4.检查配置文件

# nginx -t

5. 启动nginx服务


#nginx

#netstat -anpt | grep nginx

tcp   0   0 0.0.0.0:80        0.0.0.0:*         LISTEN      17295/nginx

  • 浏览器访问本机IP

nginx配置优化

worker_processes auto //nginx要开启的进程数,一般等于cpu的总核数 (设置为“auto”将尝试自动检测它)

worker_rlimit_nofile 102400 //这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,但是nginx分配请求并不是那么均匀,所以最好与ulimit -n的值保持一致。

worker_connections 5000 //每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为worker_processes*worker_connections。

keepalive_timeout 60 //keepalive超时时间

access_log /var/log/nginx/access.log //设置nginx是否将存储访问日志

error_log /var/log/nginx/error.log //告诉nginx只能记录严重的错误

【mysql】

1.创建用户

 #useradd mysql 

2.编译安装

# yum -y install ncurses ncurses-devel gcc libtool gcc-c++ make cmake
#tar zvxf mysql-5.6.22.tar.gz -C /usr/src

#cd /usr/src/mysql-5.6.22/

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DENABLE_DOWNLOADS=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DMYSQL_USER=mysql

#make && make install

3. 更改属主属组

#chown -R mysql:mysql /usr/local/mysql/

初始化:

#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

拷贝文件:


# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

添加启动mysqld服务:


[[email protected] ~]# chkconfig --add mysqld

[[email protected] ~]# chkconfig mysqld on

[[email protected] ~]# service mysqld start

Starting MySQL..                                           [确定]

软连接:

[[email protected]localhost ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/

4. 设置mysql密码

  #mysqladmin -uroot password ‘newpass‘

修改密码报错:

mysqladmin: connect to server at ‘localhost‘ failed
error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: YES)‘

进数据库更改密码:

  • 1.service mysqld stop

  • 2. mysqld_safe --skip-grant-tables &
  • 3. mysql -uroot -p  回车进入
  • >use mysql;
    > update user set password=PASSWORD("newpass")where user="root";

    > flush privileges;
     更新权限
    > quit
     退出
  • 4.service mysqld restart
  • 5. mysql -uroot -pnewpass 进入

【PHP】

1. 编译安装

# yum -y install openssl openssl-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

# tar zvxf php-5.6.19.tar.gz -C /usr/src

# cd /usr/src/php-5.6.19/

# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5 --enable-fpm --with-fpm-user=php --with-fpm-group=php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache

报错:

1. configure: error: mcrypt.h not found. Please reinstall libmcrypt.

#tar zvxf libmcrypt-2.5.7.tar.gz -C /usr/src/

#cd /usr/src/libmcrypt-2.5.7/

#./configure --prefix=/usr/local/libmcrypt  && make && make install

2. configure: error: Don‘t know how to define struct flock on this system, set --enable-opcache=no

   #vim /etc/ld.so.conf.d/local.conf     

      /usr/local/lib                       添加该行

  # ldconfig             //使之生效

继续编译安装:

# make && make install

2. 配置php-fpm模块

[[email protected] php-5.6.19]# cp php.ini-development /usr/local/php5/php.ini

[[email protected] ~]# cd /usr/local/php5/etc/

[[email protected] etc]# ls

pear.conf  php-fpm.conf.default

[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf

[[email protected] etc]# useradd -M -s /sbin/nologin php

编辑配置文件


# vim php-fpm.conf

25 pid = run/php-fpm.pid

131 user = php

132 group =php

236 pm.max_children = 50

241 pm.start_servers = 20

246 pm.min_spare_servers = 5

251 pm.max_spare_servers = 35

启动php-fpm

[[email protected] etc]# /usr/local/php5/sbin/php-fpm

[[email protected] etc]# netstat -anpt | grep php-fpm

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      45716/php-fpm

3.将php-fpm模块加入nginx配置文件


#vim /usr/local/nginx/conf/nginx.conf

server {

listen       80;

server_name  www.baidu.com;

charset utf-8;

access_log  logs/host.access.log  main;

location / {

root   html/baidu;

index  index.html index.htm index.php;

}

location ~ \.php$ {

root           html/baidu;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

include        fastcgi.conf;

}

}

重启nginx


[[email protected] etc]# killall nginx

[[email protected] etc]# netstat -anpt | grep nginx

[[email protected] etc]# nginx

[[email protected] etc]# netstat -anpt | grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      45787/nginx

4. 测试

域名映射


# vim /etc/hosts

192.168.1.36    www.baidu.com

创建网页目录


#mkdir /usr/local/nginx/html/baidu

测试

# echo Baidu > /usr/local/nginx/html/baidu/index.html

# elinks --dump 192.168.1.36

Baidu

测试nginx和PHP连通性


[[email protected] baidu]# pwd

/usr/local/nginx/html/baidu

[[email protected] baidu]# cat 2.php

<?php

phpinfo();

?>

测试数据库和PHP连通性

#vim /usr/local/nginx/html/baidu/test.php

<?php

$link=mysql_connect(‘localhost‘,‘root‘,‘123456‘);            //连接mysql数据库

if($link) echo "<h1>恭喜你,大功告成!!</h1>";                           //连接成功则返回信息

mysql_close();                                                                                              //关闭数据库连接

?>


[[email protected] html]# elinks --dump192.168.1.36/test.php

恭喜你,大功告成!!

在网上查询的,未实验过。

mysql_connect这个模块将在未来弃用,请你使用mysqli或者PDO来替代。

解决方法1:

禁止PHP报错


display_errors = On


改为


display_errors = Off

鉴于这个服务器都是给用户用的,有时候他们需要报错,不能这做,让他们改程序吧,看方案2.

解决方法2:

常用的php语法连接MySQL如下


<?php


$link =  mysql_connect(‘localhost‘, ‘user‘, ‘password‘);


mysql_select_db(‘dbname‘, $link);


改成mysqi


<?php


$link = mysqli_connect(‘localhost‘, ‘user‘, ‘password‘, ‘dbname‘);

常用mysql建表SQL如下


<?php


//  老的


mysql_query(‘CREATE  TEMPORARY TABLE `table`‘, $link);


// 新的


mysqli_query($link, ‘CREATE  TEMPORARY TABLE `table`‘);

解决方法三:
在php程序代码里面设置报警级别


<?php


error_reporting(E_ALL ^  E_DEPRECATED);

时间: 2024-11-01 21:37:41

Chapter one:安装配置LNMP的相关文章

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)

CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: 1 /etc/init.d/iptables stop #关闭防火墙 2 关闭SELINUX 3 vi /etc/selinux/config 4 #SELINUX=enforcing #注释掉 5 #SELINUXTYPE=targeted #注释掉 6 SELINUX=disabled #增加 7 :wq 8 shutdown -r now #重启系统 二.安装篇 1.安装nginx 1 yum re

CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

准备篇 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙 备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败, 正确

CentOS 6.5 yum安装配置lnmp服务器(Nginx+PHP+MySQL)

以下全部转载于  http://blog.csdn.net/lane_l/article/details/20235909 本人于今晚按照该文章使用centos 6.7 64bit安装成功,做个备份,就转过来了. --------------------------------------------------------------- 转载者语: 转载于:http://www.osyunwei.com/archives/2353.html 原文标题:CentOS 6.2yum安装配置lnmp

CentOS 6.4 安装配置LNMP服务器(Nginx+PHP+MySQL) 及搭建Wordpress

准备:1.配置防火墙,开启80端口.3306端口 # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state –state ESTABLISHED,RE

ubuntu安装配置LNMP

Ubuntu-15. 04安装配置LNMP服务 一.操作系统版本信息 [email protected]:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description:    Ubuntu 14.04.4 LTS Release:    14.04 Codename:   trusty 二.安装MYSQL (1)开始安装: apt-get install mysql-server libmys

CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

这篇文章主要介绍了CentOS 6.4下配置LNMP服务器的详细步骤,需要的朋友可以参考下 准备篇 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #允许80端口通过防火墙-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口

Centos6.4 安装配置LNMP

配置环境: L:Centos 2.6.32-358.el6.x86_64 N:Nginx 1.7 M:Mysql5.7.3 P:PHP5.5.11 NGINX一键脚本: #!/bin/bash # Author:Byrd # Version:1.0 # Site:www.t4x.org # Contact:root#t4x.org # Compile and install NGINX BY:BYRD AT:2014-04-30 # This script for nginx1.4 nginx1

CentOS上yum方式安装配置LNMP

实验环境 一台最小化安装的CentOS 7.6虚拟机 安装软件包 yum install -y epel-* yum install -y nginx mariadb-server php php-mysql php-fpm php-pdo php-pdo_dblib php-gd php-pear php-xml php-pecl-zip php-json php-devel wget vim 配置nginx支持PHP 1.建立nginx的web主目录 mkdir /var/wwwroot c

CentOS6.2 yum安装配置lnmp服务器(Nginx+PHP+MySQL)

1.配置防火墙,开启80端口.3306端口        vi /etc/sysconfig/iptables        -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)        -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙) 特别提示:很多网友把这两条规则添加到防火