۱۳۹۵ شهریور ۱۷, چهارشنبه

آموزش نصب Nginx و PHP و MySQL یا lemp روی سرور لینوکس

آموزش نصب Nginx و PHP و MySQL یا lemp روی سرور لینوکس

Nginx یک وب سرور HTTP رایگان، متن باز و با کارایی بالا میباشد که به علت پایداری ،داشتن مجموعه ای پربار از ویژگی ها، پیکربندی ساده، و مصرف منابع کم سرور شناخته شده است. این آموزش نشان می دهد که چگونه Nginx را بر روی سرور لینوکس CentOS 7  که از PHP (از طریق PHP-FPM) و MySQL (Mariadb) پشتیبانی  میکند نصب کنید.
  • نکات مقدماتی :
در این آموزش از نام هاست server1.example.com با IP آدرس ۱۹۲٫۱۶۸٫۱٫۱۰۵ استفاده شده است . این تنظیمات ممکن است با تنظیمات شما متفاوت باشد، بنابراین باید آنها را با تنظمات مورد نظر خود در بخش های مناسب جایگزین کنید.
  • فعال کردن مخازن دیگر:
Nginx از مخازن رسمی لینوکس CentOS  وجود ندارد، بنابراین با استفاده از دستور زیر مخزن Nginx را نصب کنید:
vi /etc/yum.repos.d/nginx.repo
[nginx]
     name=nginx repo
     baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
     gpgcheck=0
     enabled=1
  • نصب MySQL
ابتدا باید Mariadb را با استفاده از دستور زیر نصب کنید. Mariadb انشعابی آزاد از MySQL است.
yum install mariadb mariadb-server net-toolsسپس لینک های راه انداز سیستم برای MySQL ایجاد کنید(به طوری که MySQL پس از بوت شدن سیستم به طور خودکار استارت شود) و سپس سرور MySQL را اجرا کنید:
systemctl enable mariadb.service
systemctl start mariadb.service
با استفاده از دستور زیر فعال شدن شبکه را بررسی کنید :

netstat -tap | grep mysql
باید چیزی شبیه به متن زیر مشاهده کنید :
[root@example ~]# netstat -tap | grep mysql
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 10623/mysqld
دستور زیر را اجرا کنید :

mysql_secure_installation
یک رمز عبور برای کاربر روت خود تعیین کنید (در غیر این صورت هر کسی می تواند به پایگاه داده MySQL شما دسترسی پیدا کند!):
[root@example ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <– ENTER
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <– ENTER
… Success!
By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <– ENTER
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– ENTER
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@example ~]#
[root@server1 ~]# mysql_secure_installation

آموزش نصب Nginx و PHP و MySQL یا lemp روی سرور لینوکس

  • نصب Nginx
Nginx به صورت یک پکیج در nginx.org در دسترس است که می توانید به شرح زیر آن را نصب کنید:
yum install nginxسپس باید یک لینک سیستم startup برای nginx ایجاد و آن را استارت کنید :
systemctl enable nginx.service
systemctl start nginx.serviceاین امکان وجود دارد که شما یک ارور مانند ارور پورت ۸۰ که در حال حاضر از آن استفاده میکنید دریافت کنید، پیغام خطا اینگونه خواهد بود.
[root@server1 ~]# service nginx start
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
                                                           [FAILED]
[root@server1 ~]#این بدان معناست که سرویس آپاچی در حال اجرا میباشد. مطابق دستور زیر آن را متوقف کرده و سرویس NGINX را فعال کنید:
systemctl stop httpd.service
yum remove httpd
systemctl disable httpd.service
systemctl enable nginx.service
systemctl start nginx.serviceو پورت های http و https را در firewall فعال کنید:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd –reloadپس از آن خروجی زیر را مشاهده خواهید کرد:
[root@example ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@example ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@example ~]# firewall-cmd --reload
success
[root@example ~]#در مرورگر خود آدرس IP یا نام هاست وب سرورتان را تایپ کنید (به عنوان مثال http://192.168.1.105)، پس از آن باید صفحه nginx را مشاهده کنید:


هیچ نظری موجود نیست:

ارسال یک نظر