本文實例講述了Centos7.3服務器搭建LNMP環境的方法。分享給大家供大家參考,具體如下:
需求:在Centos7.3下搭建LNMP環境
1. 關閉防火墻和selinux
打開文件selinux
vim /etc/sysconfig/selinux
將文件中SELINUX=enforcing改為disabled,然后執行”setenforce 0″不用重啟地關閉selinux。
SELINUX=disabled
關閉放火墻
systemctl stop firewalld.service
2.安裝軟件
2.1 MYSQL安裝
下載mysql的repo源
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
更改MYSQL用戶權限:
sudo chown -R root:root /var/lib/mysql
重啟服務:
systemctl restart mysql.service
登錄,并修改密碼:
mysql -u rootmysql > use mysql;mysql > update user set password=password(‘123456‘) where user='root';mysql > flush privilgegs;mysql > exit;
2.2 nginx安裝
下載對應當前系統版本的nginx包
建立nginx的yum倉庫(默認yum是沒有nginx的)
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
下載并安裝nginx
?yum install -y nginx
nginx啟動
systemctl start nginx.service
2.3 安裝php
rpm 安裝 Php7 相應的 yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安裝php7.0
yum install -y php70w
安裝php擴展
安裝PHP FPM
yum install -y php70w-fpm
3. 修改配置文件
3.1修改Nginx配置文件
nginx配置文件位置:(/etc/nginx/conf.d/default.conf)
vim /etc/nginx/conf.d/default.conf
修改 root目錄,可自定義:
root /forest/nginxDir/html;
修改配置php解析:
location ~.php$ { root /forest/nginxDir/html;? fastcgi_pass 127.0.0.1:9000;? fastcgi_index index.php;?fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;? include fastcgi_params;}
3.2 修改php-fpm配置文件
php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)
修改
user =nginxgroup=nginx
4.放入測試文件
cd /forest/nginxDir/htmlecho 'hello eric' >index.php
5.啟動服務
5.1 啟動nginx服務:
systemctl start nginx.service
查看啟動狀態:
systemctl status nginx
看到以下字眼說明啟動成功!
?Active: active (running) since 六 2016-11-19 13:40:04 CST; 50min ago
5.2 啟動PHP-FPM:
systemctl start php-fpm.service
查看啟動狀態:
systemctl status php-fpm.service
看到以下字眼說明啟動成功!
?Active: active (running) since 六 2016-11-19 14:14:33 CST; 18min ago
6.測試
在瀏覽器打開192.168.44.129:80/index.php
看到 hello eric 就大功告成~
希望本文所述對大家CentOS服務器配置有所幫助。
新聞熱點
疑難解答
圖片精選