標籤:arch 火牆 安裝完成 com 沒有許可權 reload ane 更新 mcr
安裝PHP&PHP-FPM
首先更新一下CentOS7系統,對系統軟體做一下升級,這裡不升級核心。
//使用root許可權,注意這裡使用upgrade,而不是update(它會升級核心,這裡我們不需要)yum upgrade
我需安裝最新的PHP,預設源安裝的PHP版本是5.4左右,差不多已經過時了,這裡先安裝新的源。
//安裝源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//安裝PHP和PHP-FPMyum install php71w php71w-cli php71w-fpm //安裝相關擴充yum install php71w-mbstring php71w-common yum install php71w-gd php71w-mcrypt yum install php71w-mysql php71w-xml yum install php71w-soap php71w-xmlrpc
安裝Nginx
Nginx是當下流行Web伺服器軟體,需要用它提供Web服務配置網站等。可選的還有Apache、Lighttpd等。
//安裝nginxyum install nginx //啟動nginxsystemctl start nginx //使用systemctl設定開機啟動systemctl enable nginx
根據之前設定的網路,可以直接在Mac瀏覽器裡面訪問http://192.168.56.101:80
看nginx是否已經啟動。我發現並不能訪問成功,這裡是CentOS7的防火牆導致的,開啟80連接埠
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
重試,顯示nginx歡迎頁面,Nginx設定成功。
安裝MySQL
MySQL是關係型資料庫軟體,用來儲存資料。安裝MySQL只需要簡單的指令,最新版本是5.7所以先安裝最新的源。
//安裝MySQL源yum install https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm//安裝MySQLyum install mysql-community-server//啟動MySQLsystemctl start mysqld //設定開機啟動systemctl enable mysqld//找到隨機產生的密碼grep ‘temporary password‘ /var/log/mysqld.log //登入mysql(需要上面的密碼)mysql -uroot -p‘xxxx‘
//更改密碼,密碼要求大寫字母、小寫字母以及數字和特殊符號
alter user ‘root‘@‘localhost‘ identified by ‘Qw.123456‘;
MySQL安裝完成。
設定Nginx和PHP-FPM
我已經安裝好需要程式,要想PHP請求被Nginx接收並轉交給PHP-FPM再由PHP解譯器執行返回結果,還需要做一些配置。
//啟動PHP-FPMsystemctl start php-fpm //設定開機啟動systemctl enable php-fpm
配置nginx網站(test.com為你的網域名稱):
vi /etc/nginx/conf.d/test.com.conf //寫入以下內容server { listen 80; server_name test.com; root /usr/share/nginx/html; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }}//重啟Nginxsystemctl restart nginx//在/usr/share/nginx/html增加phpinfo.php檔案寫入以下內容
<?php phpinfo();
開啟Mac的瀏覽器輸入http://test.com/phpinfo.php
就可以看到PHP的資訊了。如果報403,說明沒有許可權,試著設定檔案路徑的許可權chmod 777 -R
/usr/share/nginx/html.
如果設定之後還報File not found
,那可能是SELinux
限制了訪問,修改相關配置關閉SELinux。
vi /etc/sysconfig/selinux SELINUX=disabled //重啟系統reboot
重新整理瀏覽器,PHP資訊的頁面正常展示。 到此PHP環境就搭建OK了。
參考:CentOS 7 安裝PHP開發環境
CentOS 7 安裝PHP7+Nginx+Mysql5.7開發環境