nginx命令
停止nginx服務:# /etc/init.d/nginx stop
啟動nginx服務:# /etc/init.d/nginx start
編輯nginx配置文件:# vim /etc/nginx/nginx.conf
/etc/init.d/php-fpm restart
service php-fpm start
最后只要 yum -y update 一下,全是最新的
別忘了開機啟動
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on
你可以用下列方法檢查配置文件是否有語法錯誤
# /etc/init.d/nginx configtest
問題:
1.打開phpmyadmin時出現mysqli擴展
設置:extension_ext = "/var/lib64/php/modules";
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.
首先看session.auto_start = 0,如果設置0不行,就設置1.
如果還不行,看session.save_path,看看這個路徑有沒有權限。
1.MySQL
yum源:http://dev.mysql.com/downloads/repo/yum/
配置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-png
ok