当前位置 : 主页 > 操作系统 > centos >

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

来源:互联网 收集:自由互联 发布时间:2023-07-29
下面是CentOS6.4系统下编译安装LNMP和配置PHP环境的具体步骤: 一、安装LNMP1.1 安装Nginx 首先安装Nginx,执行以下命令: yum install gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel p

下面是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扩展,执行以下命令:

自由互联热门推荐:PDF电子发票识别软件,一键识别电子发票并导入到Excel中!10大顶级数据挖掘软件!人工智能的十大作用!

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配置文件这两个步骤。

网友评论