1、安裝 php
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repohtml
# yum install nginx php mysql php-mysql mysql-server php-cli php-curl php-fpm php-intl php-mcrypt php-gd php-mbstring php-xml php-dom -ymysql
2、部署mysql-server linux
# vi /etc/my.cnfnginx
[mysqld]web
datadir=/var/lib/mysqlsql
socket=/var/lib/mysql/mysql.sock數據庫
user=mysqlvim
log-bin=/var/lib/mysql/mysqld-binsession
log-bin-index=/var/lib/mysql/mysqld-bin
innodb_file_per_table
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# mysql_install_db --defaults-file=/etc/my.cnf
# service mysqld start
# mysql_secure_installation 注意在這裏設置數據庫root的密碼,注意記錄
3、部署php
告訴php,socket的具體路徑
# vi /etc/php.ini
mysql.default_socket = /var/lib/mysql/mysql.sock
mysqli.default_socket =/var/lib/mysql/mysql.sock
date.timezone = PRC #在946行 把前面的分號去掉,改成date.timezone = PRC
配置php-fpm
/etc/php-fpm.conf #主配置文件
# vim /etc/php-fpm.d/www.conf #編輯
listen = 127.0.0.1:9000 #默認9000<---讓php進程監聽本機9000端口
user = nginx #修改用戶爲nginx
group = nginx #修改組爲nginx
啓動php-fpm服務(其實就是啓動php相關進程,接受nginx的請求)
# service php-fpm start
4、配置nginx
簡單配置nginx,可以簡單運行靜態頁面
# vim /etc/nginx/nginx.conf
user nginx; #配置用戶或者組
worker_processes 1; #容許生成的進程數,默認爲1
error_log /var/log/nginx/error.log; #制定日誌路徑,級別。這個設置能夠放入全局塊,http塊,server塊,級別以此爲:debug|info|notice|warn|error|crit|alert|emerg
pid /var/run/nginx.pid; #指定nginx進程運行文件存放地址
events {
worker_connections 1024; #最大鏈接數
}
http { #http塊
include /etc/nginx/mime.types; #文件擴展名與文件類型映射表
default_type application/octet-stream; #默認文件類型,默認爲text/plain
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; #設置日誌格式與位置
sendfile on; #容許sendfile方式傳輸文件,能夠在http塊,server塊,location塊。
keepalive_timeout 65; #鏈接超時時間,能夠在http,server,location塊。
include /etc/nginx/conf.d/*.conf;
}
# service nginx start
測試:訪問IP
5、以虛擬主機的形式建立phpmyadmin
網站目錄定義在/web/myadmin
# vim /etc/nginx/conf.d/myadmin.conf
server {
listen 8080; #監聽端口
server_name php.senduy.xyz; #監聽地址
include /etc/nginx/default.d/*.conf;
location / {
root /web/myadmin; #根目錄
index index.html index.htm index.php; #增長index.php
}
location ~ \.php$ {
root /web/myadmin;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#變量改成$document_root$fastcgi_script_name
include fastcgi_params;
}
}
#Nginx是經過本機的9000端口將PHP請求轉發給PHP的,PHP本身是從本機的9000端口偵聽數據,Nginx與PHP經過本機的9000端口完成了數據請求。
創建測試頁面:
# vim /web/myadmin/index.php
<?php
phpinfo();
?>
# service nginx restart
測試:訪問IP:8080
而後將phpmyadmin的網頁文件放入/web/myadmin內
重啓服務後再進行訪問
6、錯誤處理
(1)***Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.***
報此錯誤或者輸入帳號密碼後扔彈回登錄界面,有多是/var/lib/php的權限問題
# chown nginx:nginx -R /var/lib/php
# service php-fpm restart
(2)phpmyadmin高級功能還沒有徹底設置部分功能未激活
# vim /web/myadmin/config.inc.php
/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = '';
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = '123456';
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
/* Contrib / Swekey authentication */
$cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
打開這些選項
(3)使用配置文件中定義的控制用戶鏈接失敗
# vim /web/myadmin/config.inc.php
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
將其改爲你的數據庫用戶和密碼,保存文件;
# chkconfig mysqld on
# chkconfig nginx on
# chkconfig php-fpm on
操做過程當中先是忘記關selinux,而後各類權限問題