操作系统: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命令,会带来测试不成功!


来源:oschina
链接:https://my.oschina.net/u/4393607/blog/4948396