Centos 7 6搭建LNMP環境的web伺服器

2022-09-23 07:27:11 字數 3128 閱讀 2987

1.1.mysql安裝

wget http://

repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安裝mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝mysql

sudo yum install -y  mysql-server
重啟服務:

systemctl restart mysql 或

systemctl restart mysql.service

登入,並修改密碼:

mysql -u root

mysql >use mysql;

mysql > update user set password=password(‘123456‘) where user=‘root‘;

mysql > grant all on *.* to [email protected]'%' identified by '123456' with grant option; 

mysql >flush privileges;

mysql > exit;

修改yum源

rpm -uvh 

rpm -uvh

安裝 nginx、php

yum -y install nginx
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache 

php70w-pecl-redis php70w-pecl-mongo

配置預設編碼為utf8

vim /etc/my.cnf

設定開機啟動:

[[email protected] ~]# systemctl enable mysqld

預設配置檔案路徑:

配置檔案:/etc/my.cnf

日誌檔案:/var/log/mysqld.log

服務啟動指令碼:/usr/lib/systemd/system/mysqld.service

socket 檔案:/var/run/mysqld/mysqld.pid

配置 nginx

安裝完成以後檢視自己防火牆是否開啟,如果已開啟,我們需要修改防火牆配置,開啟nginx外網埠訪問。

[[email protected] ~]# systemctl status firewalld
如果顯示active (running),則需要調整防火牆規則的配置。

[[email protected] ~]# vim /etc/firewalld/zones/public

.xml

...

"nginx

"/>

[[email protected] ~]# systemctl reload firewalld

修改nginx配置:

[[email protected] ~]# vim /etc/nginx/nginx.conf

location / 

# php 指令碼請求全部**到 fastcgi處理. 使用fastcgi預設配置.

location ~ .php$

配置完成重啟nginx

[[email protected] ~]# systemctl start nginx    # 啟動 nginx

設定開機啟動:

[[email protected] ~]# systemctl enable nginx
3、設定開機啟動php-fpm

[[email protected] ~]# systemctl enable php-fpm

[[email protected] ~]# systemctl start php-fpm # 啟動 php-fpm

開啟80埠:

iptables -i input -p tcp -m state --state new -m tcp --dport 80 -j accept
放入測試檔案:

cd  /usr/share/nginx/htmlecho 

'<?php phpinfo(); ?>

' >info.php

​ 看啟動狀態:

systemctl status php-fpm.service