當前位置:首頁 » 編程語言 » lnmp安裝php

lnmp安裝php

發布時間: 2023-04-01 20:17:52

A. 如何在lnmp上部署Thinkphp

ThinkPHP的四種URL模式:0(普通模式);1(PATHINFO模式);2(REWRITE模式);3(兼容模式)nginx需要PATHINFO模式,但需要更改nginx配置文件讓其支持PATHINFO模式。系統環境:系統:CentOS-6.4-x86_64web伺服器:nginx1.2.7PHP版本:PHP5.3.17資料庫版本:Mysql5.5.28一、安裝LNMP1.0一鍵安裝包按照以上版本安裝環境二、修改配置文件1.修改php配置文件php.ini,將其中cgi.fix_pathinfo=0,值改為1重啟php-fpm2.ssh里執行:cat>/usr/local/nginx/conf/pathinfo.conf<<'EOF'set$real_script_name$fastcgi_script_name;if($fastcgi_script_name~"(.+?\.php)(/.*)"){set$real_script_name$1;set$path_info$2;}fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;fastcgi_paramSCRIPT_NAME$real_script_name;fastcgi_paramPATH_INFO$path_info;EOF再將虛擬主機配置文件里的location~.*\.(php|php5)?$替換為:location~.*\.php再在includefcgi.conf;下面添加一行includepathinfo.conf;重啟nginx完整的虛擬主機配置文件如下:server { listen 80; server_namewww.lnmp.org; indexindex.htmlindex.htmindex.php; root /home/wwwroot/lnmp; location~.*\.php { try_files$uri=404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_indexindex.php; includefcgi.conf; includepathinfo.conf; } location/status{ stub_statuson; access_log off; } location~.*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location~.*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/lnmp.log lnmp;}將ThinkPHP的URL模式設置成PATHINFO。ThinkPHP就可以在nginx中運行了。

B. 請教,使用lnmp如何手動安裝配置php-fpm,謝謝大家

編譯安裝的時候有沒有log? 看log, 升級一下php試試

C. 怎麼安裝PHP環境

LAMP/LNMP 環境搭建

一.檢查系統環境

1.確認centos版本

[root@localhost ~]# cat /etc/redhat-release

2.檢查是否安裝過apache

rpm -qa | grep httpd

或者:

apachectl -v

或者:

httpd -v

3.檢查是否安裝過Mysql

service mysqld start

如果未被識別則沒有安裝

如果系統安裝過,或者安裝失敗,清理一下系統

4.清理Mysql痕跡

yum remove mysql

rm -f /etc/my.cnf

5.卸載Apache包

rpm -qa|grep httpd

注意:如果是新的系統或者你從來沒有嘗試安裝過,則以上步驟省略

二.安裝Apache、PHP、Mysql

停止防火牆服務

[root@localhost ~]# systemctl stop firewalld.service

禁用防火牆開機啟動服務

[root@localhost ~]# systemctl disable firewalld.service

1.安裝apache

[root@localhost ~]# yum -y install httpd

2.安裝php

[root@localhost ~]# yum -y install php

3.安裝php-fpm

[root@localhost ~]# yum -y install php-fpm

4.安裝Mysql

[root@localhost ~]# yum -y install mysql

5.安裝 mysql-server

[root@localhost ~]# yum install mariadb-server

CentOS 7+ 版本將MySQL資料庫軟體從默認的程序列表中移除,用mariadb代替了,entos7配置教程上,大多都是安裝mariadb,因為centos7默認將mariadb視作mysql。

因為mysql被oracle收購後,原作者擔心mysql閉源,所以又寫了一個mariadb,這個資料庫可以理解為mysql的分支。如果需要安裝mariadb,只需通過yum就可。

6.安裝 php-mysql

[root@localhost ~]# yum -y install php-mysql

三.安裝基本常用擴展包

1.安裝Apache擴展包

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

2.安裝PHP擴展包

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel

3.安裝Mysql擴展包

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

四.配置Apache、mysql開機啟動

重啟Apache、mysql服務(注意這里和centos6有區別,Cenots7+不能使用6的方式)

systemctl start httpd.service #啟動apache

systemctl stop httpd.service #停止apache

systemctl restart httpd.service #重啟apache

systemctl enable httpd.service #設置apache開機啟動

重啟資料庫

#啟動MariaDB

[root@localhost ~]# systemctl start mariadb.service

#停止MariaDB

[root@localhost ~]# systemctl stop mariadb.service

#重啟MariaDB

[root@localhost ~]# systemctl restart mariadb.service

#設置開機啟動

[root@localhost ~]# systemctl enable mariadb.service

五.配置Mysql

初次安裝mysql是沒有密碼的,我們要設置密碼,mysql的默認賬戶為root

方式1:設置 MySQL 數據 root 賬戶的密碼:

[root@localhost ~]# mysql_secure_installation

當出現如下提示時候直接按回車:

Enter current password for root

出現如下再次回車:

Set root password? [Y/n]

出現如下提示輸入你需要設置的密碼,這里輸入了root,輸入密碼是不顯示的,回車後再輸入一次確認:

New password:

接下來還會有四個確認,分別是:

Remove anonymous users? [Y/n]

Disallow root login remotely? [Y/n]

Remove test database and access to it? [Y/n]

Reload privilege tables now? [Y/n]

直接回車即可。

方式2:進入mysql mysql -r

修改mysql密碼:set password for 'root'@'localhost'=password('root');

mysql授權遠程連接(navicat等): grant all on *.* to root identified by 'root';

六.測試環境

我們在瀏覽器地址欄輸入http://ip/,正常顯示,說明我們的lamp 環境搭建成功

七.安裝nginx

yum install yum-priorities -y

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

