牛下载:绿色软件官方软件免费下载基地!
所在位置:首页 > 新闻资讯 > apt方式安装LNMP环境教程(ubuntu17.10|PHP7.1)

apt方式安装LNMP环境教程(ubuntu17.10|PHP7.1)

发布时间:2020-04-12 19:26:39来源:阅读:

1. 简要说明

安装环境是阿里云ubuntu17.10,这个教程里我把域名都写成hostname.com, ip都写成192.168.1.1,你可以根据自己的需要更换。另外如果不是root账户的话,最好切换到root账户。

sudo su

2. 安装MYSQL 5.7

我们使用apt-get方式安装MySQL:

apt-get -y install mysql-server mysql-client

安装的时候会要求你输入MySQL的root密码,建议此时输入,比较方便。
输入以下命令,让MySQL更安全:

mysql_secure_installation

我们将会被问这些问题:

root@root:~# mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: 这里输入MySQL密码VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: 想要让MySQL验证密码强度可以填Y,但个人建议N。otherwise.Using existing password for root.Change the password for root ? ((Press y|Y for Yes, any other key for No) : 建议NoBy default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : 这个要填YSuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 是否允许root远程登录?想要更安全选Y,但我建议选N,可以避免很多问题。Success.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 这个选Y,移除没用的test表。- Dropping test database...Success.- Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 选YSuccess.All done!

MySQL就装好了。

3. 安装Nginx

apt-get install nginx
apt-get install nginx

然后你打开你的IP地址或域名,就能看见nginx默认页面了。

apt方式安装LNMP环境教程(ubuntu17.10|PHP7.1)

nginx默认的路径在/var/www/html

4. 安装PHP7.1

我们搭建wordpress博客主要要用到php-fpm组件,我们apt-get它,ubuntu会自动安装必要的php程序。

apt-get -y install php7.1-fpm

5. 配置nginx

编辑nginx的默认站点配置文件

vim /etc/nginx/sites-available/default
server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: http://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: http://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf;root /var/www/html;# Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html;server_name _;location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; }# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: # fastcgi_pass unix:/run/php/php7.0-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; }}

另外需要注意,我们是要安装wordpress的,所以又一个index的地方(# Add index.php to the list),在index后面要增加index.php

PHP-FPM默认是通过socket连接的,我们要改成用TCP链接。

vim /etc/php/7.0/fpm/pool.d/www.conf

修改listen:

;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000

像上面那样修改后,重启nginx:

service nginx restart

然后打开:

vim /etc/php/7.1/fpm/php.ini

设置cgi.fix_pathinfo=0

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting; of zero causes PHP to behave as before. Default is 1. You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.; http://php.net/cgi.fix-pathinfocgi.fix_pathinfo=0

reload php-fpm:

service php7.0-fpm reload

新建一个文件:

vim /var/www/html/info.php

写入

<?php
phpinfo();
?>

然后我们可以打开浏览器输入域名,例如 192.168.1.1/info.php(你的显示应该是php7.1)

你可以看到PHP已经工作了,包括现在支持的一些模块。

6. 使PHP7.1支持MySQL

我们可以先看一下有哪些PHP7.1的模块:

apt-cache search php7.1

可以选一些你喜欢的模块安装(以下是我自己安装的):

apt-get -y install php7.1-mysql php7.1-gd php7.1-curl php7.1-intl php7.1-mcrypt

reload PHP-FPM:

service php7.1-fpm reload

刷新一下192.168.1.1/info.php,看一下自己的模块是否都安装好了。

这样就安装配置好了,接下来就可以在/var/www/html里上传wordpress文件了。

反对
收藏
  • 热门资讯
  • 最新资讯
  • 应用排行榜
  • 游戏排行榜