lanmp平台架构的搭建:
LAMP(Linux-Apache-MySQL-PHP)网站架构是Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言
#####################################################################################
mysql 的安装
mysql的基本安装步骤:
(1)mysql的编译需要用到cmake 得先安装cmake
接下来可以安装一些已经所知道的一些依赖软件
【 gcc-c++ncurses-devel 】
(2)解压mysql的包 (注意 mysql解压后较大,要留有超过10G的内存)
(3)进入mysql的一级目录 进行编译
(4)make && make insatll
(5)进行mysql的初始化及相关设定
mysql的具体步骤:
[root@server1 ~]# ls
anaconda-ks.cfg install.log nginx-1.12.0
bansys.zip install.log.syslog nginx-1.12.0.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.17.tar.gz php-5.6.20.tar.bz2
[root@server1 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
[root@server1 ~]# yum install -y gcc-c++ ncurses-devel
[root@server1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 19G 1.2G 17G 7% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/vda1 485M 33M 427M 8% /boot
[root@server1 ~]# tar zxf mysql-boost-5.7.17.tar.gz 解压
[root@server1 ~]# cd mysql-5.7.17/ 进入一级目录进行编译
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DWITH_BOOST=boost/boost_1_59_0/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \ #数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安装innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #安装 archive 存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #安装 blackhole 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \ #安装数据库分区
-DENABLED_LOCAL_INFILE=1 \ #允许从本地导入数据
-DWITH_READLINE=1 \ #快捷键功能
-DWITH_SSL=yes \ #支持 SSL
-DDEFAULT_CHARSET=utf8 \ #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \ #校验字符
-DEXTRA_CHARSETS=all \ #安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 \ #MySQL监听端口
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[root@server1 mysql-5.7.17]# make && make install 编译并安装
[root@server1 mysql-5.7.17]# groupadd -g 27 mysql
[root@server1 mysql-5.7.17]# useradd -u 27 -g 27 -s /sbin/nologin -M -d/usr/local/lnmp/mysql/data mysql 添加一个mysql用户
[root@server1 mysql-5.7.17]# vim /etc/passwd
[root@server1 mysql-5.7.17]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# ls
bin docs lib mysql-test share
COPYING include man README support-files
[root@server1 mysql]# ll
total 56
drwxr-xr-x 2 root root 4096 Jul 21 10:47 bin
-rw-r--r-- 1 root root 17987 Nov 28 2016 COPYING
drwxr-xr-x 2 root root 4096 Jul 21 10:46 docs
drwxr-xr-x 3 root root 4096 Jul 21 10:46 include
drwxr-xr-x 4 root root 4096 Jul 21 10:47 lib
drwxr-xr-x 4 root root 4096 Jul 21 10:46 man
drwxr-xr-x 10 root root 4096 Jul 2110:48 mysql-test
-rw-r--r-- 1 root root 2478 Nov 28 2016 README
drwxr-xr-x 28 root root 4096 Jul 2110:48 share
drwxr-xr-x 2 root root 4096 Jul 21 10:48 support-files
[root@server1 mysql]# chown mysql.mysql . -R 更改文件的用户组
[root@server1 mysql]# cd ..
[root@server1 lnmp]# cd mysql/bin/
[root@server1 bin]# vim ~/.bash_profile 更改系统环境变量
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[root@server1 bin]# source ~/.bash_profile 使得更改后的文件即时生效
[root@server1 bin]# cd ..
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# cd /etc/
[root@server1 etc]# rpm -qf /etc/my.cnf
mysql-libs-5.1.71-1.el6.x86_64
[root@server1 etc]# cp my.cnf my.cnf.bak 因为我们复制一个my.cnf文件所以将其先备份
[root@server1 etc]# cd
[root@server1 ~]# cd /usr/local/lnmp/mysql/support-files/
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf 启动mysql时会读取/etc/.cnf 所以我们将其有用的复制过去给他
cp: overwrite `/etc/my.cnf'? y
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld 可执行脚本一般会放在/etc/init.d里
[root@server1 support-files]# cd
[root@server1 ~]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# cd /usr/local/lnmp/mysql/bin/
[root@server1 bin]# which mysql
/usr/local/lnmp/mysql/bin/mysql
[root@server1 bin]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/usr/local/lnmp/mysql/data/mysql.sock' (2)
[root@server1 bin]# mysql --initialize --user=mysql
mysql: [ERROR] unknown option '--initialize'
[root@server1 bin]# mysqld --initialize --user=mysql 对mysql进行初始化(会得到一个初始密码)
[root@server1 mysql]# ll
total 60
drwxr-xr-x 2 root root 4096 Jul 21 10:47 bin
-rw-r--r-- 1 root root 17987 Nov 28 2016 COPYING
drwxr-x--- 5 mysql mysql 4096 Jul 21 11:18 data
drwxr-xr-x 2 root root 4096 Jul 21 10:46 docs
drwxr-xr-x 3 root root 4096 Jul 21 10:46 include
drwxr-xr-x 4 root root 4096 Jul 21 10:47 lib
drwxr-xr-x 4 root root 4096 Jul 21 10:46 man
drwxr-xr-x 10 root root 4096 Jul 21 10:48 mysql-test
-rw-r--r-- 1 root root 2478 Nov 28 2016 README
drwxr-xr-x 28 root root 4096 Jul 21 10:48 share
drwxr-xr-x 2 root root 4096 Jul 21 11:12 support-files
[root@server1 mysql]# chown mysql.mysql . -R
[root@server1 mysql]# ls data/
auto.cnf ibdata1 ib_logfile1 performance_schema
ib_buffer_pool ib_logfile0 mysql sys
[root@server1 mysql]# chown root.root . -R 改回mysql里文件的用户组权限
[root@server1 mysql]# chown mysql data -R 但是mysql的数据文件data还是mysql
[root@server1 mysql]# cd
[root@server1 ~]# /etc/init.d/mysqld start 开启mysql服务
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server1.err'.
SUCCESS!
[root@server1 ~]# mysql_secure_installation 更改mysql密码
[root@server1 ~]# mysql -uroot -p 登陆mysql
Enter password:
Welcome to the MySQL monitor. Commandsend with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rightsreserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
mysql> exit
Bye
php的安装:
php的基本安装(源码安装三部曲):
(1)解压 php 包
(2)编译
(3)make && makeinstall
这里要注意 php 编译时的依赖包很多,可以根据其编译出错的提示来下载相应的东西
php的具体安装步骤:
[root@server1 ~]# tar jxf php-5.6.20.tar.bz2 解压
[root@server1 ~]# cd php-5.6.20 进入解压后的一级目录
[root@server1 php-5.6.20]# yum install -y curl-devel libjpeg-turbo-develfreetype-devel gmp-devel net-snmp-devel bison libxml2-devel 如果知道一些所需要的依赖包,可以提前下载
…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
这里还有三个yum源里没有,需要着相应的安装包来安装包
[root@server1 ~]# rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpmlibmcrypt-devel-2.5.8-9.el6.x86_64.rpm
warning: libmcrypt-2.5.8-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, keyID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:libmcrypt ########################################### [ 50%]
2:libmcrypt-devel ########################################### [100%]
[root@server1 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
warning: re2c-0.13.5-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID0608b895: NOKEY
Preparing... ###########################################[100%]
1:re2c ########################################### [100%]
………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp--with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir--with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash 进行编译 注意一定要在他的一级目录里
checking for FreeType 2... yes
checking for T1lib support... no
checking whether to enable truetype string function in GD... no
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
&& 这里报错显示找不到 png.h 的头文件,像这种看不出来所需要的哪个包,我们可以使用命令来查询 &&
&& 使用 yumprovides */+所需的头件 ,再根据查询提示来下载相应的包
[root@server1 php-5.6.20]# yum provides */png.h
[root@server1 php-5.6.20]# yum install -ylibpng-devel-1.2.49-1.el6_2.x86_64
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp--with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir--with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash 再进行编译
[root@server1 php-5.6.20]# make 编译成功就可以make && make install了
[root@server1 php-5.6.20]# make install
php的配置
( 使得可以网页访问mysql )
[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.20]# cd sapi/fpm/
[root@server1 fpm]# file init.d.php-fpm
init.d.php-fpm: POSIX shell script text executable
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm 可执行脚本一般会放在/etc/init.d里
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm 给/etc/init.d/php-fpm可执行权限
[root@server1 fpm]# cd /usr/local/
[root@server1 local]# cd lnmp/php/etc/
[root@server1 etc]# vim php.ini 编辑配置文件
925 date.timezone = Asia/Shanghai 更改时区
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid
[root@server1 etc]# /etc/init.d/php-fpm start 开启php-fpm
Starting php-fpm done
[root@server1 etc]# cd ..
[root@server1 php]# vim ~/.bash_profile 添加php的路径
8 # User specific environment and startup programs
9
10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[root@server1 php]# source ~/.bash_profile 使更改的文件即时生效
[root@server1 php]# netstat -antlp |grep :9000 查看9000端口开启状态 (php--9000端口)
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7796/php-fpm
[root@server1 php]# cd ..
[root@server1 lnmp]# cd nginx/conf/
[root@server1 conf]# vim nginx.conf 更改配置文件,打开nginx服务
51 location / {
52 root html;
53 index index.php index.html index.htm; 将index.php放在前面,首先访问
54 }
73 location ~ \.php$ {
74 root html;
75 fastcgi_pass 127.0.0.1:9000;
76 fastcgi_index index.php;
77 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name ;
78 include fastcgi.conf;
79 }
[root@server1 conf]# nginx -t 检查配置文件是否有语法错误
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax isok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test issuccessful
[root@server1 conf]# nginx 打开nginx
[root@server1 conf]# cd ..
[root@server1 nginx]# cd html/
[root@server1 html]# vim index.php 编辑php测试页
phpinfo()
?>
~
论坛搭建:
使用安装包来快速配置一个论坛
具体步骤如下:
[root@server1 ~]# unzip Discuz_X3.2_SC_UTF8.zip 搞到论坛的安装包解压
[root@server1 ~]# mv upload/ /usr/local/lnmp/nginx/html/bbs 将其移动到可发布目录
[root@server1 ~]# cd /usr/local/lnmp/nginx/html/bbs
[root@server1 bbs]# chmod 777 config/ data/ uc_client/ uc_server/ -R 给他们足够的权限,不然网页配置时会悲剧的
[root@server1 bbs]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# vim php.ini
1000 ; http://php.net/pdo_mysql.default-socket
1001 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock
1149 ; http://php.net/mysql.default-socket
1150 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
1208 ; http://php.net/mysqli.default-socket
1209 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 etc]# /etc/init.d/php-fpm reload 重启php-fpm服务
Reload service php-fpm done
[root@server1 etc]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# chmod 755 /usr/local/lnmp/mysql/data/ 也得调整mysql 数据文件的权限
[root@server1 mysql]# cd
[root@server1 ~]# cd /usr/local/lnmp/nginx/html/bbs/install/
[root@server1 install]# rm -f index.php 在网页上完全配置好了再来删除这个文件
如果在网页上配置完成后不删除这个php文件,下次就会需要重新配置
如果在万页上没有配置时就删除了这个文件,那么恭喜你 需要重新再来
#####################################################################################
想要在原先编译好的php中加入memcacha或者ImageMagick等拓展模块可以使用 phpize 命令
[root@server1 ~]# tar zxf memcache-2.2.5.tgz 解压memcache包
[root@server1 ~]# cd memcache-2.2.5 切入memcache一级解压目录
[root@server1 memcache-2.2.5]# phpize 扩展php扩展模块的
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@server1 memcache-2.2.5]# ./configure 在一级目录里进行编译
[root@server1 memcache-2.2.5]# make make使之生成可执行文件
[root@server1 memcache-2.2.5]# make install 安装可执行文件
[root@server1 no-debug-non-zts-20131226]# php -m |grep memcache
[root@server1 no-debug-non-zts-20131226]# cd /etc/
[root@server1 etc]# cd /usr/local/
[root@server1 local]# cd lnmp/php/
[root@server1 php]# ls
bin etc include lib php sbin var
[root@server1 php]# cd etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php.ini
871 extension=memcache.so
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[root@server1 etc]# php -m |grep memcache
memcache
[root@server1 etc]# cd
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# yum install -y memcached
[root@server1 memcache-2.2.5]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@server1 memcache-2.2.5]# netstat -antlp |grep :11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 10485/memcached
tcp 0 0 :::11211 :::* LISTEN 10485/memcached
[root@server1 memcache-2.2.5]# yum install -y telnet
[root@server1 memcache-2.2.5]# cp example.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# cp memcache.php/usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# vim memcache.php
20 $VERSION='$Id: memcache.php,v 1.22008/09/11 19:21:06 mikl Exp $';
21
22 define('ADMIN_USERNAME','admin'); // Admin Username
23define('ADMIN_PASSWORD','westos'); // Admin Password
24 define('DATE_FORMAT','Y/m/dH:i:s');
25 define('GRAPH_SIZE',200);
26 define('MAX_ITEM_DUMP',50);
27
28 $MEMCACHE_SERVERS[] = '127.0.0.1:11211';// add more as an array
29 #$MEMCACHE_SERVERS[] ='mymemcache-server2:11211'; // add more as an array
30