操作系統:CentOS Linux release 7.9
一、安裝Apache
1.安裝Apache依賴庫和相關軟件包
# wget -c http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz
[root@Linux tool]# tar zxvf apr-1.6.3.tar.gz
[root@Linux tool]# cd arp-1.6.3
[root@Linux apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@Linux apr-1.6.3]# make -j 8 && make install
# wget https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@Linux /]# yum install expat expat-devel
[root@Linux tool]# tar zxvf apr-util-1.6.1.tar.gz
[root@Linux tool]# cd apr-util-1.6.1
[root@Linux apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@Linux apr-util-1.6.1]# make -j 8 && make install[root@Linux apr-util-1.6.1]# make -j 8 && make install
#獲取資源一
[root@Linux tool]# wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
#獲取資源二
[root@Linux tool]# wget -c https://udomain.dl.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
[root@Linux tool]# tar zxvf pcre-8.41.tar.gz
[root@Linux tool]# cd pcre-8.41
[root@Linux pcre-8.41]# ./configure --prefix=/usr/local/pcre
[root@Linux pcre-8.41]# make -j 8 && make install
[root@Linux tool]# yum install zlib zlib-devel #安裝zlib庫
[root@Linux tool]# yum install epel-release
[root@Linux tool]# yum install make gcc-c++ cmake bison-devel ncurese-devel libtool bison perl perl-devel perl perl-deve
2.源碼編譯、安裝Apache
[root@Linux tool]# wget -c http://archive.apache.org/dist/httpd/httpd-2.4.29.tar.gz
[root@Linux tool]# tar zxvf httpd-2.4.29.tar.gz
[root@Linux tool]# cd httpd-2.4.29
#將相關庫文件複製到當前安裝"httpd-2.4.29/srclib/"目錄下
[root@Linux httpd-2.4.29]# cp -r /home/tool/apr-1.6.3 srclib/apr
[root@Linux httpd-2.4.29]# cp -r /home/tool/apr-util-1.6.1 srclib/apr-util
[root@Linux httpd-2.4.29]#./configure --prefix=/usr/local/apache2 --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \
--enable-so --enable-modules=most --enable-mods-shared=all --with-included-apr --enable-rewrite=shared
[root@Linux httpd-2.4.29]# make -j 8 && make install
[root@Linux htdocs]# find / -name libphp7.so
#沒有找到libphp7.so,原因是php安裝在前,Apache安裝在後,所以沒有產生該庫文件。
# vi /usr/local/apache2/conf/httpd.conf
Addtype application/x-httpd-php .php .phtml #加一條配置
Listen 8080 #80修改成8080,因nginx已經在跑80端口
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#/usr/local/apache2/bin/apachectl start
[root@Linux htdocs]# ps -ef|grep httpd
root 3988 4215 0 10:34 pts/1 00:00:00 grep --color=auto httpd
root 4523 1 0 10:28 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 4525 4523 0 10:28 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 4526 4523 0 10:28 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 4527 4523 0 10:28 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
看到上面的頁面,說明Apache安裝成功,接下來還需測試,是否能解析PHP文件?
[root@Linux htdocs]# cp /www/html/mysqli.php ./
看到上面這個頁面,說明Apahce還不能解析PHP文件,什麼原因?是Apahce的module的目錄下沒有生成libphp7.so模塊。
二.源碼編譯、安裝MySQL
1.下載MySQL 5.7.23 :
#wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.23.tar.gz
2.安裝依賴包:
# yum -y install make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel
3.解壓並創建MySQL組和用戶
#tar -zxvf mysql-boost-5.7.23.tar.gz
#groupadd mysql
#useradd -r -g mysql -s /bin/false mysql
3.開始編譯MySQL
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/db/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci - DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=boost -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_EMBEDDED_SERVER=1
[root@Linux db]# cat /proc/cpuinfo| grep "processor"| wc -l
8
# make -j 8 && make install #並行編譯
4.初始化數據庫
[root@Linux mysql-5.7.23]#mkdir /db/data
[root@Linux mysql-5.7.23]#chown -R mysql:mysql /db/data
[root@Linux mysql-5.7.23]#/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/db/data
[root@Linux mysql-5.7.23]# cp /usr/local/mysql/support-files/mysql.service /etc/init.d/msyqld
[root@Linux mysql-5.7.23]# chmod 755 /etc/init.d/mysqld
[root@Linux mysql-5.7.23]# chkcofnig --add mysqld
[root@Linux mysql-5.7.23]# chkconfig mysqld on
[root@Linux mysql-5.7.23]#servcie mysqld start
5.配置my.cnf文件
[root@Linux mysql-5.7.23]# vi /etc/my.cnf
explicit_defaults_for_timestamp=true
basedir=/usr/local/mysql
datadir=/db/data
socket=/tmp/mysqld.sock
symbolic-links=0
log-error=/var/log/mysqld.log
user=mysql
6.配置MySQL啓動腳本
[root@Linux mysql-5.7.23]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@Linux mysql-5.7.23]# chmod 755 /etc/init.d/mysqld
[root@Linux mysql-5.7.23]# chkconfig --add mysqldroot@Linux mysql-5.7.23]# service mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/db/data/Linux.pid).
[root@Linux db]# ps -aux|grep mysql
root 20495 0.0 2.0 1797788 164308 ? Sl 1月31 0:42 mysqld -uroot
root 22312 0.0 0.0 112824 980 pts/0 S+ 17:21 0:00 grep --color=auto mysql
[root@Linux db]# kill 20495
[root@Linux db]# service mysqld start
Starting MySQL. SUCCESS!
[root@Linux db]# mysql –uroot
mysql> SET PASSWORD=PASSWORD('*******') ;#設置密碼
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
7.配置環境變量
[root@Linux db]# vi /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
[root@Linux db]# source /etc/profile
三、源碼編譯、安裝PHP7
[root@Linux php-7.2.3]# yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype freetype-devel gd libpng libpng-devel openjpeg openjpeg-devel libjpeg libjpeg-devel libxml2 libxml2-devel zlib curl curl-devel
[root@Linux php-7.2.3]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc/ --enable-fpm --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip --with-gettext --enable-bcmath --enable-sockets --enable-sockets --enable-ctype
#make -j 8 && make install
collect2: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] Error 1
#make clean
#rm -f Makefile
#make ZEND_EXTRA_LIBS='-liconv'
/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
make: *** [libphp7.la] 錯誤 1
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@Linux libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
#make
In file included from progname.c:26:0:
./stdio.h:1010:1: 錯誤:‘gets’未聲明(不在函數內)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
make[2]: *** [progname.o] 錯誤 1
make: *** [sapi/cli/php] 錯誤 1
make: *** 正在等待未完成的任務....
/usr/bin/ld: ext/phar/.libs/util.o: undefined reference to symbol 'EVP_DigestInit@@libcrypto.so.10'
//usr/lib64/libcrypto.so.10: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] 錯誤 1
/usr/bin/ld: ext/phar/.libs/util.o: undefined reference to symbol 'EVP_DigestInit@@libcrypto.so.10'
//usr/lib64/libcrypto.so.10: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/phpdbg/phpdbg] 錯誤 1
/usr/bin/ld: ext/phar/.libs/util.o: undefined reference to symbol 'EVP_DigestInit@@libcrypto.so.10'
//usr/lib64/libcrypto.so.10: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/cgi/php-cgi] 錯誤 1
/usr/bin/ld: cannot find -lcrypt-liconv
collect2: error: ld returned 1 exit status
make: *** [libphp7.la] 錯誤 1
make: *** 正在等待未完成的任務....
/usr/bin/ld: cannot find -lcrypt-liconv
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] 錯誤 1
/usr/bin/ld: cannot find -lcrypt-liconv
collect2: error: ld returned 1 exit status
make: *** [sapi/cgi/php-cgi] 錯誤 1
/usr/bin/ld: cannot find -lcrypt-liconv
collect2: error: ld returned 1 exit status
make: *** [sapi/phpdbg/phpdbg] 錯誤 1
/usr/bin/ld: cannot find -lcrypt-liconv
collect2: error: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] 錯誤 1
以上報這麼多錯誤,就是因爲沒有找到libiconv,實際上是安裝了libiconv,如何解決此問題?只要在編譯的時候指定libiconv目錄即可,當前的目錄是“--with-iconv-dir=/home/tool/libiconv-1.14”
[root@Linux php-7.2.3]# ./confgiure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc/ --enable-mbstring --with-curl --enable-fpm --enable-mysqlnd --enable-bcmath --enable-sockets --enable-ctype --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-iconv-dir=/home/tool/libiconv-1.14
[root@Linux php-7.2.3]# make -j 8 && make install
............................................................................................................
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/home/tool/php-7.2.3/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers: /usr/local/php7/include/php/ext/pdo/
四、測試LAMP環境安裝的正確性
[root@Linux htdocs]# ls
index.html index.php mysqli.php pdomysql.php phpinfot.php
實戰技能:不建設以phpinfo.php命令,會帶來測試不成功!