需求:在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 root mysql > use mysql; mysql > update user set password=password(‘123456‘) where user=‘root‘; mysql > exit;
2.2nginx安裝下載對應目前系統版本的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
2.3安裝php
rpm 安裝Php7 對應的yum來源
#合適rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.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
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 =nginx
group=nginx4.放入測試檔案
cd /forest/nginxDir/html echo '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 就大功告成~
systemctl enable php-fpm.service systemctl enable nginx.service如專案框架為lavarel,則設定檔可用下面這個:### ###
server { listen 80; server_name learn.laravel5.com; root /var/www/html/learnlaravel5/public; index index.html index.php; location / { try_files $uri $uri/ /index.php$is_args$query_string; } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
以上是如何在centos7.3系統下安裝php7.0的詳細內容。更多資訊請關注PHP中文網其他相關文章!