centos7 lnmp部署

来源:互联网 发布:淘宝主店分店 编辑:程序博客网 时间:2024/05/20 23:32

安装Nginx

cd /usr/local/src

wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tzr.gz
mv nginx-1.10.2 nginx
cd nginx
ll
yum install -y pcre-devel
yum install gcc gcc-c++ ncurses-devel perl
yum -y install make gcc gcc-c++ ncurses-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl--devel
./configure --prefix=/usr/local/nginx
make
make install
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
netstat -tunlp
/usr/local/nginx/sbin/nginx -s stop

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT




安装php

  cd php-7.1.0/
  ./configure --help
  ll
  yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel openssl openssl-devel curl curl-devel
  ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
 最后出现个报错 configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
  yum install libxslt-devel
  ./configure --prefix=/usr/local/php  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip
  make && make install
  cp /usr/local/src/php-7.1.0/php.ini-production /usr/local/php/etc/php.ini
  cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
  cp /usr/local/src/php-7.1.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  chmod --help
  chmod +x /etc/init.d/php-fpm
  chkconfig --add php-fpm
  chkconfig --help
  /etc/init.d/php-fpm start

php加入全局变量
  vim /etc/profile   在里面加入PATH=$PATH:/usr/local/php/bin
  source --help
  source /etc/profile

即可


整合Nginx和php

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

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

# deny access to .htaccess files, if Apache's document root

这两行中间的注释去掉  $fastcgi_script_name前面改为php网站放置的目录


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

测试下就可以了



安装MySQL

wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

下载完 解压后放到/usr/local/mysql

创建mysql组和用户,设置mysql不能登录,防止别人利用mysql账号登录主机,并更改目录所有者
groupadd mysql 
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
cd /usr/local/mysql
chown -R mysql ./
chgrp -R mysql ./

mkdir data
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --explicit_defaults_for_timestamp
A temporary password is generated for root@localhost: q>18mp-3keUw
初始化数据库
bin/mysql_ssl_rsa_setup
修改配置文件
cp /usr/local/mysql/support-files/my-defult.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
vim /etc/my.cnf
更改basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock
启动mysql并用生成的临时密码登录,设置登录密码
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql --u root -p
set password=password('root');
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
如果提示Can't connect to local MySQL server through socket '/tmp/mysql.sock' 就ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
添加系统路径,配置开机启动
vim /etc/profile
export  PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on


网上搜了看了很多  内容基本上都是借鉴网上的  php和mysql部分主要是参照 https://my.oschina.net/OSrainn/blog/804521  




后来装php53的时候 

configure: error: Unable to find your mysql installation

加上 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 可以了


后来装php53的时候 

configure: error: Unable to find your mysql installation

加上 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 可以了

原创粉丝点击