LAMP
一、基础
1.LAMP概述
Apache:实现网页共享传输
MySQL:实现数据存储
PHP :实现页面解析的解析器
浏览器 :仅能解析简单的HTML语言,无法直接解析PHP语言
部署方式
(1)yum安装
优点:安装部署方便,快速
缺点:软件版本固定,版本较低
(2)源码安装
优点:版本可自选,自定义性强
缺点:难度较大,维护相对困难
二、LAMP搭建
[root@localhost user1]# yum -y install gcc*
1.安装libxml2
[root@localhost libxml2-2.6.30]# yum -y install libxml2-devel python-devel [root@localhost libxml2-2.6.30]# cd /lamp/libxml2-2.6.30/ [root@localhost libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2 && make && make install [root@localhost libxml2-2.6.30]# echo $?
0
2.安装libmcrypt
[root@localhost libmcrypt-2.5.8]# cd /lamp/libmcrypt-2.5.8/ [root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt && make && make install [root@localhost libxml2-2.6.30]# echo $? 0 [root@localhost libmcrypt-2.5.8]# cd /lamp/libmcrypt-2.5.8/libltdl/ #安装libltdl,也在libmcrypt的源码目录中,非新软件 [root@localhost libltdl]# ./configure --enable-ltdl-install && make && make install [root@localhost libxml2-2.6.30]# echo $? 0
3.安装mhash
[root@localhost mhash-0.9.9.9]# cd /lamp/mhash-0.9.9.9/ [root@localhost mhash-0.9.9.9]# ./configure && make && make install #默认装在/usr.local/lib下 [root@localhost mhash-0.9.9.9]# echo $? 0
4.安装mcrypt
[root@localhost lamp]# cd /lamp/mcrypt-2.6.8/ [root@localhost mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/libmcrypt:/usr/local/lib #LD_LIBRARY_PATH用来指定libmcrypt和mhash的库的位置 [root@localhost mcrypt-2.6.8]# ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt && make && make install [root@localhost mcrypt-2.6.8]# echo $? 0
5.安装zlib
[root@localhost mcrypt-2.6.8]# cd /lamp/zlib-1.2.8/ [root@localhost zlib-1.2.8]# ./configure && make && make install [root@localhost zlib-1.2.8]# echo $? 0
6.安装libpng
[root@localhost zlib-1.2.8]# cd /lamp/libpng-1.6.16/ [root@localhost libpng-1.6.16]# ./configure --prefix=/usr/local/libpng && make && make install [root@localhost libpng-1.6.16]# echo $? 0
7.安装jpeg
[root@localhost jpeg-9a]# cd /lamp/jpeg-9a/ [root@localhost jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static && make && make install [root@localhost libpng-1.6.16]# echo $? 0
8.安装freetype
[root@localhost lamp]# cd /lamp/freetype-2.5.5/ [root@localhost freetype-2.5.5]# ./configure --prefix=/usr/local/freetype && make && make install [root@localhost freetype-2.5.5]# echo $? 0
9.安装apache
[root@localhost httpd-2.4.10]# cp -a /lamp/apr-1.4.5 /lamp/httpd-2.4.10/srclib/apr [root@localhost httpd-2.4.10]# cp -a /lamp/apr-util-1.3.12 /lamp/httpd-2.4.10/srclib/apr-util [root@localhost lamp]# cd /lamp/pcre-8.32/ [root@localhost pcre-8.32]# ./configure && make && make install [root@localhost pcre-8.32]# echo $? 0 [root@localhost pcre-8.32]# yum -y install openssl-devel [root@localhost pcre-8.32]# cd /lamp/httpd-2.4.10/ [root@localhost httpd-2.4.10]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/apache2/etc --with-included-apr --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-ssl && make && make install [root@localhost httpd-2.4.10]# echo $? 0
[root@localhost httpd-2.4.10]# vim /usr/local/apache2/etc/httpd.conf Listen 0.0.0.0:80 ServerName localhost:80 [root@localhost httpd-2.4.10]# /usr/local/apache2/bin/apachectl start [root@localhost httpd-2.4.10]# netstat -antp
10.安装ncurses
[root@localhost ncurses-5.7]# yum -y install ncurses-devel [root@localhost httpd-2.4.10]# cd /lamp/ncurses-5.7/ [root@localhost ncurses-5.7]# ./configure --with-shared --without-debug --without-ada --enable-overwrite && make && make install [root@localhost ncurses-5.7]# !ech echo $? 0
11.安装cmake和bison
[root@localhost ncurses-5.7]# yum -y install cmake bison
12.安装Mysql
[root@localhost mysql-5.6.22]# useradd -r -s /sbin/nologin mysql #编译安装前需要为其创建用户 [root@localhost ncurses-5.7]# cd /lamp/mysql-5.6.22/ [root@localhost mysql-5.6.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STOREGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READING=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 && make && make install [root@localhost mysql-5.6.22]# echo $? 0
[root@localhost mysql-5.6.22]# cd /usr/local/mysql/ [root@localhost mysql]# chown -R root . [root@localhost mysql]# chown -R mysql data [root@localhost mysql]# cp -a /lamp/mysql-5.6.22/support-files/my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y [root@localhost mysql]# cd /usr/local/mysql/ #一定要切换到安装主目录下,然后执行下一步 [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql #初始化成功的标识:2个OK
Installing MySQL system tables...
200522 1:10:00 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
200522 1:10:00 [Note] ./bin/mysqld (mysqld 5.5.60-log) starting as process 19275 ...
OK
Filling help tables...
200522 1:10:00 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
200522 1:10:00 [Note] ./bin/mysqld (mysqld 5.5.60-log) starting as process 19282 ...
OK
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql & [root@localhost mysql]# /usr/local/mysql/bin/mysqladmin -uroot password 123 [root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p123 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> Ctrl-C -- exit!
13.安装PHP
[root@localhost lamp]# cd /lamp/php-7.3.18/ [root@localhost php-7.3.18]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-mcrypt-dir=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --with-gd --without-pear && make && make install [root@localhost php-7.3.18]# echo $? 0 [root@localhost php-7.3.18]# mkdir /usr/local/php/etc [root@localhost php-7.3.18]# cp /lamp/php-7.3.18/php.ini-production /usr/local/php/etc/php.ini [root@localhost php-7.3.18]# vim /usr/local/apache2/etc/httpd.conf AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps [root@localhost php-7.3.18]# /usr/local/apache2/bin/apachectl stop [root@localhost php-7.3.18]# /usr/local/apache2/bin/apachectl start [root@localhost php-7.3.18]# vim /usr/local/apache2/htdocs/test.php <?php phpinfo(); ?>
14.为PHP安装Openssl模块
[root@localhost php-7.3.18]# cd /lamp/php-7.3.18/ext/openssl/ [root@localhost openssl]# mv config config0.m4 config.w32 [root@localhost openssl]# mv config0.m4 config.m4 [root@localhost openssl]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. [root@localhost openssl]# yum -y install autoconf [root@localhost openssl]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 [root@localhost openssl]# ./configure --with-openssl --with-php-config=/usr/local/php/bin/php-config/ && make && make install [root@localhost openssl]# echo $? 0
15.为PHP安装memcache模块
[root@localhost lamp]# cd /lamp/pecl-memcache-NON_BLOCKING_IO_php7/ [root@localhost pecl-memcache-NON_BLOCKING_IO_php7]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 [root@localhost pecl-memcache-NON_BLOCKING_IO_php7]# ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install [root@localhost pecl-memcache-NON_BLOCKING_IO_php7]# echo $? 0
16.修改PHP配置文件
[root@localhost lamp]# vim /usr/local/php/etc/php.ini extension_dir="/usr/local/php/lib/php/extensions/no-debug-zts-20180731/" extension="openssl.so" extension="memcache.so"
17.安装memcachae服务
[root@localhost lamp]# yum -y install libevent-devel [root@localhost lamp]# cd /lamp/memcached-1.6.6/ [root@localhost memcached-1.6.6]# ./configure --prefix=/usr/local/memcache && make && make install [root@localhost memcached-1.6.6]# echo $? 0 [root@localhost memcached-1.6.6]# useradd -r -s /sbin/nologin memcache [root@localhost memcached-1.6.6]# /usr/local/memcache/bin/memcached -umemcache & [4] 53565 [root@localhost memcached-1.6.6]# netstat -antp
18.安装PHPmyadmin
[root@localhost lamp]# cp -a /lamp/phpMyAdmin-4.9.5-all-languages /usr/local/apache2/htdocs/phpmyadmin [root@localhost lamp]# cd /usr/local/apache2/htdocs/phpmyadmin/ [root@localhost phpmyadmin]# cp -a config.sample.inc.php config.inc.php [root@localhost phpmyadmin]# vim config.inc.php $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['auth_type'] = 'http';
http://10.0.0.150/phpmyadmin/ index.php root 123
19.设置开启自启
[root@localhost htdocs]# vim /etc/rc.local /usr/local/apache2/bin/apachectl start /usr/local/mysql/bin/mysqld_safe --user=mysql & /usr/local/memcache/bin/memcached -umemached &
20.项目部署
[root@localhost lamp]# wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz [root@localhost lamp]# tar -xzvf 1.1-17.10.30-release.tar.gz [root@localhost lamp]# cp -r /lamp/build/ /usr/local/apache2/htdocs/blog
http://10.0.0.150/blog/ install.php
[root@localhost lamp]# ps -aux | grep httpd root 43253 0.0 0.4 255484 11884 ? Ss 06:30 0:00 /usr/local/apache2/bin/httpd -k start daemon 53847 0.0 0.5 747624 15492 ? Sl 07:34 0:00 /usr/local/apache2/bin/httpd -k start daemon 53848 0.0 0.5 883340 15464 ? Sl 07:34 0:00 /usr/local/apache2/bin/httpd -k start daemon 53849 0.0 0.5 679848 14588 ? Sl 07:34 0:00 /usr/local/apache2/bin/httpd -k start daemon 53931 0.0 0.6 819524 19380 ? Sl 07:34 0:00 /usr/local/apache2/bin/httpd -k start root 54302 0.0 0.0 110372 900 pts/1 S+ 07:46 0:00 grep --color=auto httpd [root@localhost lamp]# setfacl -R -m u:daemon:rwx /usr/local/apache2/htdocs/blog/