Centos 7.6搭建LNMP環境的web伺服器
阿新 • • 發佈:2019-01-07
一.安裝軟體
1.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
重啟服務:
systemctl restart mysql 或
systemctl restart mysql.service
登入,並修改密碼:
mysql -u root mysql > use mysql; mysql > update user set password=password(‘123456‘) where user=‘root‘; mysql > flush privileges; mysql > exit;
1.2、nginx安裝
下載對應當前系統版本的nginx包
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
建立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
1.3安裝php
rpm 安裝 Php7 相應的 yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安裝php7.0
yum install -y php70w
安裝php擴充套件
yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64
安裝PHP FPM
yum install -y php70w-fpm
1.4、修改php-fpm配置檔案
php-fpm配置檔案位置:(/etc/php-fpm.d/www.conf)
user =nginx
group=nginx
放入測試檔案:
cd /usr/share/nginx/html echo 'hello eric' >index.php
1.5、啟動服務
啟動nginx服務
systemctl start nginx.service
檢視啟動狀態:
systemctl status nginx
看到截圖類容說明啟動成功!
啟動PHP-FPM:
systemctl start php-fpm.service
檢視啟動狀態:
systemctl status php-fpm.service
到這裡應該還是不能訪問的,原因是沒有開啟80埠
開啟80埠:
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
測試
在瀏覽器開啟http://192.168.2.76/index.php
看到 hello eric 就大功告成~