文章目录
1.安装 Nginx
1.1 安装依赖
yum -y install gcc gcc-c++ autoconf automake make zlib-devel pcre-devel -y
1.2 下载,解压,编译
wget http://nginx.org/download/nginx-1.17.0.tar.gz
tar -zxvf nginx-1.17.0.tar.gz
cd nginx-1.17.0
./configure --prefix=/usr/local/nginx
make && make install
1.3 设置软链并启动
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -h
nginx
1.4 配置 nginx
# /etc/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
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;
}
...
}
ln -s /usr/local/nginx/html ~
2. 安装 php
2.1 下载解压
wget https://www.php.net/distributions/php-7.3.4.tar.gz
tar -zxvf php-7.3.4.tar.gz
cd php-7.3.4
2.2 安装依赖
yum groupinstall "Development Tools" -y
yum --enablerepo=epel install bzip2-devel curl-devel libjpeg-turbo-devel libpng-devel libicu-devel libmcrypt-devel libxml2-devel freetype-devel -y
yum install libxslt-devel* -y
yum install openssl openssl-devel -y
2.3 安装 PHP
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/conf.d --enable-bcmath --with-bz2 --with-curl --enable-filter --enable-fpm --with-gd --enable-intl --enable-mbstring --enable-mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-phpdbg --disable-phpdbg-webhelper --enable-opcache --with-openssl --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-zip --with-zlib --enable-soap --enable-shmop --enable-sockets --enable-sysvmsg --with-openssl-dir=/usr/local/ssl --with-jpeg-dir=/usr/lib64 --with-freetype-dir --with-gettext
或者精简点 (推荐)
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --enable-filter --enable-fpm --with-gd –with-jpeg-dir --enable-intl --enable-mbstring --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-simplexml --with-zlib --enable-sockets --disable-fileinfo
2.4 make
make
make install
2.5 配置PHP
cp php.ini-development /usr/local/php/lib/php.ini
cp sapi/fpm/www.conf /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php–fpm.conf
#### 2.6 配置php-fpm服务
1. 修改php-fpm.conf的pid
vim /usr/local/php/etc/php-fpm.conf
取消pid前面的注释
pid = run/php-fpm.pid
2. 复制文件并增加执行权限
cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
3. 修改 /etc/init.d/php-fpm
文件
把路径改成绝对路径
php_fpm_BIN=/usr/local/php/sbin/php-fpm
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/usr/local/php/var/run/php-fpm.pid
4. 启动
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
5. 搞定!!
service php-fpm stop |start | restart
3.安装 MySQL
3.1 安装依赖
yum install libaio-devel ncurses-devel cmake gcc gcc-c++ bison -y
3.2 安装 MySQL
# 下载
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
# 校验校验码
md5sum mysql57-community-release-el7-9.noarch.rpm
# 安装
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
sudo yum install mysql-server
3.3 启动MySQL
- 启动
sudo systemctl start mysqld
sudo systemctl status mysqld
Note: MySQL is automatically enabled to start at boot when it is installed. You can change that default behavior with sudo systemctl disable mysqld
- 查看默认密码
sudo grep 'temporary password' /var/log/mysqld.log
# 2018-06-28T07:07:04.914495Z 1 [Note] A temporary password is generated for root@localhost: XTk;w145PkgT
3.4 配置MySQL
- 登录
mysql -uroot -p XTk;w145PkgT
- 查看密码配置
show variables like "%password%";
- 设置密码配置长度和安全 设置新密码
set global validate_password_length=0;
set global validate_password_policy=low;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
exit;
- 设置远程登录权限
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
- 配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务,查看数据库默认编码如下所示:
- 配置文件:/etc/my.cnf
- 日志文件:/var/log//var/log/mysqld.log
- 服务启动脚本:/usr/lib/systemd/system/mysqld.service
- socket文件:/var/run/mysqld/mysqld.pid
遇到错误
错误1:
php文件提示错误,提示信息如下:
nginx: connect() failed (111: Connection refused) while connecting to upstream....
解决办法:
- 找到
/usr/local/php/etc/php-fpm.d/www.conf
取消以下这行当注释
listen.allowed_clients = 127.0.0.1
2. 重启nginx和php-fpm 即可
错误2:
php编译文件提示错误:configure: error: Please reinstall the libzip distribution
解决办法:
安装 libzip支持即可
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make -j4 && make install
错误3:
php编译文件提示错误:error: Package requirements (sqlite3 > 3.7.4) were not met
解决办法:
yum install libsqlite3x-devel -y
错误4:
php编译文件提示错误: error: Package requirements (oniguruma) were not met
解决办法:
yum install oniguruma-devel -y
错误5:
/www/server/php/74/sbin/php-fpm: error while loading shared libraries: libonig.so.2: cannot open shared object file: No such file or directory
解决办法:
ln -s /usr/lib64/libonig.so /usr/lib64/libonig.so.2