当前位置:首页 » 编程语言 » 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中运行了。

热点内容
微信墙完美版php源码 发布:2024-05-01 20:17:36 浏览:482
优酷上传视频软件 发布:2024-05-01 20:17:32 浏览:269
vc与数据库连接 发布:2024-05-01 20:16:37 浏览:997
天猫在哪里修改密码 发布:2024-05-01 19:58:59 浏览:734
安卓手机文件怎么收藏 发布:2024-05-01 19:50:22 浏览:333
mysql存储过程ifnull 发布:2024-05-01 19:27:11 浏览:254
台州华为云存储服务器 发布:2024-05-01 19:12:10 浏览:882
短租系统源码 发布:2024-05-01 18:59:11 浏览:636
深度优先算法广度优先算法 发布:2024-05-01 18:47:02 浏览:437
pythonlist索引获取 发布:2024-05-01 18:43:20 浏览:153