搜尋
首頁後端開發PHP問題linux 虛擬機器上怎麼安裝php

linux 虛擬機器上怎麼安裝php

May 27, 2021 am 09:57 AM
linuxphp

linux虚拟机上安装php的方法:1、安装依赖包;2、安装libmcrypt;3、通过“wget”下载PHP并使用“tar -zxvf”进行解压安装;4、配置域名;5、分割日志;6、在主机的hosts里,将域名指向虚拟机的IP即可。

linux 虛擬機器上怎麼安裝php

本文操作环境:linux5.9.8系统、PHP7.0.2版,DELL G3电脑

linux 虚拟机 安装 php-7.0.2

1.安装依赖包  

yum -y install libxml2 libxml2-devel openssl openssl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
yum -y install bzip2 bzip2-devel libcurl libcurl-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel

2. 安装libmcrypt

    -> wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
    -> tar -zxvf libmcrypt-2.5.8.tar.gz
    -> cd libmcrypt-2.5.8
    -> ./configure
    -> make && make install

3. 安装PHP7

   -> wget http://cn2.php.net/get/php-7.0.2.tar.gz  下载 php-7.0.2.tar.gz
    -> tar -zxvf php-7.0.2.tar.gz 解压缩
    -> cd php-7.0.2 进入目录
    -> ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-openssl-dir --with-mcrypt --with-mhash --with-pcre-regex --with-pcre-dir --with-sqlite3 --with-zlib --with-zlib-dir --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gmp --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --enable-mysqlnd-compression-support --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xsl --enable-zip --with-pear --enable-opcache

注:

        --prefix=/usr/local/php         指定 php 安装目录
        --with-config-file-path=/etc     设置php.ini的搜索路径。默认为PREFIX/lib
        --enable-fpm                     打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序
        --with-fpm-user=www 
        --with-fpm-group=www
        --enable-inline-optimization     优化线程
        --disable-debug                 关闭调试模式
        --disable-rpath                 关闭额外的运行库文件 
        --enable-shared                 编译共享库,默认yes
        --enable-soap                    soap模块
        --with-libxml-dir                 打开libxml2库的支持
        --with-xmlrpc                    打开xml-rpc的c语言 
        --with-openssl                     openssl的支持,加密传输时用到的
        --with-mcrypt                     mcrypt算法(函数库需要安装)
        --with-mhash                     mhash算法(函数库需要安装)
        --with-pcre-regex                 定 PCRE 包含文件和库文件路径
        --with-sqlite3 
        --with-zlib                     打开zlib库的支持
        --enable-bcmath                 打开图片大小调整,用到zabbix监控的时候用到了这个模块
        --with-iconv
        --with-bz2                         打开对bz2文件的支持
        --enable-calendar                 打开日历扩展功能
        --with-curl                     打开curl浏览工具的支持
        --with-cdb 
        --enable-dom 
        --enable-exif                     图片的元数据支持 
        --enable-fileinfo 
        --enable-filter 
        --with-pcre-dir                 perl的正则库安装位置
        --enable-ftp                     打开ftp的支持
        --with-gd                         打开gd库的支持 
        --with-openssl-dir
        --with-jpeg-dir                 打开对jpeg图片的支持
        --with-png-dir                     打开对png图片的支持 
        --with-zlib-dir                    打开zlib库的支持
        --with-freetype-dir             打开对freetype字体库的支持
        --enable-gd-native-ttf            支持TrueType字符串函数库
        --enable-gd-jis-conv 
        --with-gettext                     打开gnu 的gettext 支持,编码库用到
        --with-gmp 
        --enable-json
        --enable-mbstring                  多字节,字符串的支持
        --enable-mbregex 
        --enable-mbregex-backtrack 
        --with-libmbfl
        --with-onig
        --enable-pdo
        --with-mysqli=mysqlnd             mysql安装目录,对mysql的支持
        --with-pdo-mysql=mysqlnd
        --with-pdo-sqlite
        --with-readline
        --enable-session
        --enable-shmop
        --enable-simplexml
        --enable-sockets                  打开 sockets 支持
        --enable-sysvmsg
        --enable-sysvsem
        --enable-sysvshm
        --enable-wddx
        --with-xsl                         打开XSLT文件支持,扩展了libXML2库 ,需要libxslt软件
        --enable-zip                     打开对zip的支持 
        --enable-mysqlnd-compression-support 
        --with-pear                      打开pear命令的支持,PHP扩展用的 
        --enable-opcache

-> 报错解决

        报错1-> configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
        解决1-> 编辑 /etc/ld.so.conf 加入/usr/local/lib,在执行ldconfig
   -> make
    -> make install

