wiki:linux:ubuntu-install-nginx-php-mysql
Ubuntu 搭建LNMP服务器(Linux/Nginx/MySQL/PHP)
准备
相关文章:
更新软件源
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update
安装 Nginx
关于php网站的配置
DokuWiki网站的Nginx配置
- Dokuwiki的安全设置 https://www.dokuwiki.org/security#web_access_security
- Dokuwiki 2018-04-22b “Greebo” 不支持 php7.3 (亲测支持php7.0)
安装php后,需要在配置文件中开启php功能。 以 vim /etc/nginx/sites-available/default 为例
# 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; }
注意:fastcgi_pass中的php版本应与当前安装的版本一致
安装 PHP
默认安装php
sudo apt-get install php
或者直接指定版本安装php
sudo apt-get install php7.0
查看安装的php版本(本次安装的为 php7.0)
php -v
安装php*-fpm模块
sudo apt-get install php7.0-fpm
安装其他可能需要的模块
sudo apt-get install php7.0-gd sudo apt-get install php7.0-mbstring
php相关服务的控制
sudo systemctl start php7.0-fpm sudo systemctl stop php7.0-fpm sudo systemctl restart php7.0-fpm sudo systemctl status php7.0-fpm
查询、安装php的可选模块
查询可用模块
apt-cache search php7.0
安装模块
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring
权限
与 php*.*-fpm 相关的文件权限
chown -R www-data:www-data /var/www/test && chmod -R 755 /var/www/test
一些问题的解决办法
nginx搭建php提示No input file specified.
打开fastcgi.conf
vim /etc/nginx/fastcgi.conf
设置fastcgi的可操作目录(防止跨站),在最后添加:
fastcgi_param PHP_VALUE open_basedir=/opt/:/tmp/;
重启nginx
service nginx restart
安装 MySQL
注意事项
安装
卸载
完全移除Nginx
sudo apt-get --purge autoremove nginx
重置Nginx配置文件
sudo apt-get -o DPkg::options::=--force-confmiss --reinstall install nginx-common
怎么完全卸载、安装Nginx,参考:
查看已安装的相关软件(以nginx为例)
dpkg --get-selections | grep nginx
wiki/linux/ubuntu-install-nginx-php-mysql.txt · 最后更改: 2023/01/03 15:25 由 127.0.0.1
评论