Nginx 版本號可變更http://nginx.org/packages/centos/7/noarch/RPMS/$版本

八.配置nginx

1.nginx啟動,停止,重啟

systemctl start nginx.service #啟動nginx

systemctl stop nginx.service #停止

systemctl restart nginx.service #重啟

systemctl enable nginx.service #設置開機啟動

  • 更改nginx埠號(根據自己需求)

  • cd /etc/nginx/conf.d/

    vim default.conf

    把listen 80改成listen 81

    3.訪問http://ip:81即可看到nginx首頁

    安裝完成訪問時候需要啟動php-fpm,不重啟訪問會出現下載文件,重啟命令如下

    systemctl start php-fpm.service #啟動php-fpm

    systemctl enable php-fpm.service #設置開機啟動

    4.更改nginx配置文件識別php

    vi /etc/nginx/conf.d/default.conf,把之前的#給去掉就可以了,順手改一下

    location ~ .php$ {

    root html;

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;

    include fastcgi_params;

    }

    方法二 安裝nginx

    yum install nginx

    啟動nginx,並設置為開機啟動

    systemctl start nginx

    systemctl enable nginx

5.在 /usr/share/nginx/html中新建一個test.php

訪問http://ip:81/test.php即可看到php頁面

修改完成配置記得啟動apache 和php-fpm 哦!

九.負載配置

upstream site{

server 172.16.170.138;

server 172.16.170.139;

}

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log /var/log/nginx/log/host.access.log main;

location / {

root /usr/share/nginx/html;

index index.html index.htm;

proxy_pass http://site;

}

apache 默認目錄 /var/www/html

nginx 默認目錄 /usr/share/nginx/html

升級php版本

centos7 默認安裝php是5.4

查看yum的可安裝的php版本列表

yum provides php

開始升級PHP更新源:

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum remove php-common -y #移除系統自帶的php-common

php72版本

yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring

php56版本

yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring #安裝依賴包

查看php版本

php -v

安裝php fpm:

yum install php72w-fpm

yum provides php-fpm #因為我是准備搭建lnmp,所以安裝php-fpm,這里會提示多個安裝源,選擇5.6版本的安裝就可以了

yum install php56w-fpm-5.6.31-1.w7.x86_64 -y

systemctl start php-fpm.service 【啟動】

systemctl enable php-fpm.service【開機自啟動】

CentOS yum有時出現「Could not retrieve mirrorlist 」的解決辦法——resolv.conf的配置

原因:沒有配置resolv.conf

解決方法:

到/etc目錄下配置resolv.conf加入nameserver IP,如:

nameserver 8.8.8.8

nameserver 8.8.4.4

search localdomain

保存再次運行上面的命令就可以。

https://blog.csdn.net/mao834099514/article/details/73470001

nginx目錄 : /usr/share/nginx/html

/etc/nginx/conf.d/default.conf nginx配置目錄

apache目錄 : /var/www/html

/etc/httpd/conf/httpd.conf apache配置文件

nginx 配置域名

cd /etc/nginx

cp default.conf imooc.conf

修改server_name imooc.test.com 以及項目目錄

配置虛擬域名 windows 訪問需要在host增加 linuxip

ServerName www.nine.com

DocumentRoot "/var/www/html/learnlaravel/public"

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

關閉防火牆

setenforce 0

D. 如何在lnmp上部署Thinkphp

ThinkPHP的四種URL模式:0(普通模式);1(PATHINFO模式);2(REWRITE模式);3(兼容模式)

nginx需要PATHINFO模式,但需要更改nginx配置文件讓其支持PATHINFO模式。

系統環境:

系統:CentOS-6.4-x86_64

web伺服器:nginx1.2.7

PHP版本:PHP5.3.17

資料庫版本:MySQL5.5.28

一、安裝LNMP1.0一鍵安裝包:

http://lnmp.org/install.html

按照以上版本安裝環境

二、修改配置文件

1.修改php配置文件php.ini,將其中cgi.fix_pathinfo = 0,值改為1

重啟php-fpm

2.ssh里執行:

cat > /usr/local/nginx/conf/pathinfo.conf << 'EOF'
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "(.+?\.php)(/.*)") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

EOF

再將虛擬主機配置文件里的location ~ .*\.(php|php5)?$ 替換為:location ~ .*\.php
再在include fcgi.conf; 下面添加一行include pathinfo.conf;
重啟nginx

完整的虛擬主機配置文件如下:

server
{
listen 80;
server_name www.lnmp.org;
index index.html index.htm index.php;
root /home/wwwroot/lnmp;

location ~ .*\.php
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
include pathinfo.conf;
}

location /status {
stub_status on;
access_log off;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log /home/wwwlogs/lnmp.log lnmp;

}

將ThinkPHP的URL模式設置成PATHINFO。

ThinkPHP就可以在nginx中運行了。

熱點內容
windows上編譯器 發布:2024-04-18 09:35:24 瀏覽:205
如何發壓縮文件 發布:2024-04-18 09:35:19 瀏覽:276
白頭神探ftp 發布:2024-04-18 09:29:48 瀏覽:384
極速上傳工具 發布:2024-04-18 09:28:15 瀏覽:901
什麼是空調的配置 發布:2024-04-18 09:20:30 瀏覽:670
幾百人訪問需要什麼級別伺服器 發布:2024-04-18 09:20:18 瀏覽:489
17款傳奇什麼配置 發布:2024-04-18 09:06:43 瀏覽:698
圖層php 發布:2024-04-18 08:54:30 瀏覽:503
江西省資料庫 發布:2024-04-18 08:17:42 瀏覽:904
文件加密知乎 發布:2024-04-18 08:15:27 瀏覽:119