Linux下搭建LNMP环境
一、安装NGINX
二、安装MySQL或MariaDB
三、安装PHP
1、移除其他版本php软件
yum remove php-mysql php php-fpm php-common
2、更新yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3、安装PHP
yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
四、建立nginx和php关系
1、nginx配置文件
server { listen 80; server_name blog.yinghui.com; location / { root /html/blog; index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; root /html/blog; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
2、测试(访问文件)
[root@web01 /html/blog]# cat test_info.php <?php phpinfo(); ?>
五、测试php和mariadb关系(打开网页显示mysql successful by root!则表示建立关系成功)
[root@web01 /html/blog]#cat test_mysql.php <?php $servername = "localhost"; $username = "root"; $password = "123"; //$link_id=mysql_connect('主机名','用户','密码'); //mysql -u用户 -p密码 -h 主机 $conn = mysqli_connect($servername, $username, $password); if ($conn) { echo "mysql successful by root !\n"; }else{ die("Connection failed: " . mysqli_connect_error()); } ?>
六、伪静态配置
第一个步骤:在wordpress后台修改页面配置
登录后台---设置---固定链接---自定义结构--/%post_id%.html
第二个步骤:实现nginx伪静态配置
server { listen 80; server_name blog.etiantian.org; rewrite /wp-admin$ $scheme://$host$uri/permanent; location / { root /html/blog; index index.php index.html; try_files $uri $uri/ /index.php?$args==$uri; } location ~ \.php$ { root /html/blog; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS on; #支持HTTPS fastcgi_pass 127.0.0.1:9000; include fastcgi_params; } }