CentOS7下LNMP环境搭建

CentOS7编译安装mysql-5.6.35

# yum -y install vim wget

http://mirrors.aliyun.com/repo/Centos-7.repo

# yum -y install gcc gcc-c++ cmake bison ncurses-devel autoconf perl perl-devel

https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

# cd /usr/local/src/

# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

# tar -zxvf mysql-5.6.35.tar.gz

# groupadd mysql

# useradd -g mysql -s /sbin/nologin mysql

# mkdir -p /data/mysq

# cd mysql-5.6.35

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql

# make && make install

# chown -R mysql:mysql /data/mysql

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

# cd /usr/local/mysql/

# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

# cd /usr/local/src/mysql-5.6.35

# cp support-files/my-default.cnf /etc/my.cnf

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

# chmod 755 /etc/init.d/mysqld

# vim /etc/init.d/mysqld

      basedir=/usr/local/mysql

      datadir=/data/mysql

# chkconfig --add mysqld

# chkconfig mysqld on

# service mysqld start

      Starting MySQL.Logging to '/data/mysql/yanghost1.localdomain.err'.

      SUCCESS!

配置环境变量

# vi /etc/profile

在后面加上

PATH=$PATH: /usr/local/mysql/bin:/usr/local/mysql/lib

export PATH

# source /etc/profile ==变量生效

# mysql -uroot -p  (登录mysql,密码初始化为空)

设置数据库管理员的登录密码:

# /usr/local/mysql/bin/mysqladmin -u root  password  'lemysql'

# systemctl status mysqld

# systemctl stop mysqld

# systemctl start mysqld

# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin:/usr/local/mysql/lib:/root/bin

CentOS7编译安装PHP5.6

Nginx中的PHP是以fastcgi的方式结合Nginx的,可以理解为Nginx代理了PHP的fastcgi,而httpd是把PHP作为自己的模块来调用的。

# cd /usr/local/src

# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz

# tar -xzvf php-5.6.30.tar.gz

# useradd -s /sbin/nologin php-fpm ==该账号用来运行php-fpm服务,在LNMP环境中,PHP以一个服务php-fpm的形式出现,独立存在于Linux系统中。

# yum groupinstall "Development Tools"

# yum -y install libxml2 libxml2-devel bzip2-devel curl curl-devel libjpeg-devel libpng libpng-devel libXpm-devel gcc gcc-c++ freetype-devel glib2-devel cairo-devel postgresql-devel libxslt libxslt-devel mysql-devel libcurl-devel

# cd php-5.6.30

./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl

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

# yum install -y epel-release

# yum install -y libmcrypt-devel

==两个不能一起安装,因为CentOs默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装libmcrypt。

# make && make install

# cp php.ini-production /usr/local/php-fpm/etc/php.ini

# vim /usr/local/php-fpm/etc/php-fpm.conf

添加下面内容

[global]

pid = /usr/local/php-fpm/var/run/php-fpm.pid

error_log = /usr/local/php-fpm/var/log/php-fpm.log

[www]

listen = /tmp/php-fcgi.sock

listen.mode = 666

user = php-fpm

group = php-fpm

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 3

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

# /usr/local/php-fpm/sbin/php-fpm -t  ==检测配置是否正确

启动php=fpm

# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# chmod 755 /etc/init.d/php-fpm

# service php-fpm start

设置php-fpm开机启动

# chkconfig php-fpm on

安装Nginx

http://nginx.org/download/nginx-1.14.1.tar.gz 建议安装stable版本

# cd /usr/local/src

# wget http://nginx.org/download/nginx-1.14.1.tar.gz

# tar xzvf nginx-1.14.1.tar.gz

# cd nginx-1.14.1

# ./configure --prefix=/usr/local/nginx

# make

# make install

编写Nginx启动脚本,并加系统服务

# vim /etc/init.d/nginx

      ==内容见代码D15Z\etc_init.d_nginx

# chmod 755 /etc/init.d/nginx

# chkconfig --add nginx

# chkconfig nginx on

更改Nginx的配置文件

# > /usr/local/nginx/conf/nginx.conf  ==清除内容

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

      ==内容见代码D15Z\nginx.conf

# /usr/local/nginx/sbin/nginx -t ==检验配置文件是否有问题

# service nginx start

# ps aux | grep nginx

# vim /usr/local/nginx/html/2.php ==加入PHP代码

# curl localhost/2.php ==测试

??? nginx服务器只能在本机访问

解决# firewall-cmd --zone=public --add-port=80/tcp --permanent   ==  添加端口

firewall-cmd --reload

firewall-cmd --zone= public --query-port=80/tcp

firewall-cmd --zone= public --remove-port=80/tcp --permanent

15.4 Nginx配置 P275

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

      在结束符号}之前添加 include vhost/*.conf; 加载虚拟主机配置文件

# cd /usr/local/nginx/conf

# mkdir vhost

# vim vhost/default.conf

server

{

      listen 80 default_server;  //default_server默认虚拟主机标记

      server_name aaa.com;

      index index.html index.htm index.php

      root /data/nginx/default;

}

# /usr/local/nginx/sbin/nginx -t

# /usr/local/nginx/sbin/nginx -s reload

# mkdir -p /data/nginx/default/

# echo "default_server" > /data/nginx/default/index.php

# curl -x127.0.0.1:80 aaa.com

出来还是主配置文件nginx.conf中的内容,vhost下的配置并未起作用,待调试。