【ubuntu】 nginx配置php&wordpress


安裝nginx

sudo su

apt-get install nginx
安裝php

apt-get install php5
安裝php5-cgi

apt-get install  php5-cgi

安裝spawn-fcgi

apt-get install spawn-fcgi
啓動fastcgi

/usr/bin/spawn-fcgi.standalone -a 127.0.0.1 -p 9000 -C 8 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
啓動成功則顯示:spawn-fcgi: child spawned successfully: PID: 17686

修改nginx配置 我的nginx配置文件在(/opt/nginx/conf/nginx.conf)

vim /opt/nginx/conf/nginx.conf
其中有一段配置php的被註釋掉了,取消掉註釋。

location ~ \.php$ {
            #  root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  <span style="background-color: rgb(255, 0, 0);">/opt/nginx/html</span>$fastcgi_script_name;  (紅色部分爲html文件的路徑即根目錄)
            include        fastcgi_params;
        }

測試php

cd /opt/nginx/html
vim test.php
<?php phpinfo(); ?>   '將這句話寫在文件test.php文件中
http://localhost/test.php '在瀏覽器中輸入此路徑,可看到php信息頁面

安裝wordpress

cp /var/www/wordpress /opt/nginx/html   '就是將wordpress文件複製到html文件中去

http://localhost/wordpress//wp-admin/install.php '瀏覽器中輸入該網址進行安裝 


安裝好後若報錯 an error occured    Sorry, the page you are looking for is currently unavailable. Please try again later

解決:看 php-fpm是否有開啓

netstat -lnp | grep php-fpm

若沒有啓動,啓動php-fpm

/etc/init.d/php-fpm start

重啓好後刷新頁面會顯示wordpress安裝成功。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章