lnmp

Centos7安裝Lnmp環境nginx1.10.1-php5.6.22/7.0.7-mysql5.7.11

2015-01-13 15:26:51

更新時間:2016-06-04 11:18

準備工做php

     安裝make        yum -y install gcc automake autoconf libtool makehtml

     安裝g++          yum -y install gcc gcc-c++mysql

一、下載nginxlinux

           http://nginx.org/download/nginx-1.10.1.tar.gz​nginx

二、下載phpc++

           http://cn2.php.net/distributions/php-5.6.22.tar.gzgit

           http://cn2.php.net/distributions/php-7.0.7.tar.gz​web

三、下載mysql​sql

           http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz數據庫

1、安裝Nginx

下載pcre,是Nginx的重寫Rewrite,zlib爲了網頁Gzip壓縮,openssl加密傳輸

一、安裝pcre

    https://sourceforge.net/projects/pcre/files/pcre/

    下載:http://pilotfiber.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

    ①、首先看服務器是否已安裝pcre

    ​[root@localhost src]# rpm -qa pcre

    pcre-8.32-15.el7.x86_64

上面查到了pcre已存在,可是不是最新版的,我要安裝一個最新版的

​   ②、編譯安裝pcre

    ​[root@localhost src]# tar -zxf pcre-8.38.tar.gz

    ​[root@localhost src]# cd pcre-8.38

    ​[root@localhost pcre-8.38]# ./configure --prefix=/usr/local/pcre

    ​[root@localhost pcre-8.38]# make

    ​[root@localhost pcre-8.38]# make install

​   

二、安裝zlib

