Centos7 yum安裝LNMP


1、Centos7系統庫中默認是沒有nginx的rpm包的,所以我們需要先更新下rpm依賴庫

 (1):使用yum安裝nginx,安裝nginx庫

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

 (2):使用下面命令安裝nginx

yum -y install nginx

 (3):啟動nginx

systemctl start nginx   #centos7

查看nginx版本
nginx -v

  nginx version: nginx/1.18.0

 (4):防火牆允許通過80端口-

查看防火牆狀態

systemctl status firewalld

 
查看防火牆開發端口
netstat -anp
 
查詢是否開啟80端口 
firewall-cmd --query-port=80/tcp
 
開通80端口
 firewall-cmd  --zone=public --add-port=80/tcp --permanent 

 (5):重啟防火牆

systemctl start firewalld

 (6):訪問網站,輸入服務器ip地址,查看是否出現 'Welcome To Nginx',如果想更改網站根目錄,修改地址:vim /etc/nginx/conf.d/default.conf,修改Root 后面的路徑

 

2、安裝Mysql,先更新yum源

 (1):yum源下載地址,根據自己需要的版本選擇相應的源

https://dev.mysql.com/downloads/repo/yum/

  (2):我們版本是6.x的,所以選擇linux 6 下載

wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm

  (3):安裝mysql的yum源

rpm -Uvh mysql57-community-release-el6-11.noarch.rpm
或
yum -y localinstall mysql57-community-release-el6-11.noarch.rpm

  (4):查看是否配置mysql源成功

在/etc/yum.repos.d下面

(5):安裝Mysql

yum -y install mysql-community-server
#時間有點長,稍微等一下

 (6):開始mysql服務

service mysqld start

  (7):Mysql安裝成功之后,會自動創建root的密碼,存儲在/var/log/mysqld.log,可以通過以下命令來查看

grep 'temporary password' /var/log/mysqld.log

  (8):登錄mysql,修改密碼

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wang123!';

  (9):開啟遠程鏈接,iptables開放3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent 

vim /etc/sysconfig/iptables (我自己沒找到這個文件,所以用上面命令開放了80和3306的端口)

  (10):重啟防火牆使iptables生效

systemctl start firewalld

3、安裝PHP(php-5.6)(根據自己要安裝的版本進行下載源碼包 https://www.php.net/releases/)

(1)cd /usr/local/src/

(2)下載:wget http://cn2.php.net/distributions/php-5.6.36.tar.gz

(3) 解壓源碼包,創建賬號

    tar zxf php-5.6.36.tar.gz

    useradd -s /sbin/nologin php-fpm

(4) 新建目錄:

    mkdir  /usr/local/php-fpm/etc

(5)配置編譯選項:#多了--enable-fpm,如果不加該參數,則不會有php-fpm執行文件生成,更不能啟動php-fpm服務

./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                

(6)可能會出現的錯誤

錯誤1:

checking for cc... no
checking for gcc... no
configure: error: in `/usr/local/src/php-5.6.36':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

# yum install -y gcc                #這里提示安裝gcc
#安裝完后繼續執行這一步
# ./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

錯誤2:

checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

# yum list |grep libxml2
libxml2.x86_64                              2.9.1-6.el7_2.3            @anaconda
libxml2.i686                                2.9.1-6.el7_2.3            base     
libxml2-devel.i686                          2.9.1-6.el7_2.3            base     
libxml2-devel.x86_64                        2.9.1-6.el7_2.3            base     
libxml2-python.x86_64                       2.9.1-6.el7_2.3            base     
libxml2-static.i686                         2.9.1-6.el7_2.3            base     
libxml2-static.x86_64                       2.9.1-6.el7_2.3            base     

# yum install -y libxml2-devel.x86_64                #安裝libxml-devel

#繼續執行這一步
 ./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                

錯誤3:

configure: error: Cannot find OpenSSL's <evp.h>

# yum install -y openssl openssl-devel                #安裝openssl和openssl-devel

#繼續執行這一步
 ./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                

錯誤4:

checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

# yum install -y libcurl-devel                #安裝libcurl-devel

#繼續執行這一步
 ./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                

錯誤5:

configure: error: jpeglib.h not found.

# yum -y install libjpeg-devel                #安裝libjpeg-devel
#繼續執行這一步
 ./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                

錯誤6:

configure: error: png.h not found.

# yum install -y libpng libpng-devel                #安裝libpng-devel

#繼續執行這一步
 ./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  

錯誤7:

configure: error: freetype-config not found.

# yum install -y freetype freetype-devel                #安裝freetype-devel

#繼續執行這一步
 ./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  

錯誤8:

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

# yum install -y epel-release

# yum install -y libmcrypt-devel                #安裝libmcrypt-devel(安裝之前要安裝epel-release這個擴展源)

#繼續執行這一步
 ./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                

(7)配置成功

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

(8)編譯php:

make

(9)安裝php

make install

(10)復制php配置文件到安裝目錄

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

vim /usr/local/php/etc/php.ini //display_errors = On,顯示錯誤信息

(11)復制啟動腳本

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

(12)修改php-fpm配置文件

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf

vim php-fpm.conf

 //去掉 pid = run/php-fpm.pid 前面的分號

(13)啟動php

/etc/init.d/php-fpm start //啟動

/etc/init.d/php-fpm stop //停止

/etc/init.d/php-fpm restart //重啟

ps -ef | grep php //查看php啟動狀態

(14)配置nginx.conf

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

(15)/usr/local/nginx/html中創建index.php,重啟php和nginx。

連接數據庫后的效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM