nginx命令
中止nginx服務:# /etc/init.d/nginx stop
啓動nginx服務:# /etc/init.d/nginx start
編輯nginx配置文件:# vim /etc/nginx/nginx.confphp
/etc/init.d/php-fpm restart
service php-fpm starthtml
最後只要 yum -y update 一下,全是最新的
別忘了開機啓動
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx onmysql
你能夠用下列方法檢查配置文件是否有語法錯誤
# /etc/init.d/nginx configtest linux
問題:nginx
1.打開phpmyadmin時出現mysqli擴展c++
設置:extension_ext = "/var/lib64/php/modules";web
2.打開phpmyadmin時,出現:Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.sql
首先看session.auto_start = 0,若是設置0不行,就設置1.
若是還不行,看session.save_path,看看這個路徑有沒有權限。apache
1.MySQL
yum源:http://dev.mysql.com/downloads/repo/yum/ vim
配置yum源:http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html
# yum -y install mysql-server
# chkconfig mysqld on
# service mysqld start
2.Nginx.
在/etc/yum.repos.d/目錄下創建一個nginx.repo軟件源配置文件。命令以下:
# cd /etc/yum.repos.d/
# vim
而後填寫以下文件內容
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
注意:必定要看這句話(參考:http://nginx.org/en/linux_packages.html#stable)
執行vim命令保存文件爲nginx.repo完整路徑是/etc/yum.repos.d/nginx.repo
:w
執行yum命令安裝nginx
yum install nginx
添加防火牆
在安裝完成nginx後,須要設置防火牆設置容許80端口,操做以下:
# vim /etc/sysconfig/iptables
添加一行
-A INPUT –m state –state NEW –m tcp –p tcp –dport 80 –j ACCEPT
在修改完防火牆後須要執行以下命令重啓防火
# /etc/init.d/iptables restart
緊接着啓動nginx
# /etc/init.d/nginx start
而後保存並退出:wq
nginx僞靜態:
1.將include /www/web1.nginx加入到nginx的虛擬機配置文件中,
加入到location / {}部分。
2.僞靜態文件:
rewrite ^/about\.html$ /?do=profile last;
注意:1.前部分須要加根目錄斜線"/";
2.將RewriteRule改爲rewrite;
3.末尾加上 last;
編譯安裝:(參考:http://lxsym.blog.51cto.com/1364623/293096)
安裝PHP(PHP5.3之後,php-fpm就是php的核心模塊存在了)
這個地方是最重要的地方,由於默認狀況下Nginx和PHP他倆之間是一點感受沒有的。在以前,不少朋友都搭建過Apache+PHP,Apache+PHP編譯後生成的是模塊文件,而Nginx+PHP須要PHP生成可執行文件才能夠,因此要利用fastcgi技術來實現Nginx與PHP的整合,這個只要咱們安裝是啓用FastCGI便可。這次咱們安裝PHP不只使用了FastCGI,並且還使用了PHP-FPM這麼一個東東,PHP-FPM說白了是一個管理FastCGI的一個管理器,它做爲PHP的插件純在,在安裝PHP要想使用PHP-FPM時就須要把PHP-FPM以補丁的形式安裝到PHP中,並且PHP要與PHP-FPM版本一致,這是必須的,切記!
整合Nginx與PHP
上面已經講過,Nginx本身並不處理動態網頁的請求,並且Nginx將獲得的動態請求轉交給PHP,下面咱們打開Nginx的配置文件看一下
#vi /etc/nginx/conf.d/default.conf
看上圖,Nginx已經知道怎麼把獲得的請求傳達給PHP,Nginx在獲得*.php請求時,會把請求經過9000端口傳給PHP。
那麼只有Nginx本身知道咋找PHP了還不行,還須要PHP知道咋找Nginx,PS:你見過大街上的JJMM約會時有不是相互認識對方,或者是不知道用啥方法和對方接頭的?這點咱們不須要擔憂,PHP-FPM已經在配置文件中定義了從哪接受PHP請求,咱們能夠打開配置文件看一下
#vi /etc/php-fpm.d/www.conf
如上圖所示,咱們在前面已經看到過Nginx是經過本機的9000端口將PHP請求轉發給PHP的,而上圖咱們能夠看到PHP本身是從本機的9000端口偵聽數據 ,Nginx與PHP經過本機的9000端口完成了數據請求。
php源碼安裝:
1.cd /usr/local/php/
wget http://cn2.php.net/distributions/php-5.6.8.tar.gz
2.
./configure --prefix=/usr/local/php --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache2/bin/apxs
PHP編譯安裝出現的各類問題:
php版本:php-5.4.3
安裝前.先安裝些軟件和庫文件
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
領導要咱們本身手動裝 不容許咱們直接用yum 因此上面的都沒執行
編譯安裝PHP
進入php的解壓目錄
./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype
運行以後遇到的問題:
error 1
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
(看提示就明白 是一個lib庫沒裝 先用 yum search 名字 看是否能搜到名字 ,找到名字後 把軟件包 開發包裝上)
解決辦法
yum install libxml2-devel.x86_64
error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
這是ssl沒裝
解決辦法
yum install openssl.x86_64 openssl-devel.x86_64 -y
error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
這是bzip2軟件包沒有安裝
解決辦法
yum install bzip2-devel.x86_64 -y
error 4
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
curl和curl庫文件沒有安裝
解決辦法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y
error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found
GD庫沒有安裝
解決辦法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt庫沒有安裝 ,要是不能用yun安裝的話 就要去下載個gz包 本身編譯安裝
(編譯安裝 ./configure --piefix=/usr/local/libmcrypt make && make install)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
要是錯誤裏面含有mysql的 那是mysql-devel 沒有安裝
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
出現
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
編譯PHP的--with-gd=/usr/include錯誤提示:configure: error: Unable to find gd.h anywhere under代表已經裝好GD庫啦,把後面的路徑取消就能夠啦--with-gd --with-jpeg --with-pngok