CentOS系列之LNPM环境搭建

以下操作以CentOS 6为例
#1、跟换yum源
需要的话猛戳这里

2、安装Mysql

以目前最新的mysql5.7为例

2.1、下载发行包

猛戳这里:http://dev.mysql.com/downloads/repo/yum/

CentOS系列之LNPM环境搭建_第1张图片

2.2、释放包

sudo rpm -Uvh mysql57-community-release-el6-11.noarch.rpm

2.3、安装mysql

 sudo yum install mysql-community-server

啪啦啪啦一大大堆英文字母,强烈忍受一会就好了

2.4、初始化mysql

不出意外的话,mysql已经成功安装了,除非你人品真的很不好,不好意思,让我嘲笑你一会

2.4.1、开启mysql服务

sudo service mysqld start

2.4.2、获取初始化密码

sudo grep 'temporary password' /var/log/mysqld.log
  • 稍微演示一下

这里写图片描述

2.4.3、复制初始化密码,登录mysql

mysql -uroot -p

2.4.5、修改密码(mysq强制执行的)

set password=PASSWORD("MewPassword123!")

2.4.6、再次登录

CentOS系列之LNPM环境搭建_第2张图片

至此,MySQL大哥就被征服了,是不是有点佩服自己呢?那好在教你一个跟简单的方法安装Nginx

3、安装Nginx

史上最简单的Nginx安装方法

3.1、修改Nginx的yum配置文件

# 粘贴下列代码到nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

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

3.2、开始安装

sudo yum nginx install -y

3.3、开启Nginx服务

sudo service nginx start

这里写图片描述

3.4、查看nginx运行情况

sudo service nginx status

至此,Nginx就安装完成了

4、安装PHP

4.1、安装杂项

  • 需要的话,猛粘这里
yum install -y epel-release
yum makecache fast
yum install -y gcc gcc-c++ perl libpng-devel libjpeg-devel libwebp-devel libXpm-devel libtiff-devel libxml2-devel libcurl-devel libmcrypt-devel fontconfig-devel freetype-devel libzip-devel bzip2-devel gmp-devel readline-devel recode-devel GeoIP-devel bison re2c

4.2、创建PHP的管理用户

groupadd www
useradd www -g www

4.3、安装必要的包

为了让 PHP 和 Nginx 更高效的运行,完善的编译下去,这里指定安装了几个最新版的相关库。

  • 安装libiconv
# 下载并解压 libiconv
cd /tmp
curl -O --retry 3 https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar -zxf libiconv-1.15.tar.gz

# 编译
cd libiconv-1.15
./configure --prefix=/usr/local/libiconv
make -j && make install

# 增加到动态链接库:
echo '/usr/local/libiconv/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
  • 安装pcre
# 下载并解压 pcre
cd /tmp
curl -O --retry 3 https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
tar -zxf pcre-8.40.tar.gz

# 编译
cd pcre-8.40
./configure --prefix=/usr/local/pcre --enable-utf8 --enable-unicode-properties
make -j && make install

# 增加到动态链接库
echo '/usr/local/pcre/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
  • 安装zlib
# 下载并解压 zlib
cd /tmp
curl -O --retry 3 http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz

# 编译
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make -j && make install

# 增加到动态链接库
echo '/usr/local/zlib/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
  • 安装libgd
# 下载并解压 libgd
cd /tmp
curl -O --retry 3 -L https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.gz
tar -zxf libgd-2.2.4.tar.gz

# 编译
cd libgd-2.2.4
./configure \
  --prefix=/usr/local/libgd \
  --with-libiconv-prefix=/usr/local/libiconv \
  --with-zlib=/usr/local/zlib \
  --with-jpeg=/usr \
  --with-png=/usr \
  --with-webp=/usr \
  --with-xpm=/usr \
  --with-freetype=/usr \
  --with-fontconfig=/usr \
  --with-tiff=/usr
make -j && make install

# 增加到动态链接库
echo '/usr/local/libgd/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
  • 安装openssl
