Open rajibul5603 opened 1 year ago
31
Selinux may cause the issue, to verify run:
getsebool -a | grep mail If it displays as bellow it is selinux:
allow_postfix_local_write_mail_spool --> off You may disabled it, but if you want to keep it (and you should as it provides an extra layer of security) you should do something else:
setsebool -P httpd_can_sendmail on This will allow the httpd to send emails, as when you use php mail().
==== CENTOS 7 LEMP STACK INSTALLATION ====
Make sure the centos 7 server have internet connection
Install the EPEL Repository sudo yum -y install epel-release
Install the Remi Repository sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install Nginx sudo yum -y install nginx
Start the nginx service sudo service nginx start
Auto start nginx on boot sudo systemctl enable nginx
Allow port 80 (HTTP) in the firewall sudo firewall-cmd --zone=public --add-service=http --permanent
Reload firewall configuration sudo firewall-cmd --reload
check if the web server is accessible through browser. input the server's ip address in the browser
install php 7.2 sudo yum --enablerepo=remi,remi-php72 install php-fpm php-common
install php modules sudo yum --enablerepo=remi,remi-php72 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pecl-redis php-gd php-mbstring php-mcrypt php-xml php-zip
start the php-fpm service sudo service php-fpm start
Auto start php-fpm on boot sudo systemctl enable php-fpm.service
Make backup of the nginx.conf file sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
Modify PHP-FPM to listen ip instead of socket ## sudo vi /etc/php-fpm.d/www.conf
14.5 change the following in www.conf file listen = 127.0.0.1:9000
open nginx.conf file sudo vi /etc/nginx/nginx.conf
change the root directory of nginx root /var/www/sites; index index.php index.html index.htm;
17 in the location, add default files location / { try_files $uri $uri/ /index.php?$query_string; }
test if nginx.conf syntax is OK sudo nginx -t
make a folder called 'sites' inside the var/www/ directory sudo mkdir /var/www/sites
create a file inside the sites folder sudo vi index.php
paste this code inside the index.php <?php phpinfo();
restart the nginx service sudo service nginx restart
input the server's ip address in the browser to check if nginx and php is working
install wget sudo yum -y install wget
install yum-utils sudo yum -y install yum-utils
download mysql yum repository sudo wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
install mysql release package sudo rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
select the specific version of mysql you want to use, we'll use 5.7 as example sudo yum-config-manager --disable mysql80-community sudo yum-config-manager --enable mysql57-community
install mysql sudo yum install mysql-community-server
start the mysql service sudo service mysqld start
auto start mysql on boot sudo systemctl enable mysqld.service
find and copy the mysql temporary password sudo grep 'temporary password' /var/log/mysqld.log
run mysql secure installation mysql_secure_installation
you will be prompted for new root password, input your new root password
check if mysql is installed and running mysql -u root -p
========= RUN LARAVEL APPLICATION ON CENTOS LEMP STACK ===========
install composer curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
check if composer is installed composer
install git sudo yum -y install git
install unzip sudo yum -y install unzip
go to sites folder cd /var/www/sites
clone project repository sudo git clone url_here
go to project directory cd project_directory_name
install composer packages sudo composer install --no-dev
copy .env.example and rename it to .env sudo cp .env.example .env
generate app key sudo php artisan key:generate
open .env file sudo vi .env
change these values in the .env file APP_ENV=production APP_DEBUG=false DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password
open php-fpm config file sudo vi /etc/php-fpm.d/www.conf
change php-fpm user to nginx:nginx user = nginx group = nginx
change project directory permissions sudo chown -R nginx:nginx /var/www/sites/project_name sudo chmod -R 755 storage sudo chmod -R 755 bootstrap/cache
Install 'policycoreutils-python' sudo yum -y install policycoreutils-python
change the context of the laravel project directories sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/public(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/storage(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/app(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/bootstrap(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/config(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/database(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/resources(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/routes(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/vendor(/.)?' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/sites/project_name/tests(/.*)?'
run SELinux restorecon command sudo restorecon -Rv '/var/www/sites/project_name/'
go again to nginx.conf file and open it sudo vi /etc/nginx/nginx.conf
change the root directory in the nginx.conf root /var/www/sites/project_name/public;
login to mysql and create a database create database database_name;
run database migrations and seeders sudo php artisan migrate sudo php artisan db:seed
if your app requrires username to login instead of email, go to /var/www/sites/project_name/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php and open it sudo vi /var/www/sites/project_name/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
find username() method and edit the return value from 'email' to 'username' public function username() { return 'username'; }
add permission to SELinux to allow nginx to connect to database sudo setsebool -P httpd_can_network_connect_db=1
your laravel app should now be up and running!
============= INSTALL REDIS ==============
install redis (make sure EPEL repository is already installed) sudo yum -y install redis
start redis service sudo service redis start
start redis on server boot sudo systemctl enable redis
============ USE REDIS FOR LARAVEL BROADCASTING =============
============= INSTALL NODE.JS =================
enable the Node.js v10 repository (make sure EPEL Repository is already installed) curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
install Node.js sudo yum -y install nodejs
install node.js build tools (optional) sudo yum -y install gcc-c++ make
verify if node.js is installed node -v
============ INSTALL NODE.JS PACKAGES =========
go to project directory cd /path/to/project/directory
install node.js packages (make sure package.json is present inside the directory) sudo npm install
============ DAEMONIZE NODE.JS SCRIPT ============
install PM2 sudo npm install pm2 -g
configure startup script to launch PM2 and its mananged processes on server boot sudo pm2 startup
run node.js app/script sudo pm2 start /path/to/the/script/filename.js
save process list sudo pm2 save
allow external access to port 3000 sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent
reload firewall configuration sudo firewall-cmd --reload
add permission to SELinux to allow nginx to connect to redis sudo setsebool -P httpd_can_network_connect=1
===== INSTALL SUPERVISOR ======
sudo yum -y install supervisor
open supervisor config file: vi /etc/supervisord.conf
add the ff: [program:programname] command=php /var/www/sites/project_name/artisan queue:listen process_name=%(programname)s%(process_num)02d autostart=true autorestart=true user=root numprocs=5 redirect_stderr=true stdout_logfile=/var/www/sites/project_name/queue-worker.log
read the newly edited config file: sudo supervisorctl reread
update the config: sudo supervisorctl update
start the queue worker: sudo supervisorctl start programname:*