centos6.9安装lnmp

your must run:

shell> yum install -y make gcc gcc-c++ perl zlib-devel libaio libpng libpng-devel libjpeg-devel pcre-devel

shell> yum install -y libXpm-devel openssl openssl-devel libxml2-devel bzip2-devel.x86_64 libjpeg-turbo-devel

unnecessary run:

yum install -y freetype freetype-devel libtool cmake ncurses-devel bison re2c curl-devel wget

rpm -ivh "http://mirrors.sohu.com/fedora-epel/epel-release-latest-6.noarch.rpm"

yum install -y libmcrypt-devel re2c

first part:Install Nginx 

Document:https://www.nginx.com/resources/wiki/start/topics/tutorials/install/ 

一、Official CentOS packages To add NGINX yum repository, create a file named /etc/yum.repos.d/nginx.repo and paste one of the configurations below: CentOS:

shell> vim /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

二、Source Releases wget Stable NGINX

shell> cd /usr/local/src

shell> wget http://nginx.org/download/nginx-1.10.1.tar.gz

shell> tar xf nginx-1.10.1.tar.gz

三、Building NGINX From Source After extracting the source, run these commands from a terminal:

shell> cd nginx-1.10.1/

shell> ./configure

return

  nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx modules path: "/usr/local/nginx/modules"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

shell> make

shell> make install

四、Starting, Stopping, and Restarting NGINX /usr/local/nginx/sbin Basic Example of Starting NGIN

shell> ln -s  /usr/local/nginx/sbin/nginx  /usr/bin/nginx

shell> /usr/bin/nginx

second part:Install PHP 

Document:http://php.net/manual/zh/install.unix.nginx.php 

一、wget Stable PHP

shell> cd /usr/local/src

shell> wget http://cn2.php.net/distributions/php-7.2.4.tar.gz

shell> tar xf php-7.2.4.tar.gz

二、configure and build PHP. This is where you customize PHP with various options, like which extensions will be enabled. Run ./configure –help for a list of available options. In our example we’ll do a simple configure with PHP-FPM and MySQLi support.

shell> cd php-7.2.4

shell> ./configure --enable-fpm --with-mysqli

shell> make

shell> make test

shell> make install

return

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/

Installing PHP CLI binary: /usr/local/bin/

Installing PHP CLI man page: /usr/local/php/man/man1/

Installing PHP FPM binary: /usr/local/sbin/

Installing PHP FPM defconfig: /usr/local/etc/

Installing PHP FPM man page: /usr/local/php/man/man8/

Installing PHP FPM status page: /usr/local/php/php/fpm/

Installing phpdbg binary: /usr/local/bin/

Installing phpdbg man page: /usr/local/php/man/man1/

Installing PHP CGI binary: /usr/local/bin/

Installing PHP CGI man page: /usr/local/php/man/man1/

Installing build environment: /usr/local/lib/php/build/

Installing header files: /usr/local/include/php/

Installing helper programs: /usr/local/bin/

  program: phpize

  program: php-config

Installing man pages: /usr/local/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment: /usr/local/lib/php/

[PEAR] Archive_Tar - installed: 1.4.3

[PEAR] Console_Getopt - installed: 1.4.1

[PEAR] Structures_Graph- installed: 1.1.1

[PEAR] XML_Util - installed: 1.4.2

[PEAR] PEAR - installed: 1.10.5

Wrote PEAR system config file at: /usr/local/etc/pear.conf

You may want to add: /usr/local/lib/php to your php.ini include_path

/usr/local/src/php-7.2.4/build/shtool install -c ext/phar/phar.phar /usr/local/bin

ln -s -f phar.phar /usr/local/bin/phar

Installing PDO headers: /usr/local/include/php/ext/pdo/

三、Obtain and move configuration files to their correct locations

shell> cp /usr/local/src/php-7.2.4/php.ini-development /usr/local/lib/php.ini

shell> cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

shell> cp /usr/local/src/php-7.2.4/sapi/fpm/php-fpm /usr/local/bin

四、modify php.ini It is important that we prevent Nginx from passing requests to the PHP-FPM backend if the file does not exists, allowing us to prevent arbitrarily script injection. We can fix this by setting the cgi.fix_pathinfo directive to 0 within our php.ini file. Load up php.ini:

shell> vim /usr/local/lib/php.ini

cgi.fix_pathinfo=0

Locate cgi.fix_pathinfo= and modify it as follows

五、run php-fpm

shell> groupadd www

shell> useradd www -g www

php-fpm.conf must be modified to specify that php-fpm must run as the user www and the group www before we can start the service: vim /usr/local/etc/php-fpm.conf,Find and modify the following:

shell> cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

shell> vim /usr/local/etc/php-fpm.d/www.conf

[www]

user = www

group = www

The php-fpm service can now be started:

shell> /usr/local/bin/php-fpm

thire part:PHP & Nginx 

一、Nginx must now be configured to support the processing of PHP applications: vim /usr/local/nginx/conf/nginx.conf Modify the default location block to be aware it must attempt to serve .php files:

shell> vim /usr/local/nginx/conf/nginx.conf

location / {

    root html;

    index index.php index.html index.htm;

}

The next step is to ensure that .php files are passed to the PHP-FPM backend. Below the commented default PHP location block, enter the following:

shell> vim /usr/local/nginx/conf/nginx.conf

