- 安装apache2
sudo apt-get install apache2
- 安装php7.0
sudo apt-get install php7.0
安装完成之后可以通过php -v测试环境是否配置正确,或者通过sudo vim /var/www/html/testphp.php
命令创建testphp.php文件,浏览器输入http://localhost/testphp.php
进行访问,如果访问正常,则表示php安装成功。
<?php echo phpinfo();?>
- 安装phpMyAdmin
sudo apt-get update
sudo apt-get install phpmyadmin php-mbstring php-gettext
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
- 安装扩展
sudo phpenmod mcrypt
sudo phpenmod mbstring
- 重启apache2 让配置生效
sudo systemctl restart apache2
- 安装php-fpm php-mysql
sudo apt-get install php-fpm php-mysql
配置文件php-fpm root权限
sudo vim /etc/php/7.0/fpm/php.ini
修改gi.fix_pathinfo
cgi.fix_pathinfo=0
更改/etc/nginx/sites-available/default
sudo vim /etc/nginx/sites-available/default
更改之前
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
修改后
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
参考我的配置文件
server {
listen 8001;
#listen [::]:80;
server_name www.ipersistence.top;
# SSL configuration
#ssl on;
listen 443 ssl;
server_name www.ipersistence.top;
ssl_certificate /var/www/cert/1531196979685.pem;
ssl_certificate_key /var/www/cert/1531196979685.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://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.php index.html index.htm index.nginx-debian.html;
server_name www.ipersistence.top;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# 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;
#}
}
- 重启nginx
sudo nginx -t
sudo systemctl reload nginx
- 访问
https://domain_name_or_IP/phpmyadmin
参考链接https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-16-04
参考链接https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
- 这个时候我们需要修改phpMyAdmin中的config.inc.php文件,这个文件的具体位置在/etc/phpmyadmin/config.inc.php;
- 找到它之中的$cfg['Servers'][$i]['controluser']与$cfg['Servers'][$i]['controlpass']两个选项分别修改为你的MySql的用户名和密码;
- 你可以直接修改也可以去修改它引用的变量$dbuser和$dbpass所在的配置文件,这两个变量所在的文件是当前目录下的config-db.php。 最后重启phpMyAdmin就可以了。