本地虛擬機LNMP環境安裝

 

首先上傳源碼包到linux中(本人上傳到根目錄中),隨意上傳能找到便可php

1、配置YUM(若是已經配好就不準要從新配置)html

掛載光驅要掛載到/mnt下  Mount /dev/cdrom /mntmysql

1.備份yum源目錄linux

 

[root@nage ~]# cp /etc/yum.repos.d /etc/yum.repos.d_baknginx

 

2.刪除yum源目錄中全部文件,並建立dvd.repoc++

 

[root@nage ~]# cd /etc/yum.repos.dsql

[root@nage yum.repos.d]# rm -rf ./*數據庫

[root@nage yum.repos.d]# touch dvd.repovim

 

3.dvd.repo中寫入如下幾行api

[root@nage yum.repos.d]# vi dvd.repo

 

[dvd]

name=install dvd

baseurl=file:///mnt

enabled=1

gpgcheck=0

 

2、YUM安裝系統所須要的依賴包

1.yum安裝,將如下幾行復制安裝便可

yum -y install yum-fastestmirror ntp

yum -y install patch make flex bison tar

yum -y install libtool libtool-libs kernel-devel

yum -y install libjpeg libjpeg-devel libpng libpng-devel

yum -y install libtiff libtiff-devel gettext gettext-devel

yum -y install libxml2 libxml2-devel zlib-devel  net-snmp

yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel

yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs

yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel

yum -y install openssl openssl-devel vim-minimal unzip

 

3、上傳源碼包到LINUX

1.將準備好的源碼包上傳到linux中(我存放在根目錄下)

 

 

4、安裝Nginx

1.安裝nginx組件

解壓包以前記得切換到源碼包所在目錄 [root@nage /]# cd /linux_nignx

 

yum -y install gcc gcc-c++ gcc-g77 flex bison tar libtool libtool-libs kernel-devel autoconf libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel gettext gettext-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel file glib2 glib2-devel bzip2diff* openldap-devel bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal unzip  automake make

 

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

 

 

2.安裝pcre (源碼包安裝)

 

1)解壓pcre包,進入解壓好的目錄

[root@nage linux_nignx]# tar -zxvf pcre-8.39.tar.gz

[root@nage linux_nignx]# cd pcre-8.39

 

(2)解析、編譯、安裝

[root@nage pcre-8.39]# ./configure

[root@nage pcre-8.39]# make && make install

3.安裝nginx

 

(1)解壓nginx包,進入目錄

[root@nage linux_nignx]# tar -zxvf nginx-1.8.0.tar.gz

[root@nage linux_nignx]# cd nginx-1.8.0

(2)解析、編譯、安裝

[root@nage linux_nignx]# ./configure

[root@nage linux_nignx]# make && make install

 

 

(3)啓動nginx

[root@nage linux_nignx]# cd /usr/local/nginx/sbin

[root@nage linux_nignx]# ./nginx

重啓[root@nage linux_nignx]# ./nginx –s

 

啓動nginx/usr/local/nginx/sbin/nginx  

重啓nginx: /usr/local/nginx/sbin/nginx -s reload

5、安裝Mysql

1.yum安裝依賴包

[root@nage linux_nignx]# yum -y install  gcc gcc-c++ gcc-g77 autoconf automake  fiex*  ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

[root@nage linux_nignx]# yum -y install cmake

 

2.建立mysql用戶

[root@nage linux_nignx]# useradd mysql

3.解壓mysql包,進入目錄

[root@nage linux_nignx]# tar -zxvf mysql-5.6.21.tar.gz

[root@nage linux_nignx]# cd mysql-5.6.21

4.解析、編譯、安裝

[root@nage mysql-5.6.21]# cmake .

[root@nage mysql-5.6.21]# make && make install

 

下面這項能夠延後處理,只是爲了用於登錄mysql使用的

5、修改mysql帳戶信息----默認狀況下是安裝在/usr/local/mysql

 

chown -R mysql.mysql /usr/local/mysql

cd /usr/local/mysql/scripts

./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 

cd /usr/local/mysql/support-files