location ~ \.php$ {

    root /usr/local/nginx/html;

    fastcgi_index index.php;

    fastcgi_pass 127.0.0.1:9000;

    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

Restart Nginx.

shell> /usr/local/nginx/sbin/nginx -s reload

二、Create a test file

rm /usr/local/nginx/html/index.html

echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php

fourth part:Install MySQL 

eg.https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

shell> groupadd mysql

shell> useradd -r -g mysql -s /bin/false mysql

shell> cd /usr/local/src

shell> wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

shell> tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

shell> mv /usr/local/src/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/

shell> cd /usr/local

shell> ln -s mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz mysql

shell> cd mysql

shell> mkdir mysql-files

shell> chown -R mysql:mysql mysql-files

shell> chmod 750 mysql-files

shell> /usr/local/mysql/bin/mysqld --initialize --user=mysql //这一步会返回MySQL密码,一定要记住

return

A temporary password is generated for root@localhost: %:#.wdGNV2C9

shell> /usr/local/mysql/bin/mysql_ssl_rsa_setup

shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &

return

2018-05-04T12:36:49.064297Z mysqld_safe Logging to '/var/log/mysqld.log'.

2018-05-04T12:36:49.082759Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

2018-05-04T12:36:49.499394Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

# Add Environment variables--建议官方文档在安装页面加上此行命令

shell> vim /etc/profile

# Path manipulation

if [ "$EUID" = "0" ]; then

    pathmunge /usr/local/src/mysql/bin

    pathmunge /etc/init.d

else

    pathmunge /usr/local/src/mysql/bin

    pathmunge /etc/init.d

fi

shell> source /etc/profile

shell> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

# Next command is optional

shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server

shell> mysql.server start

if start mysql.server return error message,eg.

shell> mysql.server start

/usr/local/src/mysql/support-files/mysql.server: line 239: my_print_defaults: command not found

/usr/local/src/mysql/support-files/mysql.server: line 259: cd: /usr/local/mysql: 没有那个文件或目录

Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[失败]sqld_safe)

your have change /usr/local/support-files/mysql.server files.

vim support-files/mysql.server

/usr/local/mysql replace /usr/local/src/mysql

mysql.server start

if start mysql.server return error message,eg.

shell> mysql.server start

Starting MySQL...The server quit without updating PID file [失败]lib/mysql/sanqianServer.pid).

sorry i don’t know

if you want to mysql

shell> vim /etc/my.cnf

[client]

user=root

password=qkyrYpd2um&)

[root@sanqianServer mysql]# 2018-04-21T10:10:50.118966Z mysqld_safe Logging to ‘/var/log/mysqld.log’.//mysqld日志 2018-04-21T10:10:50.152620Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2018-04-21T10:10:51.014194Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

fifth part:Install Redis 

1、download redis

shell > cd /usr/local/

shell > wget http://download.redis.io/releases/redis-2.8.17.tar.gz

2、Install

shell > tar xf redis-2.8.17.tar.gz

shell > ln -s redis-2.8.17.tar.gz redis

shell > cd redis

shell > make

return

Leaving directory `/usr/local/redis-4.0.9/src'

3、start redis

shell > /usr/local/redis/src/redis-server

sixth part:PHP & Redis 

一、Install PHP redis drive 

1、to pull latest stable repleased version phpredis https://github.com/phpredis/phpredis

shell > cd /usr/local/

shell > wget https://github.com/phpredis/phpredis/archive/3.1.4.tar.gz

shell > cd phpredis-3.1.4 # 进入 phpredis 目录

shell > /usr/local/bin/phpize # php安装后的路径

shell > ./configure --with-php-config=/usr/local/bin/php-config

shell > make && make install

if you have question,like this

shell > /usr/local/bin/phpize

return

Cannot find config.m4.

Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module

you need run command

cd /usr/loca/src

wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz

tar xf m4-1.4.9.tar.gz

mv m4-1.4.9 /usr/loca/

cd /usr/loca/m4-1.4.9

./configure && make && make install

cd /usr/loca/src

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz

tar xf autoconf-2.62.tar.gz

mv autoconf-2.62 /usr/loca/

cd /usr/loca/autoconf-2.62/

./configure && make && make install

2、phpredis can be used to store PHP sessions. To do this, configure session.save_handler and session.save_path in your php.ini to tell phpredis where to store the sessions:

shell > vim /usr/local/lib/php.ini

session.save_handler = redis

session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5"

3、update php.ini

shell > vim /usr/local/lib/php.ini

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20170718/"

extension=redis.so

3、restart php

shell > ps aux | grep php-fpm

root 105292 0.0 0.0 145288 4984 ? Ss 10:58 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)

nobody 105293 0.0 0.0 145352 6052 ? S 10:58 0:00 php-fpm: pool www

nobody 105294 0.0 0.0 145288 4632 ? S 10:58 0:00 php-fpm: pool www

root 105342 0.0 0.0 103344 860 pts/3 S+ 11:00 0:00 grep php-fpm

shell > kill 105292 # php-fpm master 进程

shell > /usr/local/bin/php-fpm

shell > ps aux | grep php-fpm

root 105347 0.0 0.0 147896 5140 ? Ss 11:00 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)

nobody 105348 0.0 0.0 147896 4780 ? S 11:00 0:00 php-fpm: pool www

nobody 105349 0.0 0.0 147896 4780 ? S 11:00 0:00 php-fpm: pool www

root 105351 0.0 0.0 103344 864 pts/3 S+ 11:00 0:00 grep php-fpm

4、restart nginx

shell > /usr/local/nginx/sbin/nginx -s reload

5、check

shell > vim redis-demo.php

<?php

    //连接本地的 Redis 服务

    $redis = new Redis();

    $redis->connect('127.0.0.1', 6379);

    echo "Connection to server sucessfully"; //查看服务是否运行

    echo "Server is running: " . $redis->ping();

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容