centOS7 搭建lnmp環境

##centOS 7 環境下的 LNMP環境搭建 centOS 7 設置命令行模式 systemctl set-default multi-user.targetphp

####安裝編譯nginx nginx最新穩定版下載地址 http://nginx.org/en/download.htmlhtml

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
./configure --prefix=/usr/local/nginx

若是提示the HTTP rewrite module requires the PCRE library 就從http://pcre.org下載pcre庫,缺乏其餘庫相同操做。 nginx1.10+須要pcre、zlib以及openssl庫 若是在安裝編譯pcre的時候提示 You need a C++ compiler for C++ support ,就 yum -y gcc gcc-c++ nginx1.6版本以上須要指定庫source地址,幾個庫我都是下載在/usr/local/lib中,從新編譯mysql

./configure --prefix=/usr/local/nginx \
--with-pcre=/usr/local/lib/pcre \
--with-zlib=/usr/local/lib/zlib \
--with-openssl=/usr/local/lib/openssl
make && make install

當沒法經過時,檢查是否權限不夠。 啓動nginx ./sbin/nginxlinux

設置centOS 7中的靜態IP地址nginx

cd /etc/sysconfig/network-script
vim ifcfg-ens192

講BOOTPROTO改成"static",添加IPADDR 192.168.xx.xx,NETMASK,DNS,GATEWAY 若是系統中裝了iptables,在打開防火牆的狀況下,須要配置80端口經過防火牆c++


安裝PHP7

PHP7的下載地址http://ca1.php.net/get/php-7.1.0.tar.gz/from/this/mirrorsql

解壓查看./configure -help數據庫

# ./configure   --help
# ./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

使用yum一併安裝vim

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 上面的指令,而後make && make installapi

  1. 設置配置文件 cp /usr/local/scr/php/php.ini-production /usr/local/php/etc/php.ini
    php.ini-development 適合開發測試,如本地測試環境, php.ini-production擁有較高的安全性設定,適合服務器上線運營當產品。通常修改php.ini-production爲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/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  1. 加入服務 chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm 須要注意的是php7中www.conf這個配置文件配置phpfpm的端口號等信息,若是你修改默認的9000端口號需在這裏改,再改nginx的配置 啓動 /etc/init.d/php-fpm start

若是想將PHP加入全局變量,則在/etc/profile中最後一行加入

PATH=$PATH:/usr/local/php/bin
#保存並在命令行執行
source /etc/profile

整合nginx與php

***

vim /usr/local/nginx/conf/nginx.conf
sbin/nginx -s reload

去掉下面php的註釋,並將$DOCUMENT_ROOT改成php項目根路徑 nginx.conf


編譯安裝MySql

MySql的下載地址http://mirrors.sohu.com/mysql

  1. 下載解壓mysql二進制文件移動到/usr/local/mysql
tar zxf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
mv zxf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz /usr/local/mysql
  1. 建立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 ./
  1. 建立data文件夾存放數據,配置MySQL參數,記下生成的臨時密碼
mkdir data
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --explicit_defaults_for_timestamp

如我這裏的位n,y&ltEDa2sJ 4. 初始化數據庫

bin/mysql_ssl_rsa_ setup
  1. 修改配置文件
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 6. 啓動mysql並用生成的臨時密碼登陸,設置登陸密碼

cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql --u root -p
set password=password('123456');
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;

若是提示Can't connect to local MySQL server through socket '/tmp/mysql.sock' 就ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock 7. 添加系統路徑,配置開機啓動

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
相關文章
相關標籤/搜索