LAMP 環境搭建


熟悉開發環境,可以更好地完成開發工作。

本篇選用最新版本 Apache 2.4 + PHP 7.3 + PostgreSQL 11.2

服務器是 CentOS 7.6,全部編譯安裝

 

一、安裝 Apache

1、安裝包 - http://archive.apache.org/dist/httpd/httpd-2.4.38.tar.gz

2、安裝

--------- 安裝 pcre ---------- # cd /usr/local/src/ # wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz
 # tar -axvf pcre-8.39.tar.gz # cd pcre-8.39 # ./configure # make # make install



--------- 安裝 apr ---------- # cd /usr/local/src/ # wget http://mirrors.ocf.berkeley.edu/apache/apr/apr-1.6.5.tar.gz
 # tar -zxvf apr-1.6.5.tar.gz # cd apr-1.6.5 # ./configure # make # make install



--------- 安裝 apr-util ---------- # cd /usr/local/src/ # wget http://mirrors.ocf.berkeley.edu/apache/apr/apr-util-1.6.1.tar.gz
 # tar -zxvf apr-util-1.6.1.tar.gz # cd apr-util-1.6.1 # ./configure --with-apr=/usr/local/apr # make # make install



--------- 安裝 Apache ---------- # cd /usr/local/src/ # wget http://archive.apache.org/dist/httpd/httpd-2.4.38.tar.gz
 # tar -zxvf httpd-2.4.38.tar.gz # cd httpd-2.4.38 # ./configure --prefix=/usr/local/apache --with-layout=Apache --enable-rewrite --enable-so --enable-expires --enable-proxy --enable-headers --enable-info  --with-apr=/usr/local/apr --with-pcre=/usr/local/pcre # make # make install


--------- 設置開機自啟動 ---------- systemctl 腳本存放在 /usr/lib/systemd/ 目錄中, Apache 設置為開機不登錄即可啟動, # cp /usr/local/apache/bin/apachectl /etc/init.d/httpd # ls /etc/init.d/ | grep httpd # vim /etc/init.d/httpd 在第一行 #!/bin/sh 下面添加兩行,三個數字代表運行、啟動、停止的級別 #chkconfig: 345 85 15 #description: Start and stop the Apache HTTP Server # chkconfig --add /etc/init.d/httpd # service httpd start

3、遇到的問題

Q1:configure: error: You need a C++ compiler for C++ support. A1:yum -y install gcc-c++ Q2:xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory A2:yum install expat-devel Q3:collect2: error: ld returned 1 exit status make[2]: *** [htpasswd] Error 1
    make[2]: Leaving directory `/usr/local/src/httpd-2.4.38/support'     make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/usr/local/src/httpd-2.4.38/support'     make: *** [all-recursive] Error 1 A3:# cp -r apr-1.6.5 httpd-2.4.38/srclib/apr # cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.38/srclib/apr-util Q4:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.26.160.216. Set the 'ServerName' directive globally to suppress this message
A4:將 conf 的 #ServerName localhost:80 注釋去掉即可。

 

二、安裝 pgsql

1、安裝包 - https://ftp.postgresql.org/pub/source/v11.2/postgresql-11.2.tar.gz

2、創建用戶

# useradd postgres # id postgres # passwd postgres

3、安裝

# cd /usr/local/src/ # wget https://ftp.postgresql.org/pub/source/v11.2/postgresql-11.2.tar.gz
 # tar -zxvf postgresql-11.2.tar.gz # chown -R postgres:postgres postgresql-11.2 # su postgres $ cd postgresql-11.2 $ ./configure --prefix=/usr/local/postgresql-11.2 $ make $ su root # make install # ln -s /usr/local/postgresql-11.2 /usr/local/pgsql ---------- 設置環境變量 -------------- # su - postgres $ cd ~ $ vim .bash_profile 添加下面三行,路徑改為自己的 export PGHOME=/usr/local/pgsql export PGDATA=/usr/local/pgsql/data export PATH=$PATH:$HOME/.local/bin:$PGHOME/bin $ source .bash_profile ----------- 初始化數據庫 ------------------ $ initdb ---------- 啟動 psql 服務 ------------ $ pg_ctl -D /usr/local/pgsql/data -l logfile start ----------- 設置開機自啟動 ---------- # cd /usr/local/src/postgresql-11.2/contrib/start-scripts # chmod a+x linux # cp linux /etc/init.d/postgresql # chkconfig --add pgsql # service pgsql start ------------- 連接測試 -------------------- $ psql

 4、遇到的問題

Q1:configure: error: readline library not found A1:$ rpm -qa | grep readline $ yum -y install -y readline-devel Q2:configure: error: zlib library not found A2:yum install zlib-devel Q3:bash: initdb: command not found A3:initdb 的路徑不對。應該寫全路徑或設置環境變量 Q4:-bash: psql: command not found A4:確保 pgsql/bin/ 在環境變量中

 

三、安裝 PHP

1、安裝包 - https://www.php.net/distributions/php-7.3.4.tar.gz

2、安裝

# cd /usr/local/src/ # wget https://www.php.net/distributions/php-7.3.4.tar.gz
 # tar -zxvf php-7.3.4.tar.gz # cd php-7.3.4 # ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-pgsql=/usr/local/postgresql-11.2/bin --enable-sigchild --enable-mbstring --enable-mbregex --enable-bcmath --enable-sockets --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-zlib-dir --with-cdb --with-openssl --with-curl=/usr/lib/curl-7.62.0 --with-iconv # make # make install


--------------- 配置環境變量 --------------------- # vim ~/.bashrc 添加下面三行 PATH=$PATH:$HOME/bin export PATH alias php=/usr/local/php/bin/php # source ~/.bashrc ------------------ 配置文件 -------------------- # cd /usr/local/php # cp /usr/local/src/php-7.3.4/php.ini-development ./lib/php.ini ----------------- httpd.conf 配置 ------------------ mime_module 中追加下面兩行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps

# service httpd stop

# service httpd start

3、遇到的問題

Q1:configure: error: libxml2 not found. Please check your libxml2 installation. A1:yum install libxml2-devel Q2:configure: error: Cannot find OpenSSL's <evp.h>
A2:yum install openssl openssl-devel Q3:configure: error: cURL version 7.15.5 or later is required to compile php with cURL support A3:# cd /usr/local/src wget https://curl.haxx.se/download/curl-7.62.0.tar.gz
    # tar -zxvf curl-7.62.0.tar.gz # cd curl-7.62.0 # ./configure --prefix=/usr/lib/curl-7.62.0 # make # make install Q4:configure: error: jpeglib.h not found. A4:yum install libjpeg libjpeg-devel Q5:configure: error: png.h not found. A5:yum install libpng libpng-devel Q6:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. A6:yum install autoconf

 

四、配置域名,測試

。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM