先安装相关目录:
mkdir -p /data/server/php /data/server/mysql/mysqldb /data/server/nginx
1、安装nginx
安装nginx依赖包:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-develtk-devel gdbm-devel db4-devel libpcap-devel xz-devel
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/data/server/nginx
make && make install
启动nginx:
/data/server/nginx/sbin/nginx
测试:
2、安装php
安装php依赖包:
yum -y install openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxml2 libxml2-devel
创建用户:
# useradd www
tar -xvf php-5.6.0.tar
cd php-5.6.0
./configure --prefix=/data/server/php --with-config-file-path=/data/server/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-curl --with-openssl --enable-mbregex --with-mysql --with-mysqli --with-mysql-sock --enable-pdo --with-pdo-mysql --enable-mysqlnd --with-gd --with-zlib --enable-zip --with-bz2 --enable-xmlreader --enable-xmlwriter --enable-mbstring --with-xmlrpc --with-libxml-dir=/usr --enable-soap --enable-sockets --enable-pcntl --enable-exif --enable-bcmath --with-mhash --enable-ftp --enable-opcache --disable-fileinfo --with-pear
make && make install
cd /data/server/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vim etc/php-fpm.conf
修改如下,修改完成后保存并退出:
pid = run/php-fpm.pid
user = web
group = web
编辑nginx.conf文件,把php相关的那几行注释去掉,即启用php
# vim /data/server/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
;
include fastcgi_params;
}
添加php到服务,并启动php服务
cp /data/server/php/sbin/php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
php-fpm
测试:
3、安装mysql
安装mysql依赖包:
yum install -y centos-release-scl devtoolset-4-gcc-c++ devtoolset-4-gcc cmake git ncurses-devel openssl-devel bison gcc gcc-c++ ncurses-devel perl make autoconf automake curl curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel perl kernel-headers cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libpng* ncurses* libtool* libxml2-devel bison libaio-devel
cmake \
-DCMAKE_INSTALL_PREFIX=/data/server/mysql \
-DMYSQL_DATADIR=/data/server/mysql/data \
-DMYSQL_UNIX_ADDR=/data/server/mysql/mysql.sock
make && make install
[root@chen ~]# groupadd -r mysql
[root@chen ~]# useradd -M -s/sbin/nologin -g mysql -r mysql
[root@chen ~]# cd /data/server/mysql
[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/data/server/mysql --datadir=/data/server/mysql/data #初始化数据库
[root@chen mysql]# cp ./support-files/my-default.cnf /etc/my.cnf
[root@chen mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@chen mysql]# chmod +x /etc/init.d/mysqld
[root@chen mysql]# chowd -R mysql:mysql /data/server/mysql
添加mysql启动脚本到环境变量中:
在 /etc/profile 末尾添加:
PATH=$PATH:/data/server/mysql/bin
[root@chen mysql]# source /etc/profile
[root@chen mysql]# systemctl start mysqld
[root@chen mysql]# mysql
注意:需要在连接mysql之前,设置软连接,否则会报以下的错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
需要设置软连接:
ln -s /data/server/mysql/mysql.sock /var/lib/mysql/mysql.sock
重启mysqld,然后输入mysql命令即可连接到数据库
systemctl restart mysqld
mysql
来源:https://www.cnblogs.com/relax1949/p/9216248.html