LAMP动态网站部署架构是由一套 Linux Apache MySQL PHP 组成的动态网站系统解决方案.LNMP动态网站部署架构是由一套 Linux Nginx MySQL PHP 组成的动态网站系统解决方案.编译安装费时费力有时还会出错误,下面我们将通过Yum仓库,快速构建LANMP网站环境.
Linux Apache MariaDB PHP
1.配置yum源,安装依赖
代码语言:javascript复制yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2.安装LAMP5环境
代码语言:javascript复制yum install -y httpd httpd-devel mariadb mariadb-server mysql-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
3.安装LAMP7环境
代码语言:javascript复制yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y httpd httpd-devel mariadb mariadb-server mysql-devel php70w php70w-intl php70w-mysql php70w-common php70w-gd php70w-mbstring php70w-mcrypt php70w-devel php70w-xml
Linux Nginx MariaDB PHP
1.配置yum源,安装依赖
代码语言:javascript复制wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel libjpeg* libmcrypt libmcrypt-devel
2.安装Nginx
代码语言:javascript复制yum install -y nginx
systemctl start nginx
systemctl enable nginx
3.安装与配置MySQL
代码语言:javascript复制yum install -y mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
4.安装PHP
代码语言:javascript复制yum install -y php php-devel php-fpm
php-mysql php-common php-gd php-imap
php-ldap php-odbc php-pear php-xml
php-xmlrpc php-mbstring php-mcrypt
php-bcmath php-mhash
systemctl start php-fpm
systemctl enable php-fpm
5.编辑PHP主配置文件
编辑配置文件,在PHP文件末尾追加写入以下标★语句
代码语言:javascript复制vim /etc/php.ini
★cgi.fix_pathinfo=1 #将注释去掉,开启PHP的pathinfo伪静态功能
★max_execution_time = 0 #脚本运行的最长时间,默认30秒
★max_input_time = 300 #脚本可以消耗的时间,默认60秒
★memory_limit = 256M #脚本运行最大消耗的内存,根据你的需求更改数值,默认128M
★post_max_size = 100M #单提交的最大数据,默认100M
★upload_max_filesize = 10M #上载文件的最大许可大小,默认2M
6.修改php-fpm的配置
编辑配置文件,在PHP-fpm文件中,修改以下标★语句
代码语言:javascript复制vim /etc/php-fpm.d/www.conf
★listen.owner = nobody #解除注释
★listen.group = nobody #解除注释
★user = nginx #将apache修改为nginx
★group = nginx #将apache修改为nginx
7.修改nginx的主配置
编辑配置文件,在server语句内,写入以下标★语句
代码语言:javascript复制vim /etc/nginx/nginx.conf
38 server {
39 listen 80 default_server;
40 listen [::]:80 default_server;
41 server_name _;
42 root /usr/share/nginx/html;
43
44 # Load configuration files for the default server block.
45 include /etc/nginx/default.d/*.conf;
46
★ location / {
★
★ root /usr/share/nginx/html;
★ index index.php index.html index.htm;
★
52 }
53
★ location ~ .php$ {
★ root /usr/share/nginx/html;
★ try_files $uri =404;
★ fastcgi_pass 127.0.0.1:9000;
★ fastcgi_index index.php;
★ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
★ include fastcgi_params;
★ }
62
63 error_page 404 /404.html;
64 location = /40x.html {
65 }
8.设置网页目录权限
代码语言:javascript复制chown -R nginx:nginx /usr/share/nginx/html
9.新建index.php测试页
代码语言:javascript复制vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
10.重启服务,并查看9000端口是否启动成功
代码语言:javascript复制systemctl restart nginx
systemctl restart php-fpm
systemctl restart mariadb
netstat -npa | grep 9000