本文目錄一覽:
求大神指導Centos7 源碼編譯安裝Nginx+PHP 配置動靜分離
這個是我的服務的實際 將配置Nginx實現動靜分離,對php頁面的請求轉發給LAMP處理,而靜態頁面交給Nginx,以實現動靜分離。客戶請求靜態數據給Nginx,Nginx直接應答客戶端,當請求動態數據到Nginx時,Nginx讓客戶端去找LAMP,通過代理的方式,LAMP就和客戶端連接了。分別配置動態分離和靜態分離
(1)架設並調試後端LAMP架構,指定的域名,IP地址為xxxx,創建動態頁面test.php。
(2)配置Nginx(xxxx)處理動態頁面請求,並把域名改為 chaodiquan.com 在server{};段中加入以下代碼,檢測語法後,重啟Nginx
(3)客戶端輸入xxxx/test.php 成功後動態分離就實現了,接下來再配置靜態分離
(4)配置Nginx處理靜態頁面請求,在server{};中加入以下代碼,檢測語法後,重啟Nginx
location ~ .*\.(gif|jpg|jpeg|bmp|swf)$ { #這段代碼意思是任意網址以這5種格式為結尾就到Nginx根目錄下的html文件夾尋找資源
root html;
expires 1d; #緩存一天}
(5)在nginx的html目錄中,放入圖片aa.jpg,然後在apache的動態測試頁test.php中添加
html
body
img src=”aaaa/aa.jpg”
/body
/html
(6)客戶端輸入xxxx/test.php測試,由於test.php是動態頁面,因此客戶端會找到LAMP架構中的Apache,然後調取圖片aa.jpg是靜態數據,所以從Nginx提取,最後反饋給客戶端。這個是
阿里雲默認centos7上怎麼安裝php
首先更新系統軟體/str
$ yum update
安裝nginx/str/str
1.安裝nginx源
$ yum localinstall .安裝nginx
$ yum install nginx
3.啟動nginx
$ service nginx start
Redirecting to /bin/systemctl start nginx.service4.訪問http://你的ip/
如果成功安裝會出來nginx默認的歡迎界面
安裝MySQL5.7.*
/str
1.安裝mysql源/str
$ yum localinstall .安裝mysql
$ yum install mysql-community-server
確認一下mysql的版本,有時可能會提示mysql5.63.安裝mysql的開發包,以後會有用
$ yum install mysql-community-devel
4.啟動mysql
$ service mysqld start
Redirecting to /bin/systemctl start mysqld.service5.查看mysql啟動狀態
$ service mysqld status
出現pid
證明啟動成功
6.獲取mysql默認生成的密碼
$ grep ‘temporary password’ /var/log/mysqld.log2015-12-05T05:41:09.104758Z 1 [Note] A temporary password is generated for root@localhost: %G1Rgns!dD!v/str
加粗的就是生成的密碼
7.換成自己的密碼
$ mysql -uroot -p
Enter password:輸入上面的密碼
成功輸入後進入一下步,這裡你估計會輸入 好幾次才進去8. 更換密碼
mysql ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass4!’;這個密碼一定要足夠複雜,不然會不讓你改,提示密碼不合法;9.退出mysql;
mysql quit;
10.用新密碼再登錄,試一下新密碼
$ mysql -uroot -p
Enter password:輸入你的新密碼
11.確認密碼正確後,退出mysql;
mysql quit;
編譯安裝php7.0.0
/str
/str
1.下載php7源碼包/str
$ cd /root wget -O php7.tar.gz .解壓源碼包/str
$ tar -xvf php7.tar.gz
3./str
$ cd php-7.0.1
4.安裝php依賴包/str
/str
$ yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel5.編譯配置,這一步我們會遇到很多configure error,我們一一解決,基本都是相關軟體開發包沒有安裝導致/str
/str
$ ./configure \
–prefix=/usr/local/php \
–with-config-file-path=/etc \
–enable-fpm \
–with-fpm-user=nginx \
–with-fpm-group=nginx \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-soap \
–with-libxml-dir \
–with-xmlrpc \
–with-openssl \
–with-mcrypt \
–with-mhash \
–with-pcre-regex \
–with-sqlite3 \
–with-zlib \
–enable-bcmath \
–with-iconv \
–with-bz2 \
–enable-calendar \
–with-curl \
–with-cdb \
–enable-dom \
–enable-exif \
–enable-fileinfo \
–enable-filter \
–with-pcre-dir \
–enable-ftp \
–with-gd \
–with-openssl-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib-dir \
–with-freetype-dir \
–enable-gd-native-ttf \
–enable-gd-jis-conv \
–with-gettext \
–with-gmp \
–with-mhash \
–enable-json \
–enable-mbstring \
–enable-mbregex \
–enable-mbregex-backtrack \
–with-libmbfl \
–with-onig \
–enable-pdo \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-zlib-dir \
–with-pdo-sqlite \
–with-readline \
–enable-session \
–enable-shmop \
–enable-simplexml \
–enable-sockets \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–enable-wddx \
–with-libxml-dir \
–with-xsl \
–enable-zip \
–enable-mysqlnd-compression-support \
–with-pear \
–enable-opcache
configure error:
1.configure: error: xml2-config not found. Please check your libxml2 installation.
解決:
$ yum install libxml2 libxml2-devel
2.configure: error: Cannot find OpenSSL’s evp.h
解決:
$ yum install openssl openssl-devel
3.configure: error: Please reinstall the BZip2 distribution解決:
$ yum install bzip2 bzip2-devel
4.configure: error: Please reinstall the libcurl distribution – easy.h should be in curl-dir/include/curl/解決:
$ yum install libcurl libcurl-devel
5.If configure fails try –with-webp-dir=DIR configure: error: jpeglib.h not found.
解決:
$ yum install libjpeg libjpeg-devel
6.If configure fails try –with-webp-dir=DIR
checking for jpeg_read_header in -ljpeg… yesconfigure: error: png.h not found.
解決:
$ yum install libpng libpng-devel
7.If configure fails try –with-webp-dir=DIR
checking for jpeg_read_header in -ljpeg… yeschecking for png_write_image in -lpng… yesIf configure fails try –with-xpm-dir=DIR
configure: error: freetype-config not found.
解決:
$ yum install freetype freetype-devel
8.configure: error: Unable to locate gmp.h解決:
$ yum install gmp gmp-devel
9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決:
$ yum install libmcrypt libmcrypt-devel
10.configure: error: Please reinstall readline – I cannot find readline.h解決:
$ yum install readline readline-devel
11.configure: error: xslt-config not found. Please reinstall the libxslt = 1.1.0 distribution解決:
$ yum install libxslt libxslt-devel
6.編譯與安裝
$ make make install
這裡要make好久,要耐心一下
7.添加 PHP 命令到環境變數
$ vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動立即生效執行
$ ./etc/profile
或
$ source /etc/profile
查看環境變數
$ echo $PATH
查看php版本
$ php -v
8.配置php-fpm
$ cp php.ini-production /etc/php.ini
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf$ cp /usr/local/php/etc/php-fpm.d/ /usr/local/php/etc/php-fpm.d/ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm$ chmod +x /etc/init.d/php-fpm
9.啟動php-fpm
$ /etc/init.d/php-fpm start
配置nginx虛擬機,綁定域名/str
1.
/str
$ vim /etc/nginx/conf.d/php7.thinkcmf.com.conf這裡可以把php7.thinkcmf.com.conf改成自己的域名把下面的內容複製到php7.thinkcmf.com.conf里server{
listen 80;
server_name php7.thinkcmf.com;
root /var/www/html/php7.thinkcmf.com; # 該項要修改為你準備存放相關網頁的路徑location / {
index index.php index.html index.htm;
#如果請求既不是一個文件,也不是一個目錄,則執行一下重寫規則if (!-e $request_filename)
{
#地址作為將參數rewrite到index.php上。
rewrite ^/(.*)$ /index.php/$1;
#若是子目錄則使用下面這句,將subdir改成目錄名稱即可。
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;}
}
#proxy the php scripts to php-fpm
location ~ \.php {
include fastcgi_params;
##pathinfo支持start
#定義變數 $path_info ,用於存放pathinfo信息set $path_info “”;
#定義變數 $real_script_name,用於存放真實地址set $real_script_name $fastcgi_script_name;#如果地址與引號內的正則表達式匹配
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {#將文件地址賦值給變數 $real_script_name
set $real_script_name $1;
#將文件地址後的參數賦值給變數 $path_info
set $path_info $2;
}
#配置fastcgi的一些參數
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;fastcgi_param SCRIPT_NAME $real_script_name;fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
2.重啟nginx
$ service nginx reload
3.
$ vim /var/www/html/php7.thinkcmf.com/index.php/str
把下面的代碼複製到這個文件 里
?php
phpinfo();
4.查看訪問
centos7系統源碼編譯安裝PHP7.3.5版本
新增系統用戶組和用戶:
下載 PHP7.3.5
[root@localhost ~]# mkdir devdir
[root@localhost ~]# cd devdir/
[root@localhost devdir]# wget
-bash: wget: 未找到命令
[root@localhost devdir]# rpm -qa|grep wget
[root@localhost devdir]# yum -y install wget
[root@localhost devdir]# rpm -qa|grep wget
wget-1.14-18.el7.x86_64
下載PHP7 解壓 編譯
wget -c
編譯參數解釋
–with-fpm-user=webu –with-fpm-group=webg 添加PHP運行用戶和用戶組
配置信息出錯:
下載gcc軟體編譯器 yum install -y gcc
configure: error: libxml2 not found. Please check your libxml2 installation.
下載libzip-1.5.2.tar.gz
解決libzip 和cmake版本問題
重新配置PHP7編譯環境參數
libzip-1.5.2 無法安裝,已經取消了。
提示off_t類型沒有定義 undefind,解決方法:
編譯安裝
測試PHP是否安裝成功
轉載自:
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/303504.html