CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤

下面是CentOS6.4系统下编译安装LNMP和配置PHP环境的具体步骤:

一、安装LNMP

1.1 安装Nginx

首先安装Nginx,执行以下命令:

yum install gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel -y
mkdir -p /home/soft/src
cd /home/soft/src
wget http://nginx.org/download/nginx-1.19.7.tar.gz
tar -zxvf nginx-1.19.7.tar.gz
cd nginx-1.19.7
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module
make && make install

1.2 安装MySQL

接着安装MySQL,执行以下命令:

yum install mysql-server mysql mysql-devel libmysqlclient-dev -y
service mysqld start
chkconfig mysqld on
mysql -u root -p

1.3 安装PHP

然后安装PHP,执行以下命令:

yum install libxml2-devel openssl-devel bzip2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
mkdir -p /home/soft/src
cd /home/soft/src
wget https://www.php.net/distributions/php-7.4.16.tar.gz
tar -zxvf php-7.4.16.tar.gz
cd php-7.4.16
./configure --prefix=/usr/local/php --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --enable-ftp --with-gd --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache
make && make install

1.4 安装PHP扩展

接着安装PHP扩展,执行以下命令:

cd /home/soft/src/php-7.4.16/ext/mysqlnd
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
echo "extension=mysqlnd.so" >> /usr/local/php/etc/php.ini

1.5 修改配置文件

最后,修改配置文件,执行以下命令:

sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
cp /usr/local/nginx/conf/nginx.conf{,.bak}
cat > /usr/local/nginx/conf/nginx.conf <<EOF
user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '\$remote_addr - \$remote_user [\$time_local] "\$request" '
                      '\$status \$body_bytes_sent "\$http_referer" '
                      '"\$http_user_agent" "\$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
    include /usr/local/nginx/conf/vhost/*.conf;
}
EOF
service nginx start
chkconfig nginx on

二、配置PHP环境

2.1 修改PHP FPM

编辑/usr/local/php/etc/php-fpm.conf,修改以下选项:

user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

2.2 新建PHP FPM配置文件

新建 /usr/local/nginx/conf/vhost/test.conf 文件,并将以下内容保存到文件中:

server {
    listen       80;
    server_name  www.test.com;
    root   /data/wwwroot/test;

    location / {
        index index.php index.html index.htm;
    }

    location ~ \.php$ {
        fastcgi_pass  unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test$fastcgi_script_name;
        include fastcgi_params;
    }
}

其中,www.test.com是站点域名,/data/wwwroot/test是站点根目录。

2.3 重启PHP FPM和Nginx

执行以下命令:

/usr/local/php/sbin/php-fpm
service nginx restart

至此,CentOS6.4系统下编译安装LNMP和配置PHP环境的步骤已经全部完成了。其中示例说明有安装Nginx和MySQL、安装PHP扩展以及新建PHP FPM配置文件这两个步骤。

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤 - Python技术站

(0)
上一篇 2023年5月14日
下一篇 2023年5月14日

相关文章

  • Linux htpasswd命令

    Linux htpasswd命令用于管理Apache服务器的密码文件,可以用于创建、编辑或删除用户密码。用户密码可以用于基本身份验证(Basic Authentication)或摘要身份验证(Digest Authentication),以保护Web服务器中的页面或资源。 命令格式 htpasswd命令的语法格式如下: htpasswd [options] …

    Linux 2023年3月28日
    00
  • CentOS系统上OpenVZ虚拟机的安装和基本使用

    那我来为你详细讲解“CentOS系统上OpenVZ虚拟机的安装和基本使用”的完整攻略。 概述 OpenVZ是一个开源的虚拟化容器软件,可以让我们在一个物理主机上运行多个虚拟化操作系统。在本文中,我们将重点介绍CentOS系统上OpenVZ虚拟机的安装和基本使用。 安装OpenVZ 步骤1:确保系统满足要求 在开始安装OpenVZ之前,请确保您的CentOS系…

    Linux 2023年5月24日
    00
  • yum命令什么方法(更新软件、删除软件等)

    下面就对 yum 命令进行详细讲解。 什么是yum命令 yum 是一个用于在 CentOS/RHEL 等基于 Red Hat 的发行版本中进行软件包管理的命令行工具。yum 的全称是 Yellowdog Updater, Modified,它可以从指定的软件仓库中搜索、安装、删除和更新软件包。 yum命令常用操作 yum 命令常用的操作包括搜索、安装、更新和…

    Linux 2023年5月14日
    00
  • linux系统中的删除操作

    #rm [-fir] 文件或者目录 参数: -f:就是force的意思,忽略不存在的文件,不会出现警告信息; -i:互动模式,在删除前会询问用户是否操作; -r:递归删除。最常用的在目录删除。这是一个非常危险的参数!!!   范例一:删除bashrc #rm -i bashrc rm: remove regular file `bashrc’? y #如果加…

    Linux 2023年4月11日
    00
  • Linux下执行shell脚本出现-bash: ./stop.sh: /bin/bash^M: bad interpreter: No such file or directory问题

    问题描述:我在Windows下将shell脚本编写好上传至Linux服务器,chmod之后执行脚本出现如下问题 出现原因:Windows下编辑的shell脚本文件格式是dos,而Linux下需要unix格式的,可用vim编辑器查看文件格式按【ESC键>>按shift+冒号>>输入set  ff>>回车】 解决方案:将dos…

    Linux 2023年4月11日
    00
  • centos7 mysql数据库安装和配置

    下面是CentOS 7下MySQL数据库安装和配置的完整攻略。 步骤一:安装MySQL 首先,打开终端并使用以下命令更新服务器的软件包列表: sudo yum update 然后使用以下命令安装MySQL: sudo yum install mysql-server 步骤二:启动并启用MySQL 使用以下命令启动MySQL: sudo systemctl s…

    Linux 2023年5月14日
    00
  • linux系统安装出错提示this kernel requires an x86怎么办?

    Linux系统安装出错提示”This kernel requires an x86″的解决方案 问题描述 在安装 Linux 操作系统时,出现以下错误提示: This kernel requires an x86-64 CPU,but only detected an i686 CPU. Unable to boot – please use a kerne…

    Linux 2023年5月24日
    00
  • CentOS 7下部署php7.1和开启MySQL扩展的方法教程

    以下是“CentOS7下部署php7.1和开启MySQL扩展的方法教程”的完整攻略。 准备 在开始之前,请确保你的CentOS7系统已经安装了LAMP环境,并且MySQL服务已经启动。 安装EPEL源 在CentOS 7上安装PHP 7.1之前,我们需要先安装EPEL源。EPEL是“Extra Packages for Enterprise Linux”的缩…

    Linux 2023年5月14日
    00
合作推广
合作推广
分享本页
返回顶部