生活随笔
收集整理的這篇文章主要介紹了
linux下PHP7环境搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
LAMP環境版本 操作系統:Centos 7 Mysql:5.7.11 Apache:2.4.18 PHP:7.0.4 安裝Mysql 下載鏈接:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
為mysql創建專屬帳號 [plain] ?view plaincopy
shell>?groupadd?mysql?? shell>?useradd?-r?-g?mysql?-s?/bin/false?mysql?? 源碼編譯安裝 [plain] ?view plaincopy
shell>?tar?zxvf?mysql-5.7.11.tar.gz?? shell>?cd?mysql-5.7.11?? shell>?cmake?.?? shell>?make?? shell>?make?install?? 安裝后設置 注意:從Mysql5.7開始,mysql默認安裝后不再是空密碼,而是生成一個隨機密碼,除非初始化時指定--initialize-insecure。 所有用戶擁有對于MySQL默認安裝test數據庫的訪問權限(即使沒有授予權限)為了安全考慮5.7版本中不在有test數據庫。 更為重要的是,MySQL 5.7版本提供了更為簡單SSL安全訪問配置,并且默認連接就采用SSL的加密方式
[plain] ?view plaincopy
shell>?cd?/usr/local/mysql?? shell>?chown?-R?mysql?.??#修改目錄所有者為mysql?? shell>?chgrp?-R?mysql?.??#修改目錄所屬組為mysql?? shell>?bin/mysqld?--initialize-insecure?--user=mysql?--datadir=/data/mysql??#初始化mysql,初始化為空,數據庫存放目錄指定為/data/mysql?? shell>?bin/mysql_ssl_rsa_setup?#啟動ssl加密方式連接?? shell>?chown?-R?root?.???#修改目錄所有者為root?? shell>?chown?-R?mysql?/data/mysql??#修改數據庫目錄所有者為mysql?? 安裝mysql服務 只需要將mysql安裝目錄下的mysql.server復制過去就OK了。
[plain] ?view plaincopy
shell>?cp?support-files/mysql.server?/etc/init.d/mysql.server?? shell>?service?mysql?start???#啟動服務?? 安裝Apache 下載鏈接:http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.18.tar.gz
源碼編譯安裝 [plain] ?view plaincopy
shell>?./configure?--prefix=/usr/local/apahche?\?? --enable-so?#動態共享對象,可實現模塊動態生效?\?? --enable-rewrite?#啟用Rewrite功能?\?? --enable-ssl?#支持SSL/TLS,可以實現https訪問?\?? --enable-deflate?#支持壓縮?\?? shell>?make?? shell>?make?install?? apache的啟動與關閉 [plain] ?view plaincopy
shell>?/usr/local/apache/bin/apachectl?start????#啟動?? shell>?/usr/local/apache/bin/apachectl?stop?????#停止?? shell>?/usr/local/apache/bin/apachectl?restart??#重啟?? 將apache添加到Linux的服務并設置自啟動 [plain] ?view plaincopy
shell>?cp?/usr/local/apache/bin/apachectl?/etc/rc.d/init.d/httpd???#設置為系統服務?? shell>?ln?-s?/etc/rc.d/init.d/httpd?/etc/rc.d/rc3.d/S80httpd???#在啟動級別3中自啟動?? shell>?service?httpd?restart???#通過服務來重啟apache?? 運行測試頁面 在客戶端瀏覽器上輸入服務器的IP地址,看是否能正常打開網頁。
常見問題 configure: error: APR not found. 解決方法: 安裝對應依賴庫 [plain] ?view plaincopy shell>?yum?install?apr?apr-util-devel?? configure: error: pcre-config for libpcre not found. 解決方法:安裝對應依賴庫 [plain] ?view plaincopy yum?install?pcre?pcre-devel?? 啟動apache時報:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.44.13.173. Set the 'ServerName' directive globally to suppress this message 解決方法:修改配置文件httpd.conf設置ServerName localhost:80 安裝PHP 下載鏈接:http://php.net/downloads.php
安裝依賴庫 zlib 官網:http://www.zlib.net/ [plain] ?view plaincopy shell>?tar?xf?zlib.1.2.8.tar.gz?? shell>?cd?zlib.1.2.8?? shell>?./configure?? shell>?make?test?? shell>?make?install?? GD庫 libpng 官網:http://www.libpng.org/ [plain] ?view plaincopy shell>?tar?xf?libpng-1.6.21?? shell>?cd?libpng-1.6.21?? shell>?./configure?--prefix=/usr/local/libpng?? shell>?make?? shell>?make?check?? shell>?make?install?? jpeg 官網:http://www.ijg.org/ [php] ?view plaincopy shell>?tar?xf?jpegsrc.v9.tar.gz?? shell>?cd?jpeg-9?? shell>?./configure?--prefix=/usr/local/libjpeg?? shell>?make?? shell>?make?install?? libcurl-devel [plain] ?view plaincopy yum?install?libcurl-devel?? openssl-devel [plain] ?view plaincopy yum?install?openssl-devel?? libxslt-devel [plain] ?view plaincopy yum?install?libxslt-devel?? libxml2-devel [plain] ?view plaincopy yum?install?libxml2-devel?? freetype 字體操作庫 官網:http://www.freetype.org/ [plain] ?view plaincopy shell>?tar?xf?freetype-2.6.3.tar.bz2?? shell>?sh?autogen.sh?? shell>?./configure?--prefix=/usr/local/freetype?? shell>?make?? shell>?make?install?? 編譯安裝PHP [plain] ?view plaincopy
./configure?--prefix=/usr/local/php?\?? ?--with-apxs2=/usr/local/apache/bin/apxs?\?? ?--with-curl?\?? ?--with-freetype-dir=/usr/local/freetype?\?? ?--with-gd?\?? ?--with-gettext?\?? ?--with-iconv-dir?\?? ?--with-mysqli?\?? ?--with-openssl?\?? ?--with-pcre-regex?\?? ?--with-pdo-mysql?\?? ?--with-pdo-sqlite?\?? ?--with-pear?\?? ?--with-png-dir=/usr/local/libpng?\?? ?--with-jpeg-dir=/usr/local/libjpeg?\?? ?--with-xsl?\?? ?--with-zlib?\?? ?--enable-fpm?\?? ?--enable-bcmath?\?? ?--enable-libxml?\?? ?--enable-inline-optimization?\?? ?--enable-gd-native-ttf?\?? ?--enable-mbregex?\?? ?--enable-mbstring?\?? ?--enable-opcache?\?? ?--enable-pcntl?\?? ?--enable-shmop?\?? ?--enable-soap?\?? ?--enable-sockets?\?? ?--enable-sysvsem?\?? ?--enable-xml?\?? ?--enable-zip?? (./configure ?'--prefix=/usr/local/php' '--with-freetype-dir=/usr/local/freetype' '--with-gd' '--with-gettext' '--with-iconv-dir' '--with-mysqli' '--with-openssl' '--with-pcre-regex' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-pear' '--with-png-dir=/usr/local/libpng' '--with-jpeg-dir=/usr/local/libjpeg' '--with-xsl' '--with-zlib' '--enable-fpm' '--enable-bcmath' '--enable-libxml' '--enable-inline-optimization' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvsem' '--enable-xml' '--enable-zip' '--with-curl=/usr/local/curl')指定curl為openssl ?? shell>?make?? shell>?make?install?? Apache與PHP的關聯 PHP安裝成功后會在apache的modules目錄下生成一個libphp.so動態庫文件,在apache的配置文件httpd.conf里自動增加一行
[plain] ?view plaincopy
LoadModule?php7_module????????modules/libphp7.so?? 在Apache的配置文件httpd.conf的<IfModule mime_module></IfModule>塊里增加一行
[plain] ?view plaincopy
AddType?application/x-httpd-php?.php?? 在網站要目錄/usr/local/htdocs里增加一個index.php測試文件內容如下:
[php] ?view plaincopy
<?php?? phpinfo();?? 然后我們運行此文件,如果輸出了phpinfo信息,證明我們安裝成功。
總結
以上是生活随笔 為你收集整理的linux下PHP7环境搭建 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。