推荐学习:《PHP视频教程

    -> 配置
    -> cp php.ini-development /etc/php.ini 复制配置文件 php.ini-development
    -> cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    -> vim /usr/local/php/etc/php-fpm.conf
       
       pid = /var/run/php-fpm.pid 去掉前面的分号
       error_log = /data/logs/php-fpm/php-fpm.log 去掉前面的分号
    -> cd /usr/local/php/etc/php-fpm.d
    -> cp www.conf.default www.conf 根据需求配置
    -> /usr/local/php/sbin/php-fpm 启动php-fpm
    -> kill -INT `cat /var/run/php-fpm.pid` 关闭php-fpm   
       /usr/local/php/var/run/php-fpm.pid
    -> kill -USR2 `cat /var/run/php-fpm.pid` 重启php-fpm

4. 配置域名

-> cd /usr/local/nginx/conf/vhost/
    -> vim www.test.com.conf
        upstream testphpfpm 
        {
            server 127.0.0.1:9000;
        }
        log_format  testaccess  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" $http_x_forwarded_for';
        server 
        {
            listen    80;
            server_name xxx.xxx.xxx;
            index  index.shtml index.html index.htm;
            root /data/www/project;
            
            ssi on;
            ssi_silent_errors on;
            ssi_types text/shtml;
            #error_page 404 = http://xxx.xxx.xxx;
            location ~ \.php$ 
            {
                alias  /data/www/project;
                fastcgi_pass  testphpfpm;
                fastcgi_index  index.php;
                include fastcgi.conf;
                
            }
            
    /*下面两个IF 是兼容 CI框架  否则CI框架项目无法使用*/
    if ($request_uri ~* "^/(static|data|install|\.)/.*"){
                set $rule  '1';
            }
            if ($rule !~ '1'){
                rewrite ^/(.+)$ /index.php?/$1 last;
            }
            
            
            access_log  /data/logs/nginx/xxx.xxx.xxx.log  testaccess;
        }
    -> :wq 保存退出

5. 分割日志

  -> 创建脚本目录
    -> cd /data
    -> mkdir scripts
    -> cd scripts
    -> vim nginx_log_splid.sh
        #!/bin/sh
        LOGDIR ="/data/logs/nginx"
        FILEDAY = `date -d "-1 days" +%Y%m%d`
        /bin/mv  $nginx_log_dir/www.test.com.log $LOGDIR /www.test.com.$FILEDAY.log
        kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
    -> :wq 
    -> crontab -e 添加一条定时任务
        0 0 * * * /data/scripts/nginx_log_splid.sh 每晚0点执行nginx_log_splid.sh文件
测试  /usr/local/nginx/sbin/nginx -t 
提示  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
     nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
即为配置成功。
重启  /usr/local/nginx/sbin/nginx -s reload

6. 主机访问虚拟机项目只需要完成下面配置 ^_^

在/usr/local/nginx/conf/vhost目录配置后,在主机的hosts里,将域名指向虚拟机的IP即可

以上是linux 虛擬機器上怎麼安裝php的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
酸與基本數據庫:差異和何時使用。酸與基本數據庫:差異和何時使用。Mar 26, 2025 pm 04:19 PM

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

PHP安全文件上傳:防止與文件相關的漏洞。PHP安全文件上傳:防止與文件相關的漏洞。Mar 26, 2025 pm 04:18 PM

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

PHP輸入驗證:最佳實踐。PHP輸入驗證:最佳實踐。Mar 26, 2025 pm 04:17 PM

文章討論了PHP輸入驗證以增強安全性的最佳實踐,重點是使用內置功能,白名單方法和服務器端驗證等技術。

PHP API率限制:實施策略。PHP API率限制:實施策略。Mar 26, 2025 pm 04:16 PM

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

php密碼哈希:password_hash和password_verify。php密碼哈希:password_hash和password_verify。Mar 26, 2025 pm 04:15 PM

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

OWASP前10 php:描述並減輕常見漏洞。OWASP前10 php:描述並減輕常見漏洞。Mar 26, 2025 pm 04:13 PM

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。

PHP XSS預防:如何預防XSS。PHP XSS預防:如何預防XSS。Mar 26, 2025 pm 04:12 PM

本文討論了防止PHP中XSS攻擊的策略,專注於輸入消毒,輸出編碼以及使用安全增強的庫和框架。

PHP接口與抽像類:何時使用。PHP接口與抽像類:何時使用。Mar 26, 2025 pm 04:11 PM

本文討論了PHP中接口和抽像類的使用,重點是何時使用。界面定義了無實施的合同,適用於無關類和多重繼承。摘要類提供常見功能

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器