CentOS搭建LNMP環境

2022-03-28 18:37:31 字數 3500 閱讀 4694

1:檢視環境:

1 [root@localhost ~]# cat /etc/redhat-release
2:關掉防火牆

1

#開機禁用

2 [root@localhost ~]# chkconfig iptables off

3 ///centos7 systemctl disable firewalld4or

56#即時生效,重啟後失效

7 [root@localhost ~]# service iptables stop

///centos7 systemctl start firewalld

關閉selinux

#即時生效,重啟後失效

[root@localhost ~]#setenforce 0

//將selinux=enforcing修改為disabled然後重啟生效

[root@localhost ~]# vi /etc/selinux/config

3.配置centos 6.7 第三方yum源(centos預設的標準源裡沒有nginx軟體包)

4:安裝開發包和庫檔案

1

#注意不要換行

2 [root@localhost ~]#yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc

gcc-c++ libxpm libxpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

5:解除安裝已安裝的apache、mysql、php

6:安裝nginx

# yum

install

nginx

# service nginx start

///centos7 systemctl status nginx.service

# chkconfig --levels 235 nginx on //

設2、3、5級別開機啟動

///centos7 systemctl enable nginx.service

7:安裝mysql

# yum

install mysql mysql-server mysql-devel

# service mysqld start

# chkconfig --levels 235 mysqld on

//

登陸mysql刪除空使用者,修改root密碼

mysql>select

user,host,password from mysql.user;

mysql>drop user ''

@localhost;

mysql>update mysql.user set password = password('

your password

') where user='

root';

mysql>flush privileges;

8:安裝php

//

同樣注意不要換行

安裝php和所需元件使php支援mysql、fastcgi模式

#yum

install php-tidy php-common php-devel php-fpm php-mysql

# service php-fpm start

# chkconfig --levels 235 php-fpm on

9:配置nginx支援php

//

將配置檔案改為備份檔案

# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak

//由於原配置檔案要自己去寫因此可以使用預設的配置檔案作為配置檔案

# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

//修改nginx配置檔案server段,新增fastcgi支援

# vi /etc/nginx/nginx.conf

//加入index.php

index index.php index.html index.htm;

//將下列**注釋去掉,並修改成nginx預設路徑

location ~\.php$

10:配置php

//

編輯檔案php.ini,在檔案末尾新增cgi.fix_pathinfo = 1

[root@centos ~]# vi /etc/php.ini

11:重啟nginx php-fpm

# service nginx restart

# service php-fpm restart

12:建立info.php檔案

# vi /usr/share/nginx/html/info

.php

<?php

phpinfo();

?>

13:測試nginx是否可以解析php

本地瀏覽器輸入:192.168.32.164/info.php

顯示phpinfo介面 環境搭建成功

centos搭建LNMP環境

一 lnmp介紹 二 nginx安裝 5 通過chkconfig設定開機啟動 sudo chkconfig nginx on 4 檢視nginx版本 root izrj98p4hhys0y9fdxmcy4z yanmin nginx v nginx version nginx 1.12.1 三 my...

CentOS 環境下 搭建 LNMP環境

關掉防火牆,避免實驗中出現伺服器無法訪問的情況 chkconfig iptables off安裝lnmp環境所需的開發包和庫檔案 yum y install ntp make openssl openssl devel pcre pcre devel libpng libpng devel libj...

Centos下搭建LNMP環境

1.安裝nginx 關於nginx的安裝請參考 2.安裝二進位製包mysql useradd mysql m s sbin nologin tar zxvf mysql 5.5.32 linux2.6 x86 64.tar.gz mv mysql 5.5.32 linux2.6 x86 64 usr...