# 下载并解压 openssl
cd /tmp
curl -O --retry 3 https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxf openssl-1.0.2k.tar.gz

# 编译
cd openssl-1.0.2k
./config --prefix=/usr/local/openssl -fPIC
make -j && make install
  • 安装php
# 下载并解压 php
cd /tmp
curl -O --retry 3 http://cn.php.net/distributions/php-5.6.32.tar.gz
tar -zxf php-7.1.5.tar.gz

# 编译
cd php-7.1.5
./configure \
  --prefix=/usr/local/php56 \
  --sysconfdir=/etc/php56 \
  --with-config-file-path=/etc/php56 \
  --with-config-file-scan-dir=/etc/php56/php-fpm.d \
  --with-fpm-user=www \
  --with-fpm-group=www \
  --with-curl \
  --with-mhash \
  --with-mcrypt \
  --with-gd \
  --with-gmp \
  --with-bz2 \
  --with-recode \
  --with-readline \
  --with-gettext \
  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-openssl=/usr/local/openssl \
  --with-openssl-dir=/usr/local/openssl \
  --with-pcre-regex=/usr/local/pcre \
  --with-pcre-dir=/usr/local/pcre \
  --with-zlib=/usr/local/zlib \
  --with-zlib-dir=/usr/local/zlib \
  --with-iconv-dir=/usr/local/libiconv \
  --with-libxml-dir=/usr \
  --with-libzip=/usr \
  --with-gd=/usr/local/libgd \
  --with-jpeg-dir=/usr \
  --with-png-dir=/usr \
  --with-webp-dir=/usr \
  --with-xpm-dir=/usr \
  --with-freetype-dir=/usr \
  --enable-fpm \
  --enable-ftp \
  --enable-gd-native-ttf \
  --enable-gd-jis-conv \
  --enable-calendar \
  --enable-exif \
  --enable-pcntl \
  --enable-soap \
  --enable-shmop \
  --enable-sysvmsg \
  --enable-sysvsem \
  --enable-sysvshm \
  --enable-wddx \
  --enable-inline-optimization \
  --enable-bcmath \
  --enable-mbstring \
  --enable-mbregex \
  --enable-re2c-cgoto \
  --enable-xml \
  --enable-mysqlnd \
  --enable-embedded-mysqli \
  --enable-opcache \
  --enable-sockets \
  --disable-debug
make -j && make install

# 增加软链接
ln -sf /usr/local/php71/bin/php /usr/bin/php
ln -sf /usr/local/php71/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php71/sbin/php-fpm /usr/bin/php-fpm

# 复制 php.ini
cp -v php.ini-production /etc/php71/php.ini
cp /usr/local/php56/sbin/php-fpm /usr/bin/php-fpm

4.4、配置php-fpm

cp -v /etc/php71/php-fpm.conf.default /etc/php71/php-fpm.conf

4.4、配置Nginx

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
vim /etc/nginx/conf.d/default.conf

将以下代码粘贴其中

server
{
    listen 80;
    server_name 127.0.0.1; #server_name end
    index index.html index.htm index.php; #index end
    charset utf-8;
    if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
 	 set $subdomain $1;
 	 set $domain $2;
    }
    # set $subdomain '/';
    root  /home/wwwroot/index/$subdomain/;
    include rewrite/nomal.conf; #rewrite end

    location ~ .*\.php$
    {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)$
    {
        expires      12h;
    }

    location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ {
        allow 127.0.0.1;
        deny all;
    }

    location ~* \.(ftpquota|htaccess|htpasswd|asa|mdb)?$ {
        deny all;
    }

    location ~ /node_modules/ {
        deny all;
    }
   location / {
	    try_files $uri $uri/ /index.php?$query_string;
   }
    access_log /var/log/nginx/index-access.log main; #access_log end
    error_log /var/log/nginx/index-error.log crit; #error_log end
}

5、调试

service mysqld restart
service nginx restart
php-fpm

If 不报错就代表操作成功啦!呵呵!

CentOS系列之LNPM环境搭建_第3张图片

你可能感兴趣的:(Linux)