LAMP網站架構是目前國際流行的Web框架,該框架包括:Linux操做系統,Apache網絡服務器,MySQL數據庫,Perl、PHP或者Python編程語言,全部組成產品均是開源軟件,是國際上成熟的架構框架,不少流行的商業應用都是採起這個架構,LAMP具備通用、跨平臺、高性能、低價格的優點,所以LAMP不管是性能、質量仍是價格都是企業搭建網站的首選平臺。php
本文介紹的LAMP環境是在(Centos7 + Apache-2.4.33 + Mysql-5.7.17 + PHP-7.2.5)上搭建的。本文是在假設Centos7已經安裝完成的前提下進行介紹的,若還沒有安裝,能夠前往Centos官網下載對應的ios文件安裝,下載地址:http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1804.iso。html
LAMP架構圖以下:mysql
系統平臺: CentOS 7.3
Server: 192.168.8.55linux
# 寫hosts記錄 [root@LAMP ~]# echo "192.168.8.55 LAMP" >> /etc/hosts # 關閉firewalld和selinux [root@LAMP ~]# systemctl stop firewalld && systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. # 關閉selinux [root@LAMP ~]# setenforce 0 [root@LAMP ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
本文不使用yum安裝,如須要使用yum安裝LNMP環境,則需搭建epel第三方yum倉庫。本文主要使用源碼包安裝,以下標題第4、5、六。ios
[root@LAMP ~]# yum –y install gcc gcc-c++ ncurses-devel perl
安裝epel擴展yum的軟件包,用於在本機生成epel擴展yum配置文件。c++
[root@LAMP ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@LAMP ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm [root@LAMP ~]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
配置好epel的yum源安裝相應的基礎模塊,可使用yum直接安裝。web
# 安裝Apache [root@LAMP ~]# yum -y install httpd # 安裝數據庫 [root@LAMP ~]# yum -y install mariadb # 安裝php7.0 [root@LAMP ~]# yum -y install php70w php70w-devel # 安裝php擴展 [root@LAMP ~]# yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 # 安裝PHP-FPM [root@LAMP ~]# yum install -y php70w-fpm
[root@LAMP ~]# yum -y remove mariadb [root@LAMP ~]# yum -y remove mysql [root@LAMP ~]# rm -rf /usr/local/mysql57 [root@LAMP ~]# rm -rf /usr/src/mysql-5.7.18/ [root@LAMP ~]# rm -rf /var/lib/mysql57/ [root@LAMP ~]# rm /etc/my.cnf
[root@LAMP ~]# yum –y install libevent* libtool* autoconf* libstd* ncurse* bison* openssl* # MySQL 5.5以後的版本須要cmake(c語言編譯器)來進行編譯安裝 [root@LAMP ~]# yum -y install cmake
# MySQL 5.7 以後的版本,cmake編譯須要boost類庫 # 下載 [root@LAMP ~]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz # 解壓 [root@LAMP ~]# tar zxvf boost_1_59_0.tar.gz -C /usr/local/ # 重命名 [root@LAMP ~]# mv /usr/local/boost_1_59_0/ /usr/local/boost/
[root@LAMP ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17.tar.gz # 解壓到/usr/src/目錄 [root@LAMP ~]# tar zxvf mysql-5.7.17.tar.gz -C /usr/src/
# 進入解壓以後的/usr/src/mysql-5.7.17/目錄 [root@LAMP ~]# cd /usr/src/mysql-5.7.17/ [root@LAMP mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DMYSQL_DATADIR=/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql57/mysql57.socket -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/usr/local/boost [root@LAMP mysql-5.7.17]# make [root@LAMP mysql-5.7.17]# make install
**cmake編譯配置參數說明:** -DCMAKE_INSTALL_PREFIX=dir_name # 安裝的主目錄 -DMYSQL_DATADIR=dir_name MySQL # 文件目錄的路徑,這個參數也能夠在啓動MySQL的時候帶上--datadir參數進行設置 -DSYSCONFDIR=dir_name my.cnf # 參數文件的路徑 -DWITH_INNOBASE_STORAGE_ENGINE=1 # 將INNODB存儲引擎編譯進去 -DWITH_MYISAM_STORAGE_ENGINE=1 # 將INNODB存儲引擎編譯進去 -DWITH_MEMORY_STORAGE_ENGINE=1 # 安裝memory存儲引擎 -DWITH_READLINE=bool # 是否使用readline庫 -DMYSQL_UNIX_ADDR=file_name Unix socket # 文件的路徑,socket文件用於服務器監聽鏈接,這個參數必須是絕對路徑 -DMYSQL_TCP_PORT=port_num # 服務器監聽TCP/IP鏈接的端口,默認是3306 -DENABLED_LOCAL_INFILE=1 # 是否打開LOAD DATA INFILE的LOCAL參數 -DWITH_PARTITION_STORAGE_ENGINE=1 # 將分區存儲引擎編譯進去 -DEXTRA_CHARSETS=all # 安裝全部擴展字符集 -DDEFAULT_CHARSET # 字符集,默認字符集是latin1 -DDEFAULT_COLLATION=collation_name # 服務校對,默認的是latin1_swedish_ci,能夠經過SHOW COLLATION語句查看哪一個校對匹配的字符集 -DWITH_BOOST # boost類庫所在目錄 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 # 將FEDERATED存儲引擎編譯進去 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 # 將BLACKHOLE存儲引擎編譯進去 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 # 不編譯EXAMPLE存儲引擎 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 # 將Performance Schema(性能視圖)存儲引擎編譯進去 -DCOMPILATION_COMMENT=string # 編譯環境描述 -DENABLED_PROFILING=bool # 是否開啓profiling代碼的查詢(用於SHOW PROFILE and SHOW PROFILES語句) -DWITH_EXTRA_CHARSETS=name # 指定額外的字符集,默認是all,包含全部的字符集。 -DINSTALL_BINDIR=dir_name # 安裝用戶程序的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/bin -DINSTALL_DOCDIR=dir_name #安裝文檔的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/doc -DINSTALL_INCLUDEDIR=dir_name #安裝頭文件的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/include -DINSTALL_LIBDIR=dir_name # 安裝庫文件的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/lib -DINSTALL_MANDIR=dir_name #安裝幫助手冊的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/man -DINSTALL_PLUGINDIR=dir_name # 安裝插件的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/lib/plugin -DINSTALL_SBINDIR=dir_name # 安裝mysqld服務端啓動腳本的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/bin -DINSTALL_SCRIPTDIR=dir_name # 初始化MySQL數據庫的數據文件路徑的mysql_install_db腳本路徑,默認路徑是DCMAKE_INSTALL_PREFIX/scripts -DINSTALL_SQLBENCHDIR=dir_name # 安裝sql-bench的路徑,默認路徑是DCMAKE_INSTALL_PREFIX -DINSTALL_SUPPORTFILESDIR=dir_name # 安裝支持文件的路徑,默認路徑是DCMAKE_INSTALL_PREFIX/support-files # 如若要編譯進其它功能,如SSL等,則可以使用相似以下選項來實現編譯時使用某庫或不使用某庫: -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0
(1)建立id爲27的mysql用戶正則表達式
[root@LAMP ~]# groupadd mysql [root@LAMP ~]# useradd -M -g mysql -s /sbin/nologin mysql
(2)配置文件my.cnf算法
[root@LAMP ~]# vim /etc/my.cnf # 修改成如下內容,其它所有刪掉 [mysqld] port=3306 datadir=/data pid-file=/var/run/mysql57/mysql57.pid socket=/var/lib/mysql57/mysql57.socket log-error=/var/log/mysql57/mysql57.log user=mysql [client] socket=/var/lib/mysql57/mysql57.socket
(3)建立相關目錄,並修改權限sql
# 建立cmake命令中的-DMYSQL_DATADIR設置的路徑) [root@LAMP ~]# mkdir /data/ # 建立cmake命令中的-DMYSQL_UNIX_ADDR設置的路徑) [root@LAMP ~]# mkdir /var/lib/mysql57/ [root@LAMP ~]# mkdir /var/run/mysql57 [root@LAMP ~]# mkdir /var/log/mysql57/ # 修改權限 [root@LAMP ~]# chown -R mysql:mysql /usr/local/mysql57/ /data/ /var/lib/mysql57/ /var/log/mysql57/ /var/run/mysql57
# 初始化MySQL [root@LAMP ~]# cd /usr/local/mysql57/ [root@LAMP mysql57]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql57/ --datadir=/data/ # 啓動MySQL [root@LAMP ~]# /usr/local/mysql57/support-files/mysql.server start
初始化以後,啓動mysql57數據庫,可是路徑太長,操做起來很麻煩,咱們能夠把MySQL設置爲系統服務,以下步驟。
[root@LAMP mysql57]# vim /lib/systemd/system/mysql57.service # 添加文件內容以下: [Unit] Description=mysql After=network.target [Service] Type=forking ExecStart=/usr/local/mysql57/support-files/mysql.server start ExecStop=/usr/local/mysql57/support-files/mysql.server stop ExecRestart=/usr/local/mysql57/support-files/mysql.server restart ExecReload=/usr/local/mysql57/support-files/mysql.server reload PrivateTmp=true [Install] WantedBy=multi-user.target
[root@LAMP ~]# systemctl enable mysql57.service 十、啓動MySQL [root@LAMP ~]# systemctl restart mysql57.service [root@LAMP ~]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 24965 mysql 16u IPv6 44563 0t0 TCP *:mysql (LISTEN)
# 登錄MySQL數據庫 [root@LAMP ~]# /usr/local/mysql57/bin/mysql mysql> update mysql.user set authentication_string=password('123') where user='root' and host = 'localhost'; Query OK, 1 row affected, 1 warning (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
Apache的Rewrite模塊和HTTP核心模塊會使用到PCRE正則表達式語法
[root@LAMP ~]# yum -y install pcre pcre-devel [root@LAMP ~]# yum -y install expat-devel
Apache的各類模塊中須要使用gzip壓縮
[root@LNMP ~]# yum -y install zlib zlib-devel
Apache須要開啓OpenSSL
[root@LNMP ~]# yum -y install openssl
# 下載Apache包 [root@LAMP ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.gz # 解壓Apache包到/usr/src/目錄 [root@LAMP ~]# tar zxvf httpd-2.4.33.tar.gz -C /usr/src/ # 下載APR和APR-util包 [root@LAMP ~]# wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz [root@LAMP ~]# wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz # 解壓APR和APR-util包到/usr/src/httpd-2.4.33/srclib/目錄 [root@LAMP ~]# tar zxvf apr-1.6.3.tar.gz -C /usr/src/httpd-2.4.33/srclib/ [root@LAMP ~]# tar zxvf apr-util-1.6.1.tar.gz -C /usr/src/httpd-2.4.33/srclib/ # 重命名 [root@LAMP ~]# cd /usr/src/httpd-2.4.33/ [root@LAMP httpd-2.4.33]# mv ./srclib/apr-1.6.3 ./srclib/apr [root@LAMP httpd-2.4.33]# mv ./srclib/apr-util-1.6.1 ./srclib/apr-util
# 進入解壓以後的/usr/src/httpd-2.4.33/目錄 [root@LAMP ~]# cd /usr/src/httpd-2.4.33/ [root@LAMP httpd-2.4.33]# ./configure --enable-modules=all --enable-mods-shared=all --with-mpm=prefork --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-rewrite --enable-ssl --with-ssl=/usr/bin/openssl --enable-so --with-included-apr [root@LAMP httpd-2.4.33]# make [root@LAMP httpd-2.4.33]# make install
**configure編譯配置參數說明:** --enable-modules=all # 靜態加載全部模塊 --enable-mods-shared=all # 動態加載全部模塊 --enable-so # 讓apache核心裝載DSO --with-mpm=prefork # 指定運行prefork多路處理模塊(MPM) --prefix=/usr/local/apache2 # 指定缺省安裝目錄 --enable-module=so # 打開so模塊 --enable-deflate=shared # 支持網頁壓縮 --enable-expires=shared # 支持HTTP控制 --enable-rewrite=shared # 支持URL重寫 --enable-cache # 支持緩存 --enable-file-cache # 支持文件緩存 --enable-mem-cache # 支持記憶緩存 --enable-disk-cache # 支持磁盤緩存 --enable-ssl # 支持open-ssl庫 --with-ssl # 指定open-ssl庫 --with-apr=PATH # 指定APR的安裝目錄 --with-apr-util= PATH # 指定APR-util的安裝目錄
Apache服務啓動和中止路徑太長,不方便操做,咱們能夠把Apache設置爲系統服務,使用系統命令進行啓動,操做步驟以下。
[root@LAMP ~]# vim /lib/systemd/system/apache.service # 添加文件內容以下: [Unit] Description=apache After=network.target [Service] Type=forking ExecStart=/usr/local/apache2/bin/apachectl start ExecStop=/usr/local/apache2/bin/apachectl stop ExecRestart=/usr/local/apache2/bin/apachectl restart ExecReload=/usr/local/apache2/bin/apachectl reload PrivateTmp=true [Install] WantedBy=multi-user.target
[root@LAMP ~]# systemctl enable apache.service Created symlink from /etc/systemd/system/multi-user.target.wants/apache.service to /usr/lib/systemd/system/apache.service.
[root@LAMP ~]# systemctl start apache.service
查看Apache服務是否啓動成功:
[root@LAMP ~]# lsof -i:80
在瀏覽器中訪問測試:
http://192.168.8.55
出現如下界面則表示能夠成功訪問:
[root@LAMP ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
若提示yum中沒有可用的軟件包libmcrypt和libmcrypt-devel,則須要手動編譯安裝。
[root@LAMP ~]# wget https://sourceforge.mirrorservice.org/m/mc/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz [root@LAMP ~]# tar zxvf libmcrypt-2.5.8.tar.gz -C /usr/src/ [root@LAMP ~]# cd /usr/src/libmcrypt-2.5.8/ [root@LAMP libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt [root@LAMP libmcrypt-2.5.8]# make [root@LAMP libmcrypt-2.5.8]# make install [root@LAMP libmcrypt-2.5.8]# /sbin/ldconfig --從新加載系統庫包
[root@LAMP ~]# wget http://cn2.php.net/distributions/php-7.2.5.tar.gz [root@LAMP ~]# tar zxvf php-7.2.5.tar.gz -C /usr/src/
# 進入解壓以後的/usr/src/php-7.2.5/目錄 [root@LAMP ~]# cd /usr/src/php-7.2.5/ [root@LAMP php-7.2.5]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-mysqli=/usr/local/mysql57/bin/mysql_config --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache2/bin/apxs --enable-mysqlnd --with-pdo-mysql=/usr/local/mysql57 --with-pcre-dir=/usr/local/ --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-gd --with-iconv --with-zlib --with-libxml-dir=/usr --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-bcmath [root@LAMP php-7.2.5]# make [root@LAMP php-7.2.5]# make install
**configure編譯配置參數說明:** --prefix # 用於指定PHP安裝目錄 --with-config-file-path # 指定php.ini位置 --with-config-file-scan-dir # 指定php.d位置 --with-mysqli # mysqli文件目錄,優化支持 --with-iconv-dir # 用於 PHP 編譯時指定 iconv 在系統裏的路徑,不然會掃描默認路徑 --with-iconv # 使編譯iconv時不被禁用 --with-apxs2 # 指定Apache的的apxs位置 --enable-mysqlnd # 啓用mysqlnd的庫來支持mysql的鏈接s --with-pdo-mysql # MySQ安裝目錄,對MySQL的支持 --with-pcre-dir # perl的正則庫案安裝位置 --enable-fpm # 打上PHP-fpm 補丁後纔有這個參數,CGI方式安裝的啓動程序 --with-fpm-user # 設置 FPM 運行的用戶身份(默認 - nobody) --with-fpm-group # 設置 FPM 運行時的用戶組(默認 - nobody) --with-fpm-systemd # 啓用 systemd 集成 (默認 - no) --with-fpm-acl # 使用POSIX 訪問控制列表 (默認 - no) 5.6.5版本起有效 --with-gd # 啓用gd庫的支持 --with-zlib # 啓用zlib庫的支持 --with-libxml-dir # 啓用libxml2庫的支持 --enable-xml # 啓用xml庫支持 --enable-shmop # 啓用shmop函數支持 --enable-inline-optimization # 優化線程 --enable-mbstring # 多字節,字符串的支持 --enable-ftp # 啓用ftp的支持 --with-openssl # openssl的支持,加密傳輸時用到的 --enable-pcntl # freeTDS須要用到的,多是連接mssql 纔用到 --enable-sockets # 啓用 sockets 支持 --with-xmlrpc # 啓用xml-rpc的c語言 --enable-zip # 啓用對zip的支持 --enable-soap # 啓用soap模塊的支持 --without-pear # 不安裝PEAR --with-gettext # 啓用gnu 的gettext 支持,編碼庫用到 --enable-session # 啓用session模塊的支持 --with-curl # 啓用curl瀏覽工具的支持 --with-jpeg-dir # 啓用對jpeg圖片的支持 --with-freetype-dir # 啓用對freetype字體庫的支持 --enable-opcache # 啓用opcache共享擴展的支持 --with-mcrypt # 指定的是libmcrypt的安裝目錄 --enable-safe-mode # 啓用安全模式 --with-bz2 # 啓用對bz2文件的支持 --with-png-dir # 啓用對png圖片的支持 --without-iconv # 關閉iconv函數,一種字符集間的轉換 --enable-gd-native-ttf # 支持TrueType字符串函數庫 --with-curlwrappers # 運用curl工具啓用url流 --with-ttf # 啓用freetype1.*的支持,能夠不加了 --with-xsl # 啓用XSLT 文件支持,擴展了libXML2庫 ,須要libxslt軟件 --with-pear # 啓用pear命令的支持,PHP擴展用的 --enable-calendar # 啓用日曆擴展功能 --enable-bcmath # 啓用圖片大小調整,用到zabbix監控的時候用到了這個模塊 --enable-exif # 圖片的元數據支持 --enable-magic-quotes # 魔術引用的支持 --disable-rpath # 關閉額外的運行庫文件 --disable-debug # 關閉調試模式 --with-mime-magic=/usr/share/file/magic.mime # 魔術頭文件位置 --enable-fastCGI # 支持fastcgi方式啓動PHP --with-ncurses # 支持ncurses 屏幕繪製以及基於文本終端的圖形互動功能的動態庫 --enable-pcntl # freeTDS須要用到的,多是連接mssql 纔用到 --with-mcrypt # 啓用mcryp算法 --with-mhash # 企業mhas算法 --with-gdbm # dba的gdbm支持 --enable-zend-multibyte # 支持zend的多字節
(1)配置Apache網站家目錄
[root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf DocumentRoot "/web" # 修改網站家目錄 235 <Directory "/web"> # 相應的目錄容器也要修改
(2)配置Apache對PHP支持
也就是配置Apache和PHP的聯繫
[root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf 168 LoadModule php7_module modules/libphp7.so # 找到這一句,在這句下面加上兩句 169 AddHandler php7-script .php 170 AddType text/html .php # 這兩句的意思是以.php結尾的文件都認爲是php程序文件,注意兩句話的.php前面都是有一個空格的
(3)默認主頁加上index.php,並放在index.html前
[root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf 270 DirectoryIndex index.php index.html
(4)配置中文優先支持
[root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf # 打開此選項註釋,擴展配置文件就生效了 486 Include conf/extra/httpd-languages.conf [root@LAMP ~]# vim /usr/local/apache2/conf/extra/httpd-languages.conf # 打開此選項註釋 19 DefaultLanguage nl # 語言集優先級,把zh-CN、zh-TW寫到前面 78 LanguagePriority zh-CN zh-TW en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr # 在文件的最後新增如下參數 142 AddDefaultCharset UTF-8 # 默認以utf-8編碼顯示中文
[root@LAMP ~]# mkdir /web
[root@LAMP ~]# /usr/local/apache2/bin/apachectl restart # 或者(前提是Apache設置爲系統服務) [root@LAMP ~]# systemctl restart apache.service [root@LAMP ~]# lsof -i:80 --啓動成功後,能夠看到下面的進程 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 61897 root 4u IPv6 473981 0t0 TCP *:http (LISTEN)
錯誤一:
[root@LAMP ~]# systemctl restart apache.service Job for apache.service failed because the control process exited with error code. See "systemctl status apache.service" and "journalctl -xe" for details. # 解決方法: [root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf # 把這一句註釋打開 161 LoadModule negotiation_module modules/mod_negotiation.so
錯誤二:
(98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs # 解決方法: 上面的報錯表示80被佔用,能夠去先停掉Nginx服務(或者改端口),再啓動Apache服務
錯誤三:
httpd: apr_sockaddr_info_get() failed for qianyun.com httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName # 解決方法: 把本機的IP地址和主機名寫進/etc/hosts文件
錯誤四:
httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.1.20 for ServerName # 解決方法: [root@LAMP ~]# vim /usr/local/apache2/conf/httpd.conf 212 ServerName *:80
創建一個主頁,在家目錄下創建一個PHP測試頁來測試
[root@LAMP ~]# vim /web/index.php <?php phpinfo(); ?>
在瀏覽器中訪問測試:
http://192.168.8.55
將PHP包解壓目錄中的配置文件放置到/usr/local/php/etc/目錄下(也就是configure命令中的--with-config-file-path設置的路徑)
# sysconfigdir參數決定的(由於,指定安裝路徑爲/usr/local/php,因此就要拷到/usr/local/php/etc/目錄下) [root@LAMP ~]# cp /usr/src/php-7.2.5/php.ini-development /usr/local/php/etc/php.ini [root@LAMP ~]# vim /usr/local/php/etc/php.ini # 修改如下內容 1154 mysqli.default_port = 3306 # 改爲對應的MySQL的端口 1159 mysqli.default_socket = /var/lib/mysql57/mysql57.socket # 對應的socket文件地址 # 在最後加上下面一段,支持opcache(php新一代的緩存加速器) zend_extension=opcache.so # 開關打開 [opcache] opcache.enable=1 # 開啓 opcache.enable_cli=1 # 開啓緩存 opcache.memory_consumption=128 # 可用內存, 酌情而定, 單位爲:Mb opcache.interned_strings_buffer=8 # Zend Optimizer + 暫存池中字符串的佔內存總量.(單位:MB) opcache.max_accelerated_files=4000 # 對多緩存文件限制, 命中率不到 100% 的話, 能夠試着提升這個值 opcache.revalidate_freq=60 # Opcache 會在必定時間內去檢查文件的修改時間, 這裏設置檢查的時間週期, 默認爲 2, 定位爲秒 opcache.fast_shutdown=1 # 打開快速關閉, 打開這個在PHP Request Shutdown的時候回收內存的速度會提升 # 重啓Apache服務,再訪問index.php頁面,找到opcache的配置選項,則表示成功 [root@LAMP ~]# systemctl restart apache.service
至此,LAMP環境搭建完成!
安裝一個開源論壇,驗證LNMP環境配置是否正常。
[root@LAMP ~]# wget http://zj.mycodes.net/201712/Discuz_X3.4_GIT_SC_GBK.zip [root@LAMP ~]# unzip Discuz_X3.4_GIT_SC_GBK.zip -d /web/ [root@LAMP ~]# cd /web/ [root@LAMP web]# mv /web/dir_SC_GBK/ /web/discuz [root@LAMP discuz]# cd /web/discuz/ [root@LAMP discuz]# ls readme upload utility [root@LAMP discuz]# mv upload/* ./ [root@LAMP discuz]# mv readme/* ./ [root@LAMP discuz]# mv utility/* ./
在瀏覽器中訪問測試
http://192.168.8.55/discuz/install
進入安裝嚮導
點擊「我贊成」。
目錄、文件權限檢查狀態爲不可寫,須要修改權限,用戶改爲daemon。
[root@LAMP ~]# chmod -R a+w /web/ [root@LAMP ~]# chown -R daemon.daemon /web/
修改完成以後,刷新瀏覽器,點擊「下一步」。
選擇「全新安裝Discuz!X(含Ucenter Server)」,點擊「下一步」。
安裝數據庫,須要MySQL數據庫受權:
# 登錄MySQL數據庫 [root@LAMP ~]# /usr/local/mysql57/bin/mysql -p123 # 建立一個庫,用於存放將要安裝的discuz論壇的表 mysql> create database discuz; Query OK, 1 row affected (0.00 sec) # 受權一個用戶,用於discuz論壇程序鏈接mysql mysql> grant all on discuz.* to 'discuz'@'localhost' identified by '123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
數據庫安裝以下圖所示:
填寫完成以後,點擊「下一步」,開始安裝數據庫。能夠看到剛纔建立的discuz庫裏面有297張表(show tables discuz;)。
安裝完成以後能夠看到discuz論壇的首頁。