下載地址:http://zlib.net/zlib-1.2.8.tar.gz

    ​[root@localhost src]# wget http://zlib.net/zlib-1.2.8.tar.gz

    ​[root@localhost src]# tar -zxf zlib-1.2.8.tar.gz

    ​[root@localhost src]# cd zlib-1.2.8

    ​[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib

    ​[root@localhost zlib-1.2.8]# make && make install

   ​

三、安裝openssl

下載地址:http://www.openssl.org/source/openssl-1.0.1t.tar.gz​

    ​[root@localhost src]# wget http://www.openssl.org/source/openssl-1.0.1t.tar.gz

    ​[root@localhost src]# tar -zxf openssl-1.0.1t.tar.gz

    ​[root@localhost src]# cd openssl-1.0.1t

    ​[root@localhost openssl-1.0.1t]# ./config --prefix=/usr/local/openssl

    ​[root@localhost openssl-1.0.1t]# make && make install

    ​[root@localhost openssl-1.0.1t]# export PATH=$PATH:/usr/local/openssl/bin

    ​[root@localhost openssl-1.0.1t]# source /etc/profile

 

注意,這裏安裝是用config不是configure哦~~編譯相對比上面久一點

四、安裝gd庫

[root@localhost src]# yum -y install gd-devel​

五、安裝Nginx

[root@localhost nginx-1.10.1]# groupadd​ nginx​

[root@localhost nginx-1.10.1]# useradd -g nginx nginx -s /bin/false

[root@localhost nginx-1.10.1]# tar -zxf nginx-1.10.1.tar.gz​

[root@localhost nginx-1.10.1]# cd nginx-1.10.1

[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1t

[root@localhost nginx-1.10.1]# ​make && make install

小技巧:

       ./configure --help #能夠查看編譯選項,如上面的--with-http_ssl_module​

圖01    

【參考文獻】http://tengine.taobao.org/book/appendix_c.html#nginxlinux

​                    http://nginx.org/en/docs/configure.html

① 修改配置文件

​[root@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx.conf

將http -> server -> server_name改成服務器的外網ip地址,或你的網站域名​

② 啓動Nginx

[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx

Nginx安裝完畢,這個是在虛擬機上面安裝的,ip地址是192.168.1.202,這是咱們用瀏覽器訪問192.168.1.202,訪問失敗,什麼緣由,你應該很快想到是防火牆

③ 開機自啓動​​

方法一:在/etc/rc.d/rc.local文件裏面增長一行,以下

/usr/local/nginx/sbin/nginx

方法二:將nginx加入服務

在/etc/​rc.d/init.d/下面增長一個腳本,名稱 nginx,腳本內容查看這裏​

 

④ 防火牆配置

Centos6】​

一、要麼關閉防火牆 [root@localhost nginx-1.8.1]# service iptables stop

二、要麼配置防火牆

[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables

​在裏面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

保存退出,

[root@localhost202 nginx-1.8.1]#service iptables restart

重啓防火牆使配置生效​​

​Centos7】

systemctl stop firewalld.service //中止firewall

systemctl disable firewalld.service //禁止firewall開機啓動

​yum -y install iptables-services​

[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables

​在裏面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

​systemctl restart iptables.service #重啓防火牆使配置生效

systemctl enable iptables.service #設置防火牆開機啓動

 

⑤加入環境變量

​​[root@localhost ~]# vim /etc/profile​ # 在文件末尾增長以下內容

​#add by tomener ~ php mysql nginx openssl

​export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin:/usr/local/nginx/sbin:/usr/local/php/bin

​​[root@localhost ~]# source /etc/profile

3、安裝PHP

下載地址:http://cn2.php.net/distributions/php-5.6.19.tar.gz

一、安裝一些必要的工具和庫​

[root@localhost202 src]# yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \         zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \         ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \         krb5 krb5-devel libidn libidn-devel openssl openssl-devel

二、安裝php

[root@localhost202 src]# wget http://cn2.php.net/distributions/php-5.6.19.tar.gz

[root@localhost202 src]# tar -zxf php-5.6.19.tar.gz

[root@localhost202 src]# cd php-5.6.19

[root@localhost202 php-5.6.19]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir --with-xpm-dir=/usr/lib --with-zlib-dir=/usr/local/zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-opcache --enable-pcntl --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --with-xmlrpc --enable-zip --enable-soap --without-pear --with-mcrypt --with-curl --with-mhash --with-openssl=/usr/local/openssl

-------------------------------------小插曲 Start---------------------------------------

編譯時遇到一個錯誤:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

用rpm -qa|grep mcrypt  沒有查到,

用yum -list installed | grep mcrypt,也沒查到​​那咱們就來安裝一下了,

能夠用yum安裝,也能夠編譯安裝,

三、咱們就來編譯安裝libmcrypt

[root@localhost202 src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

[root@localhost202 src]# ​tar -zxf libmcrypt-2.5.8.tar.gz

[root@localhost202 src]# ​cd libmcrypt-2.5.8

[root@localhost202 libmcrypt-2.5.8]#./configure

[root@localhost202 libmcrypt-2.5.8]# make && make install

-------------------------------------小插曲 End---------------------------------------

configure success 圖02

./configure 後看見這個就表示配置沒問題了,開始下面的編譯和安裝

[root@localhost php-5.6.19]# make

Build complete 圖03          

編譯完了,看上面有一句Don't forget to run 'make test'.

那咱們就make test一下了

​[root@localhost php-5.6.19]# make test

make test  圖04  

測試了很久,是否是咱們不該該這麼聽話呢? 唉,慢慢等了~~~

[root@localhost php-5.6.19]# make install

make install success 圖05

PHP編譯安裝到此結束~~ , 下面咱們來配置php和php-fpm

一、php.ini配置

①查看php.ini配置文件的路徑​

[root@localhost php-5.6.19]# /usr/local/php/bin/php --ini

Configuration File (php.ini) Path: /usr/local/php/lib

顯示在lib下面,全部咱們應該拷貝源碼包裏面配置文件到/usr/local/php/lib下面

[root@localhost php-5.6.19]# cp php.ini-production /usr/local/php/lib/php.ini

​②配置php.ini

     A.關閉在http頭中顯示php版本信息​

​     expose_php = Off

     B. 設置時區

     date.timezone = PRC​

更多配置請查看 PHP7配置文件設置

二、php-fpm配置

[root@localhost php-5.6.19]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php54/etc/php-fpm.conf

① 去掉25行 ;pid = run/php-fpm.pid  前面的分號,是之生效

② 第148行改成 user = nginx 設置php-fpm運行帳號爲nginx,由於咱們安裝nginx的時候用的是nginx這個用戶,能夠看上面的nginx安裝那步。

③ 第149行改成 group = nginx #設置php-fpm運行組爲nginx,和上面一個原理

④ 設置socket的監聽

listen = /dev/shm/php-fpm.sock​

listen.owner = nginx​

listen.group = nginx

三、設置php-fpm開機自啓動

​[root@localhost php-5.4.36]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@localhost php-5.4.36]# chmod 0755 /etc/init.d/php-fpm

[root@localhost php-5.4.36]# chkconfig --level 35 php-fpm on

而後能夠用chkconfig --list 來查看是否將php-fpm添加到了自啓動​

四、啓動php-fpm

[root@localhost html]# /usr/local/php/sbin/php-fpm

固然,第3步咱們已經把php-fpm加入了開機自啓動,也就是加入了服務,全部,我就能夠用這樣的命令來控制php-fpm了:

​[root@localhost html]# service php-fpm start|restart|stop|reload|status|force-quit

五、配置nginx支持php腳本

修改哪裏呢?這還問麼,天然是nginx的配置文件了

​​[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf​

①頂部的user那行設置爲 user nginx nginx

②找到

location ​/ {

      root    html;

      index index.html index.htm

}​

改成:

​location ​/ {

      root    /data/webroot;

      index index.php index.html index.htm

}​​

③以下圖:

圖06    

 Nginx + PHP-FPM設置虛擬主機 + 開啓PATHINFO模式

六、重啓nginx

[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s reload

七、修改web根目錄的全部者所屬組

​[root@localhost nginx]# chown -R nginx:nginx /data/webroot

這步,先能夠不作​

八、測試php-fmp是否配置成功

[root@localhost nginx]# vim /usr/local/nginx/html/phpinfo.php

echo phpinfo();

:wq

http://localhost/phpinfo.php

--------------------------------------------------------------------------------------​

小提示:php核心編譯選項:http://php.net/manual/zh/configure.about.php

查看更多選項 ./configure --help 或者

./configure --help >> /data/php-configure.txt 從定向到文件,拿到本地來慢慢研究

2、安裝MySQL​

安裝一些必要的軟件:ncurses-devel、cmake

剛開始沒裝ncurses-devel,編譯不成功,而後yum install ncurses-devel,後面編譯就成功了。

MySQL從5.5開始使用cmake來編譯安裝了,

一、安裝cmake

下載地址:http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz​

    ​[root@localhost src]# wget http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz

    ​[root@localhost src]# tar -zxf cmake-3.1.0.tar.gz

    ​[root@localhost src]# cd cmake-3.1.0

    ​[root@localhost cmake-3.1.0]# ./configure --prefix=/usr/local/cmake

    ​[root@localhost cmake-3.1.0]# make

    ​[root@localhost cmake-3.1.0]# make install

​    [root@localhost cmake-3.1.0]# export PATH=$PATH:/usr/local/openssl/bin​

    [root@localhost cmake-3.1.0]# source /etc/profile

 

 

小提示:下載有點滿,5.7M下了10多分鐘~~,查看cmake是否安裝:

which cmake 或者 whereis cmake

二、安裝MySQL

下載地址:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz

                 http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

    ​[root@localhost src]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz

    ​[root@localhost src]# tar -zxf mysql-5.6.22.tar.gz

    ​[root@localhost src]# cd mysql-5.6.22

    ​[root@localhost mysql-5.6.22]# groupadd mysql

    ​[root@localhost mysql-5.6.22]# useradd -g mysql mysql -s /bin/false

    ​[root@localhost mysql-5.6.22]# mkdir -p /usr/local/mysql

    ​[root@localhost mysql-5.6.22]# mkdir -p /data/mysql

    [root@localhost mysql-5.6.22]# chown -R mysql:mysql /data/mysql

    ​[root@localhost mysql-5.6.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci​​

    ​[root@localhost mysql-5.6.22]# make

    ​[root@localhost mysql-5.6.22]# make install

    ​[root@localhost mysql-5.6.22]# cd /usr/local/mysql

 

5.7版本在cmake的時候須要增長兩個參數  -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost​​

小提示:若是cmake後出錯,需刪除mysql-5.6.22目錄下面的CMakeCache.txt這個文件後再cmake,我就是開始cmake出錯了,安裝了ncurses-devel後再cmake

 

參考文獻:http://my.oschina.net/looly/blog/297980

編譯參數:

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

可能遇到問題:

一、Warning: Bison executable not found in PATH
​解決: yum -y install bison

二、Could NOT find Git (missing: GIT_EXECUTABLE)​

解決: yum -y install git

~~~~~~~~~~~~~MySQL安裝完畢~~~~~~~~~~~​

配置MySQL​

一、初始化mysql數據庫

​[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb/ #生成mysql系統數據庫

二、複製mysql服務啓動配置文件

[root@localhost support-files]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

三、複製mysql服務啓動腳本及加入PATH路徑

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# vim /etc/profile #編輯profile添加環境變量

在profile最後加上:
​# add by Tomener ~ mysql,openssl

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

保存退出​​

[root@localhost mysql]# source /etc/​profile

四、啓動MySQL

[root@localhost202 mysql]# service mysqld start

Starting MySQL... SUCCESS!

​五、將MySQL加入開機自啓動

[root@localhost202 mysql]# chkconfig --level 35 mysqld on​

六、檢查MySQL是否已啓動

[root@localhost202 mysql]# netstat -ntpl | grep mysql​

看見3306端口就表示啓動了~~

七、用mysql客服端登陸

​[root@localhost202 mysql]# mysql -u root -p

密碼是空的,直接回車

八、修改MySQL的root密碼

[root@localhost202 mysql]# mysql_secure_installation​

這裏能夠設置root的密碼(咱們設置爲tomenr888),刪除匿名用戶,設置是否阻止root賬號遠程登陸,是否刪除test庫,是否重新加載權限表

第二種方法,通常安裝完MySQL後root密碼都爲空,咱們能夠mysql客服端裏面修改

mysql> set password for root@localhost = password('tomener888');

Query OK, 0 rows affected (0.10 sec)​

固然設置root的密碼有不少方法,可自行百度

九、添加MySQL用戶

​首先進入mysql客服端

[root@localhost202 mysql]#mysql -u root -p

mysql>​create user 'tomener'@'localhost' IDENTIFIED BY 'tomenr888';

 更多關於MySQL用戶知識,請看我以前的一篇文章:

http://blog.sina.com.cn/s/blog_75ad10100101o3hi.html

完畢~~

本文來自:http://blog.sina.com.cn/tomener

原文連接:​http://blog.sina.com.cn/s/blog_75ad10100102vc14.html

相關文章
相關標籤/搜索