- 安装nginx
1.安装pcre
为了后续支持rewrite安装pcre
yum -y install pcre*
2.安装openssl
为了后续支持ssl
yum -y install openssl*
3.下载nginx源码安装包
cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
4.解压该安装包
tar -zxvf nginx-1.8.0.tar.gz
5.安装nginx
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0 --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
make
make install
6.启动nginx服务
mkdir /usr/local/nginx-1.8.0/logs
cd /usr/local/nginx-1.8.0/logs
touch error.log
/usr/local/nginx-1.8.0/sbin/nginx
7.在浏览器里输入http://192.168.1.101如果能看到welcome的欢迎页面就表示nginx安装成功了。 - 安装PHP5
1.安装各种lib库
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
2.下载php源码安装包
cd /usr/local/
wget http://cn2.php.net/get/php-5.6.9.tar.bz2/from/this/mirror
3.解压该安装包
tar -jxf php-5.6.9.tar.bz2
4.安装PHP
cd php-5.6.9
./configure --prefix=/usr/local/php-5.6.9 --with-config-file-path=/usr/local/php-5.6.9/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make
make test
make install
cp php.ini-production /usr/local/php-5.6.9/etc/php.ini
cp /usr/local/php-5.6.9/etc/php-fpm.conf.default /usr/local/php-5.6.9/etc/php-fpm.conf
5.启动PHP服务并检查php服务是否起来
/usr/local/php-5.6.9/sbin/php-fpm
netstat -lnt | grep 9000 - 配置nginx
mkdir -p /data/logs/nginx/
mkdir -p /data/site/test.ttlsa.com/
vim /data/site/test.ttlsa.com/info.php
<?php
phpinfo();
?>
保存退出
vim /usr/local/nginx-1.8.0/conf/nginx.conf
server {
listen 80;
server_name test.ttlsa.com;
access_log /data/logs/nginx/test.ttlsa.com.access.log;
index index.php index.html index.html;
root /data/site/test.ttlsa.com;
location ~ .*\.(php|php5)?$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
保存退出
/usr/local/nginx-1.8.0/sbin/nginx -s reload
然后在浏览器里输入http://192.168.1.101/info.php如果能出现PHP的信息页面则表示配置成功了。 - 安装MYSQL
1.安装基础环境包
yum –y install autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel
2.下载MYSQL安装包
cd /usr/local/
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz/from/http://cdn.mysql.com/
3.解压MYSQL安装包
tar zxvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.14-linux-glibc2.5-x86_64 mysql
4.创建Mysql用户,及数据库存放目录
useradd mysql -s /sbin/nologin -M
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql .
5.创建配置文件
vim /usr/local/mysql/my.cnf
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
6.mysql系统服务
cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
7.初始化
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
8.启动服务
/etc/init.d/mysqld start
9.进入mysql数据库
/usr/local/mysql/bin/mysql -p -uroot
密码为空
/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘
设置root密码为123456
至此LNMP基础环境就算搭建完毕了
PS:如果不希望后面使用mysql命令要输入全路径的话,可以在/etc/profile文件里将这个路径加入到全局变量里面:
vim /etc/profile
在文件的末尾加上
PATH=/usr/local/mysql/bin:$PATH
保存退出
. /etc/profile //让刚才的配置生效
至此LNMP环境就搭建完毕了。
时间: 2024-10-11 04:13:06