Skip to content

Latest commit

 

History

History
212 lines (161 loc) · 5.78 KB

阿里云Ubuntu16.04安装apache2&php7.0&phpMyAdmin实践.md

File metadata and controls

212 lines (161 loc) · 5.78 KB

阿里云Ubuntu16.04安装apache2&php7.0&phpMyAdmin实践

  • 安装apache2
sudo apt-get install apache2
安装完成之后使用service apache2 status查看apahce2的状态,使用service apache2 restart重启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安装成功。
testphp.php内容如下
<?php echo phpinfo();?>
如果出现下图所示表示php已经正常解析了。一般情况下是不生效的。因为nginx部分还没有配置...

安装过程中记住自己设置的密码。使用mysql -u root -p命令,然后输入自己的密码进行数据库登录。
  • 安装phpMyAdmin
sudo apt-get update
sudo apt-get install phpmyadmin php-mbstring php-gettext
server 选择apache2,dbconfig-common选择yes
注意的问题。我们一般是用nginx服务器。phpmyadmin安装完以后,默认是在/usr/share/phpmyadmin,我们需要通过一个软链接把这个目录放到nginx目录下,命令如下
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

2018-7-25 Ubuntu-ubuntu16.0.4phpmyadmin使用配置文件中定义的控制用户连接失败错误

解决方法
  1. 这个时候我们需要修改phpMyAdmin中的config.inc.php文件,这个文件的具体位置在/etc/phpmyadmin/config.inc.php;
  2. 找到它之中的$cfg['Servers'][$i]['controluser']与$cfg['Servers'][$i]['controlpass']两个选项分别修改为你的MySql的用户名和密码;
  3. 你可以直接修改也可以去修改它引用的变量$dbuser和$dbpass所在的配置文件,这两个变量所在的文件是当前目录下的config-db.php。 最后重启phpMyAdmin就可以了。