一、Nginx安装
1、下载Nginx软件包(源码包),并解压
wget http://nginx.org /download/nginx-1.14 .0 .tar .gz
tar xf nginx-1.14 .0 .tar .gz
2、创建www虚拟用户
useradd -M -s /sbin/nologin www
3、编译安装nginx
cd nginx- 1.14 .0
. /configure -- prefix= /usr/local /nginx- 1.14 .0 -- user= www -- group = www -- with -http_ssl_module -- with_http_stub_status_module
make && make install
ln -s /usr/local /nginx- 1.14 .0 /usr/local /nginx
4、添加环境变量
echo 'export PATH=$PATH:/usr/local/nginx/bin' > /etc/profile
. /etc/profile
5、启动nginx服务,并查看服务是否启动
nginx
netstat -lntp (查看80 端口是否监听)
二、Mysql安装
1、下载Mysql软件包(二进制包),并解压
wget https:
tar xf mysql- 8.0 .11 -linux -glibc2 .12 -x86_64 . tar. gz
mv mysql- 8.0 .11 -linux -glibc2 .12 -x86_64 /usr/local /mysql- 8.0 .11
ln -s /usr/local /mysql- 8.0 .88 /usr/local /mysql
2、创建mysql虚拟用户,并修改权限
useradd -M -s /sbin/nologin mysql
chown -R root. mysql /usr/local /mysql- 8.0 .11
chown -R mysql. mysql /usr/local /mysql/data
3、初始化数据库
/usr/local /mysql/scripts/mysql_install_db -- basedir= /usr/local /mysql -- datadir= /usr/local /mysql/data -- user= mysql
4、编写启动脚本和配置文件
mv /usr/local /mysql/supports/mysql_server /etc/init.d/mysqld
mv /usr/local /mysql/my .cnf /etc/my .cnf
5、设置root密码
/usr/local /mysql/bin/mysqladmin -uroot password
6、登录Mysql测试
mysql -uroot -p
7、排错
Starting MySQL .... ERROR ! The server quit without updating PID file (/application/mysql /data/web 01.pid)
解决:
(1 )、重新初始化数据库
(2 )、配置文件中添加innodb_force_recovery = 11
原文请参考:https: //blog.csdn.net/qq _35440678/article/details/56016264
三、Php安装
1、php安装包下载(源码包),并解压
网址:http://php.net /downloads.php
tar xf php-7.1 .19 .tar .gz
2、安装依赖库
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo -devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
3、编译安装
./configure \
--prefix=/usr/local /php \
--with-mysql=/usr/local /mysql-5.6.34 \
--with-pdo-mysql=mysqlnd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--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-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
(防错)
(ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar)
make && make install
4、编写配置文件
cp php.ini -production /usr/local/php/lib/php.ini
cd /usr/local/php/etc
cp php-fpm.conf .default php-fpm.conf
5、启动php-fpm服务
/usr/local /php/sbin/php-fpm
四、Nginx与Php连接
1、编写nginx配置文件
worker_processes 2
events {
worker_connections 1024
}
http {
include mime.types
default_type application/octet-stream
sendfile on
keepalive_timeout 65
server {
listen 80
server_name zabbix.zhengsy .net
root html/www
index index.php index.html index.htm
location ~* .*\.(php|php5?)$ {
fastcgi_pass 127.0 .0 .1 :9000
fastcgi_index index.php
include fastcgi.conf
}
}
}
五、Mysql与Php连接
1、编写index.php
<?php
$link_id =mysql_connect('localhost' ,'root' ,'oldboy123' ) or mysql_error();
if ($link_id ){
echo "mysql successful by oldboy !\n" ;
}else {
echo mysql_error();
}
?>