Chapter one:安装配置LNMP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 3. 创建软连接
# 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
#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.创建用户
2.编译安装
#useradd mysql
# 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] ~]# 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);
本文出自 “一个Linux小白-学习运维” 博客,请务必保留此出处http://zhaojia.blog.51cto.com/12886290/1923697
以上是关于Chapter one:安装配置LNMP的主要内容,如果未能解决你的问题,请参考以下文章
Chapter One:数据结构和算法-解压序列赋值给多个变量