##初始化MySQL数据库文件
#建立MySQL数据文件目录
mkdir -p /usr/local/mysql/data
#授权mysql用户管理MySQL的安装目录
chown -R mysql.mysql /usr/local/mysql
#光盘源安装依赖包,否则下一步的编译会报错
yum -y install libaio
#初始化MySQL数据库文件,会有很多信息提示,如果没有ERROR级别的错误,会有两个OK的字样,表示初始化成功,否则就要解决初始化的问题
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#拷贝MySQL启动脚本到MySQL的命令路径
cp support-files/mysql.server /etc/init.d/mysqld
#使脚本可执行
chmod +x /etc/init.d/mysqld
#启动MySQL数据库
/etc/init.d/mysqld start
#检查MySQL数据库是否启动
netstat -antup | grep mysql
#设置MySQL开机自启动
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld
#配置mysql命令的全局使用路径
ln -s /usr/local/mysql/bin/* /usr/local/bin/
#设置密码
mysqladmin -u root password '123123'
#安装Nginx
略
#启动Nginx
/usr/local/nginx/sbin/nginx
#检查端口及启动情况
netstat -antup | grep -E "80|3306"
#测试Nginx
wget 127.0.0.1
#安装相关的lib软件包
yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
yum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-devel
#安装yum无法安装的libiconv库
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xf libiconv-1.14.tar.gz -C /usr/src/
cd /usr/src/libiconv-1.14/
./configure --prefix=/usr/local/libiconv && make && make install
#安装libmcrypt库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel
#安装mhash加密扩展库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install mhash
#安装mcrvpt加密扩展库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install mcrypt
#获取PHP软件包
wget http://cn2.php.net/get/php-5.3.28.tar.gz/from/this/mirror
# 解压配置PHP
tar xf php-5.3.28.tar.gz -C /usr/src/
cd /usr/src/php-5.3.28/
./configure \
--prefix=/usr/local/php5.3.28 \
--with-mysql=/usr/local/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp
#编译PHP
cd /usr/src/php-5.3.28/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make
#安装PHP生成文件到系统
make install
#设置软链接
ln -s /usr/local/php5.3.28/ /usr/local/php
ls -l /usr/local/php
#拷贝PHP配置文件到PHP默认目录,并更改文件名称为php.ini
cp php.ini-production /usr/local/php/lib/php.ini
#配置PHP(FastCGI方式)的配置文件php-fpm.conf
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
#启动PHP服务php-fpm
/usr/local/php/sbin/php-fpm
#默认9000端口提供服务
lsof -i:9000
#修改Nginx配置文件
cd /usr/local/nginx/conf/
cp nginx.conf nginx.conf.02
cat nginx.conf
############################################
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/www.conf;
include extra/mail.conf;
include extra/status.conf;
include extra/blog.conf;
}
#创建目录和配置文件
cd /usr/local/nginx/conf
mkdir extra
cd extra
touch www.conf mail.conf status.conf blog.conf
vim blog.conf
#最终blog虚拟机的完整配置
server {
listen 80;
server_name blog.yunjisuan.com;
location / {
root /var/www/html/blogcom;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root /var/www/html/blogcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
# 检查并启动Nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
#进入指定的默认站点目录后,编辑index.php
cd /var/www/html/blogcom/
echo "<?php phpinfo(); ?>" >test_info.php
#编辑test_mysql.php
<?php
//$link_id=mysql_connect('主机名','用户','密码');
$link_id=mysql_connect('localhost','root','123123');
if($link_id){
echo "mysql successful by Mr.chen !";
}else{
echo mysql_error();
}
?>
################################################
##WordPress 博客程序的搭建准备
#登陆MySQL数据库
mysql -uroot -p123123
#创建一个数据库,名字为wordpress
create database wordpress;
#创建一个专用的WordPress blog管理用户
grant all on wordpress.* to wordpress@'localhost' identified by '123123';
#刷新权限,使得创建用户生效
flush privileges;
#查看用户对应权限
show grants for wordpress@'localhost';
quit
#选择之前配置好的支持LNMP的blog域名对应的虚拟主机#补充一个首页文件index.php
server {
listen 80;
server_name blog.yunjisuan.com;
location / {
root /var/www/html/blogcom;
index index.html index.php index.htm;
}
location ~ .*\.(php|php5)?$ {
root /var/www/html/blogcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
#重启
/usr/local/nginx/sbin/nginx -s reload
cd /var/www/html/blogcom/
#解压博客程序
tar xf wordpress-4.7.4-zh_CN.tar.gz
#删除无用文件
rm -f index.html test_info.php test_mysql.php
#把目录里的内容移动到blogcom根目录下
mv wordpress/* .
#移走源程序
/bin/mv wordpress-4.7.4-zh_CN.tar.gz /root/
#授权用户访问
chown -R www.www ../blogcom/