cp mysql.server /etc/rc.d/init.d/mysql

cp my-default.cnf /etc/my.cnf

chkconfig --add mysql

chkconfig mysql on

service mysql start

 

修改密碼:/usr/local/mysql/bin/mysqladmin -u root password '123456'

 

登錄:/usr/local/mysql/bin/mysql -u root -p

 

 

修改遠程訪問權限:

 

1。 改表法。多是你的賬號不容許從遠程登錄,只能在localhost。這個時候只要在localhost的那臺電腦,登入mysql後,更改 "mysql" 數據庫裏的 "user" 表裏的 "host" 項,從"localhost"改稱"%"

 

Sql代碼 複製代碼

 

   1. mysql -u root -pvmwaremysql>use mysql;  

   2. mysql>update user set host = '%' where user = 'root';  

   3. mysql>select host, user from user;

 

2. 受權法。例如,你想myuser使用mypassword從任何主機鏈接到mysql服務器的話。

 

Sql代碼 複製代碼

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

 

FLUSH PRIVILEGES;

6、安裝PHP

1、安裝libi

[root@wenl linux_nignx]# tar -zxvf libiconv-1.14.tar.gz

 

[root@wenl linux_nignx]# cd libiconv-1.14

[root@wenl libiconv-1.14]#./configure help

[root@wenl libiconv-1.14]# ./configure --prefix=/usr/local

[root@wenl libiconv-1.14]# make && make install

2、安裝php

解壓php5.6之後進入解壓好的目錄,執行如下命令

[root@wenl php-5.6.3]# echo "/usr/local/lib">>/etc/ld.so.conf

[root@wenl php-5.6.3]# /sbin/ldconfig

 

[root@wenl php-5.6.3]# ./configure --enable-fpm --enable-mbstring --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mb --enable-bcmath --enable-mbstring --enable-sockets --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-t --with-zlib --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --with-iconv-dir=/usr/local

 

編譯完畢後,咱們再來make。在make時,咱們注意要加上-liconv參數。若是不加上-liconv參數,系統在make編譯會報錯。報錯信息以下:

 

Generating phar.php

 

//php-5.3.16/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

make: *** [sapi/cli/php] Error 1

 

使用命令以下:

make ZEND_EXTRA_LIBS='-liconv'

 

若是仍然報錯,執行如下操做

[root@wenl php-5.6.3]# cp ext/phar/phar.php ext/phar/phar.phar

[root@wenl php-5.6.3]# make test

[root@wenl php-5.6.3]# make install

 

 

三、配置環境變量

[root@wenl php-5.6.3]# echo "PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin">> /etc/profile

 

四、刷新系統變量

[root@wenl php-5.6.3]# source !$

 

五、配置php信息

[root@wenl php-5.6.3]# cp php.ini-production /usr/local/php/etc/php.ini

[root@wenl php-5.6.3]# cd /usr/local/php

[root@wenl php]# cp etc/php-fpm.conf.default etc/php-fpm.conf

[root@wenl php-5.6.3]# useradd www

[root@wenl php]# vi etc/php-fpm.conf

  user = nobody     改寫爲 user = www

     group = nobody           group = www

 

下面這段複製的命令看好本身的源碼包路徑

[root@wenl php]# cp /linux_nignx/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 

六、修改php-fpm權限並運行

[root@wenl php]# chmod 755 /etc/init.d/php-fpm

[root@wenl php]# /usr/local/php/sbin/php-fpm -t

 

七、啓動php-fpm

[root@wenl php]# service php-fpm start

 

八、添加php到系統服務

[root@wenl php]# chkconfig --add php-fpm && chkconfig php-fpm on

7、Nginx解析PHP

一、打開nginx配置文件

[root@wenl conf]# vi /usr/local/nginx/conf/nginx.conf

二、server內部對應位置加入如下配置信息

 location ~ .php$ {

                root html;

                fastcgi_pass 127.0.0.1:9000;

                fastcgi_index index.php;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                include fastcgi_params;

        }

 

三、重啓nginx搞定

相關文章
相關標籤/搜索