LAMP环境版本
- 操作系统:Centos 7
- Mysql:5.7.11
- Apache:2.4.18
- PHP:7.0.4
安装Mysql
为mysql创建专属帐号
- shell> tar zxvf mysql-5.7.11.tar.gz
- shell> cd mysql-5.7.11
- shell> cmake .
- shell> make
- shell> make install
安装后设置
注意:从Mysql5.7开始,mysql默认安装后不再是空密码,而是生成一个随机密码,除非初始化时指定--initialize-insecure。
所有用户拥有对于MySQL默认安装test数据库的访问权限(即使没有授予权限)为了安全考虑5.7版本中不在有test数据库。
更为重要的是,MySQL 5.7版本提供了更为简单SSL安全访问配置,并且默认连接就采用SSL的加密方式
- shell> cd /usr/local/mysql
- shell> chown -R mysql . #修改目录所有者为mysql
- shell> chgrp -R mysql . #修改目录所属组为mysql
- shell> bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql #初始化mysql,初始化为空,数据库存放目录指定为/data/mysql
- shell> bin/mysql_ssl_rsa_setup #启动ssl加密方式连接
- shell> chown -R root . #修改目录所有者为root
- shell> chown -R mysql /data/mysql #修改数据库目录所有者为mysql
安装mysql服务
只需要将mysql安装目录下的mysql.server复制过去就OK了。
- shell> cp support-files/mysql.server /etc/init.d/mysql.server
- shell> service mysql start #启动服务
安装Apache
源码编译安装
- shell> ./configure --prefix=/usr/local/apahche
- --enable-so #动态共享对象,可实现模块动态生效
- --enable-rewrite #启用Rewrite功能
- --enable-ssl #支持SSL/TLS,可以实现https访问
- --enable-deflate #支持压缩
- shell> make
- shell> make install
apache的启动与关闭
- shell> /usr/local/apache/bin/apachectl start #启动
- shell> /usr/local/apache/bin/apachectl stop #停止
- shell> /usr/local/apache/bin/apachectl restart #重启
将apache添加到Linux的服务并设置自启动
- shell> cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd #设置为系统服务
- shell> ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S80httpd #在启动级别3中自启动
- shell> service httpd restart #通过服务来重启apache
运行测试页面
在客户端浏览器上输入服务器的IP地址,看是否能正常打开网页。
常见问题
- configure: error: APR not found.
解决方法: 安装对应依赖库
- shell> yum install apr apr-util-devel
- configure: error: pcre-config for libpcre not found.
解决方法:安装对应依赖库
- yum install pcre pcre-devel
- 启动apache时报:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.44.13.173. Set the 'ServerName' directive globally to suppress this message
解决方法:修改配置文件httpd.conf设置ServerName localhost:80
安装PHP
安装依赖库
-
zlib
- shell> tar xf zlib.1.2.8.tar.gz
- shell> cd zlib.1.2.8
- shell> ./configure
- shell> make test
- shell> make install
- GD库
libpng
- shell> tar xf libpng-1.6.21
- shell> cd libpng-1.6.21
- shell> ./configure --prefix=/usr/local/libpng
- shell> make
- shell> make check
- shell> make install
- shell> tar xf jpegsrc.v9.tar.gz
- shell> cd jpeg-9
- shell> ./configure --prefix=/usr/local/libjpeg
- shell> make
- shell> make install
- libcurl-devel
- yum install libcurl-devel
-
openssl-devel
- yum install openssl-devel
-
libxslt-devel
- yum install libxslt-devel
-
libxml2-devel
- yum install libxml2-devel
-
freetype 字体操作库
- shell> tar xf freetype-2.6.3.tar.bz2
- shell> sh autogen.sh
- shell> ./configure --prefix=/usr/local/freetype
- shell> make
- shell> make install
编译安装PHP
- ./configure --prefix=/usr/local/php
- --with-apxs2=/usr/local/apache/bin/apxs
- --with-curl
- --with-freetype-dir=/usr/local/freetype
- --with-gd
- --with-gettext
- --with-iconv-dir
- --with-mysqli
- --with-openssl
- --with-pcre-regex
- --with-pdo-mysql
- --with-pdo-sqlite
- --with-pear
- --with-png-dir=/usr/local/libpng
- --with-jpeg-dir=/usr/local/libjpeg
- --with-xsl
- --with-zlib
- --enable-fpm
- --enable-bcmath
- --enable-libxml
- --enable-inline-optimization
- --enable-gd-native-ttf
- --enable-mbregex
- --enable-mbstring
- --enable-opcache
- --enable-pcntl
- --enable-shmop
- --enable-soap
- --enable-sockets
- --enable-sysvsem
- --enable-xml
- --enable-zip
- (./configure '--prefix=/usr/local/php' '--with-freetype-dir=/usr/local/freetype' '--with-gd' '--with-gettext' '--with-iconv-dir' '--with-mysqli' '--with-openssl' '--with-pcre-regex' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-pear' '--with-png-dir=/usr/local/libpng' '--with-jpeg-dir=/usr/local/libjpeg' '--with-xsl' '--with-zlib' '--enable-fpm' '--enable-bcmath' '--enable-libxml' '--enable-inline-optimization' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-opcache' '--enable-pcntl' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvsem' '--enable-xml' '--enable-zip' '--with-curl=/usr/local/curl')指定curl为openssl
- shell> make
- shell> make install
Apache与PHP的关联
PHP安装成功后会在apache的modules目录下生成一个libphp.so动态库文件,在apache的配置文件httpd.conf里自动增加一行- LoadModule php7_module modules/libphp7.so
- AddType application/x-httpd-php .php
- <?php
- phpinfo();