1.安装nginx
yum -y install gcc pcre-devel openssl-devel tar xf nginx-1.16.1.tar.gz cd nginx-1.16.1/ ./configure --with-http_ssl_module make && make install
2.安装php
下载
http://www.php.net/downloads.php
yum -y install libxml2 libxml2-devel tar xf php-7.2.34.tar.gz cd php-7.2.34/ ./configure --enable-fpm --with-mysql make && make install
创建配置文件,并将其复制到正确的位置.
cp php.ini-development /usr/local/php/php.ini cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf cp sapi/fpm/php-fpm /usr/local/bin cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
将php.ini文件中的配置项cgi.fix_painfo设置为0 。需要着重提醒的是,如果文件不存在,则阻止nginx将请求发送到后端的PHP-FPM模块,以避免遭受恶意脚本注入的攻击.
vim /usr/local/php/php.ini 771 cgi.fix_pathinfo=0
在启动服务之前,需要修改php-fpm.conf配置文件,
vim /usr/local/etc/php-fpm.conf include=/usr/local/etc/php-fpm.d/*.conf #最后一行 修改安装路径
启动
/usr/local/bin/php-fpm
配置Nginx使其支持PHP应用
vim /usr/local/nginx/conf/nginx.conf 修改默认的Location块,使其支持.php文件: location / { root html; index index.php index.html index.htm; }
下一步配置来保证对于.php文件的请求将被传送到后端的PHP-fpm模块,取消默认的PHP配置块的注释,并修改为下面的内容:
location ~* .php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }
重启Nginx.
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
创建测试文件.
rm -rf /usr/local/nginx/html/index.html echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
验证
curl localhost
3.安装mysql
下载
https://dev.mysql.com/downloads/mysql/
解压并创建数据目录
tar xf mysql-5.7.32-el7-x86_64.tar.gz mv mysql-5.7.32-el7-x86_64 /usr/local/mysql groupadd mysql useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql cd /usr/local/mysql chown -R mysql. * mkdir /var/lib/mysql chown -R mysql /var/lib/mysql cd /usr/local/mysql
编译
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
拷贝启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改配置文件
vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/var/lib/mysql
vi /etc/my.cnf
创建日志路径
mkdir /var/log/mariadb touch /var/log/mariadb/mariadb.log chown -R mysql. /var/log/mariadb
启动
/etc/init.d/mysql start
--登陆
# mysql -uroot -p
--如果出现:-bash: mysql: command not found
--就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin
--修改密码
mysql> set password=password('123456');
--设置root账户的host地址(修改了才可以远程连接)
mysql>grant all privileges on *.* to 'root'@'%' identified by '123456'; mysql>flush privileges;