CentOS 7.3 LNAMP 安装文档
安装步骤
1.安装nginx
1.1 停止原有web服务
1.2 安装组件&依赖包
yum -y install epel-release && yum repolist
yum -y install wget vim gcc gcc-c++ cmake make automake autoconf libtool bison ncurses ncurses-devel openssl-devel perl-Data-Dumper libxml2-devel bzip2-devel openssl-devel zlib libpng-devel
1.3 下载nginx源码包
cd /usr/src
wget http://nginx.org/download/nginx-1.12.2.tar.gz
1.4 编译安装
useradd -M -s /sbin/nologin nginx
tar zxf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-mail --with-mail_ssl_module
make && make install
编译项说明 | |
---|---|
--prefix=/usr/local/nginx | 指定安装路径 |
--with-http_stub_status_module | 声明启用service status页 |
--with-http_ssl_module | 启用ssl模块,以支持https请求 |
1.5 启动服务:
/usr/local/nginx/nginx -c /usr/local/nginx/conf/nginx.conf
1.6 添加防火墙端口通过规则: // 腾讯云CVM的CentOS默认没启动防火墙,可忽略此步
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld
2.安装mySQL
准备工作(为了避免配置文件或命令冲突)
1.将现有系统rpm的mariadb 和 mariadb-server卸载
2.删除配置文件
rm -rf /etc/my.cnf
2.1 添加运行mySQL的普通账户
useradd -M -s /sbin/nologin mysql
2.2 下载 mySQL源码包
cd /usr/src
wget https://github.com/mysql/mysql-server/archive/5.6.zip
yum -y install unzip
unzip 5.6.zip 1>/dev/null
2.3 编译安装
cd mysql-server-5.6
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 -DSYSCONFDIR=/usr/local/mysql-5.6 -DMYSQL_DATADIR=/usr/local/mysql-5.6/data -DINSTALL_MANDIR=/usr/share/man -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql-5.6.sock -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
make && make install
编译项说明 | |
---|---|
-DCMAKE_INSTALL_PREFIX | 指定安装位置 |
-DSYSCONFDIR | 指定配置文件目录位置 |
-DMYSQL_DATADIR | 指定数据库文件目录位置 |
-DINSTALL_MANDIR | 指定帮助手册存放目录 |
-DMYSQL_TCP_PORT | 指定port |
-DMYSQL_UNIX_ADDR | 指定套接字文件 |
-DDEFAULT_CHARSET | 指定默认字符集 |
-DEXTRA_CHARSETS | 附属字符集 |
-DDEFAULT_COLLATION | 设置mysql的默认字符校对 |
-DWITH_SSL | 支持ssl |
-DWITH_EMBEDDED_SERVER | 构建嵌入式mysql库 |
-DENABLED_LOCAL_INFILE | 支持从本地导入数据 |
-DWITH_INNOBASE_STORAGE_ENGINE | 支持innodb引擎 |
2.4 MySQL初始化
cd /usr/local/mysql-5.6
chown -R mysql.mysql .
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.6 --datadir=/usr/local/mysql-5.6/data
2.5 生成MySQL Sys V脚本
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
2.6 启动服务设置开机启动
chkconfig mysqld on
2.7 配置MySQL环境变量
echo "export PATH=$PATH:/usr/local/mysql-5.6/bin" >> /etc/profile
. /etc/profile
2.8 启动mySQL
/etc/init.d/mysqld start
3.安装PHP
3.1 下载PHP源码
cd /usr/src
wget http://cn2.php.net/distributions/php-5.6.33.tar.gz
3.2 编译安装
tar zxf php-5.6.33.tar.gz
cd php-5.6.33/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-libxml-dir --with-openssl --with-pcre-regex --with-zlib --with-bz2 --with-pcre-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql-5.6 --with-mysqli=/usr/local/mysql-5.6/bin/mysql_config --enable-zip --enable-maintainer-zts --enable-fpm --enable-mail --enable-sockets
make && make install
cp php.ini-development /usr/local/php/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
3.3 配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
在顶部添加以下内容
user nginx;
在http标签内添加(或者修改成)以下内容
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php; \\加上index.php
}
location ~ \.php{
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/htmlfastcgi_script_name;
include fastcgi_params;
}
}
3.4 配置PHP
vim /usr/local/php/etc/php-fpm.conf
查找到以下等号左边的内容,并修改等号右边的内容为以下值(数值你可以自己按需修改)
user = nginx
group = nginx
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
3.5 启动服务
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm
4.安装Apache
4.1 apr 安装
cd /usr/src
wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz
tar zxf apr-1.6.3.tar.gz
cd apr-1.6.3/
./configure --prefix=/usr/local/apr
make && make install
4.2 apr-util安装
cd /usr/src/
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
tar zxf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
4.3 Apache 安装
cd /usr/src
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.29.tar.gz
tar zxf httpd-2.4.29.tar.gz
cd httpd-2.4.29/
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-modules=all --enable-mods-shared=all --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre --with-libxml2 --with-mpm=event --enable-mpms-shared=all
make && make install
4.4 配置apache环境变量
vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
. /etc/profile.d/httpd.sh
4.5 配置Apache支持PHP
vim /etc/httpd/httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
AddHandler php5-script .php
AddType text/html .php
</IfModule>
测试 PHP 和 Nginx 的连接
vim /usr/local/nginx/html/info.php
<?php
phpinfo();
?>
使用浏览器打开 http://IP/info.php
如果能看到显示相关信息,则表示安装成功
测试mysql和和php的连接
vim /usr/local/nginx/html/mysql.php
<?php
mysql_connect("localhost","root","",'test') or die("NOT");
echo "Success";
jdbc
?>
使用浏览器打开 http://IP/mysql.php
如果能看到显示Success相关信息,则表示安装成功