Install Nginx, PHP-fpm, Mariadb on Centos 7
In this post, we are going post to explain installing nginx, PHP-fpm, mariadb on Centos 7. As a bouns, gonna add information on how to install wordpress on the host.
Installation:
Mariadb Installation:
Let’s start with adding mariadb repository. Create a MariaDB.repo on /etc/yum.repos.d directory with the below content.
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list – created 2016-08-25 16:09 UTC[mariadb]name = MariaDBgpgcheck=1
yum install MariaDB-server MariaDB-client
systemctl enable mariadb
systemctl start mariadb
Nginx Installation:
Create a nginx repo on /etc/yum.repos.d/nginx.repo
vi /etc/yum.repos.d/nginx.
[nginx]name=nginx repogpgcheck=0enabled=1
Install nginx and enable to system startup.
yum install nginx
systemctl enable nginx
systemctl start nginx
Install php-fpm and Dependencies:
Let’s install php-fpm and other php dependencies to run a php application on the host.
yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap
As a part of security, make expose_php to off on php.ini.
vi /etc/php.ini
expose_php = Off
Website on Nginx:
We had done all the dependency installation. Now, its time to create a website on nginx. Starts with User creation.
useradd wordpress -d /var/www/wordpress
Uncomment the line listen = 127.0.0.1:9000 on /etc/php-fpm.d/www.conf
vim /etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
Uncomment/add the following line on /etc/nginx/conf.d/default.conf
vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {root /var/www/wordpress/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
mkdir -p /var/www/wordpress/html
chown -R wordpress.wordpress /var/www/wordpress/html
vi /etc/nginx/nginx.conf
include /etc/nginx/sites-enabled/*.conf;
vi /etc/nginx/sites-enabled/domain.conf
server {listen 80;server_name sites.tldwww.sites.tld;location / {root /var/www/wordpress/html;index index.php index.html index.htm;try_files $uri $uri/ =404;}error_page 500 502 503 504 /50x.html;location = /50x.html {root /var/www/wordpress/html;}location ~ \.php$ {root /var/www/wordpress/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}
systemctl restart nginx
systemctl restart php-fpm
WordPress installation:
Download wordpress latest version to domain documentroot
cd /var/www/wordpress/html
wget http://wordpress.com/latest.
tar -xzf latest.tar.gz
cp -pr wordpress/* .
create database wordpress;
grant all privileges on wordpress.* to wordpress@localhost identified by <password>;
flush privileges;