天天看點

CentOS 7 快速部署 LAMP環境 Apache Nginx MySQL PHP

如果安裝NGINX 那麼修改如下 

如果沒有nginx.repo就建立一個 

<code>cd</code> <code>/etc/yum</code><code>.repos</code>

<code>touch</code> <code>nginx.repo</code>

<code>vi</code> <code>/etc/yum</code><code>.repos.d</code><code>/nginx</code><code>.repo</code>

修改為:

<code> </code><code>[nginx]</code>

<code>name=nginx repo</code>

<code>baseurl=http:</code><code>//nginx</code><code>.org</code><code>/packages/centos/</code><code>$releasever/$basearch/</code>

<code>gpgcheck=0</code>

<code>enabled=1</code>

接下來安裝apache nginx php mysql

<code>yum </code><code>install</code> <code>nginx</code>

<code>#yum install httpd httpd-devel</code>

<code>yum </code><code>install</code> <code>mariadb*</code>

<code>yum </code><code>install</code> <code>php php-devel php-gd php-xml php-mbstring php-session php-pecl-memcache php-fpm php-pdo php-pear php-mysql</code>

<code>[root@localhost~]</code><code># mysql_secure_installation</code>

<code>/usr/bin/mysql_secure_installation</code><code>: line 379: find_mysql_client: </code><code>command</code> <code>not found</code>

<code>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB</code>

<code>SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!</code>

<code>In order to log into MariaDB to secure it, we’ll need the current</code>

<code>password </code><code>for</code> <code>the root user. If you’ve just installed MariaDB, and</code>

<code>you haven’t </code><code>set</code> <code>the root password yet, the password will be blank,</code>

<code>so you should just press enter here.</code>

<code>Enter current password </code><code>for</code> <code>root (enter </code><code>for</code> <code>none):</code>

<code>OK, successfully used password, moving on…</code>

<code>Setting the root password ensures that nobody can log into the MariaDB</code>

<code>root user without the proper authorisation.</code>

<code>Set root password? [Y</code><code>/n</code><code>] &lt;– 回車</code>

<code>New password: &lt;– 輸入ROOT密碼</code>

<code>Re-enter new password: &lt;– 再輸入一次ROOT密碼</code>

<code>Password updated successfully!</code>

<code>Reloading privilege tables..</code>

<code>… Success!</code>

<code>By default, a MariaDB installation has an anonymous user, allowing anyone</code>

<code>to log into MariaDB without having to have a user account created </code><code>for</code>

<code>them. This is intended only </code><code>for</code> <code>testing, and to </code><code>make</code> <code>the installation</code>

<code>go a bit smoother. You should remove them before moving into a</code>

<code>production environment.</code>

<code>Remove anonymous </code><code>users</code><code>? [Y</code><code>/n</code><code>] &lt;– 回車</code>

<code>Normally, root should only be allowed to connect from ‘localhost’. This</code>

<code>ensures that someone cannot guess at the root password from the network.</code>

<code>Disallow root login remotely? [Y</code><code>/n</code><code>] &lt;– 回車</code>

<code>By default, MariaDB comes with a database named ‘</code><code>test</code><code>’ that anyone can</code>

<code>access. This is also intended only </code><code>for</code> <code>testing, and should be removed</code>

<code>before moving into a production environment.</code>

<code>Remove </code><code>test</code> <code>database and access to it? [Y</code><code>/n</code><code>] &lt;– 回車</code>

<code>– Dropping </code><code>test</code> <code>database…</code>

<code>– Removing privileges on </code><code>test</code> <code>database…</code>

<code>Reloading the privilege tables will ensure that all changes made so far</code>

<code>will take effect immediately.</code>

<code>Reload privilege tables now? [Y</code><code>/n</code><code>] &lt;– 回車</code>

<code>Cleaning up…</code>

<code>All </code><code>done</code><code>! If you’ve completed all of the above steps, your MariaDB</code>

<code>installation should now be secure.</code>

<code>Thanks </code><code>for</code> <code>using MariaDB!</code>

<code>[root@localhost ~]</code><code>#</code>

開啟服務并永久通過防火牆 CentOS的防火牆改變了 是用firewall

<code>systemctl stop httpd.service</code>

<code>systemctl disable httpd.service</code>

<code>systemctl </code><code>enable</code> <code>nginx.service</code>

<code>systemctl start nginx.service</code>

<code>systemctl </code><code>enable</code> <code>php-fpm.service</code>

<code>systemctl start php-fpm.service</code>

<code>firewall-cmd –permanent –zone=public –add-service=http</code>

<code>firewall-cmd –permanent –zone=public –add-service=https</code>

<code>firewall-cmd –reload</code>

APC是一個自由和開放的PHP操作碼來緩存和優化PHP的中間代碼。它類似于其他PHP操作碼cachers,如eAccelerator和XCache。強烈建議有這些安裝,以加快您的PHP頁面。

從PHP PECL庫中安裝的APC。 PECL要求CentOS開發工具beinstalled編譯APC包。

确認安裝了開發包  如果沒有安裝

<code>yum groupinstall ‘Development Tools’</code>

指令 pecl install apc

<code>[root@localhost ~]</code><code># pecl install apc</code>

<code>downloading APC-3.1.13.tgz …</code>

<code>Starting to download APC-3.1.13.tgz (171,591 bytes)</code>

<code>……………..</code><code>done</code><code>: 171,591 bytes</code>

<code>55 </code><code>source</code> <code>files, building</code>

<code>running: phpize</code>

<code>Configuring </code><code>for</code><code>:</code>

<code>PHP Api Version: 20100412</code>

<code>Zend Module Api No: 20100525</code>

<code>Zend Extension Api No: 220100525</code>

<code>Enable internal debugging </code><code>in</code> <code>APC [no] : &lt;– 回車</code>

<code>Enable per request </code><code>file</code> <code>info about files used from the APC cache [no] : &lt;– 回車</code>

<code>Enable spin locks (EXPERIMENTAL) [no] : &lt;– 回車</code>

<code>Enable memory protection (EXPERIMENTAL) [no] : &lt;– 回車</code>

<code>Enable pthread mutexes (default) [no] : &lt;–回車</code>

<code>Enable pthread </code><code>read</code><code>/write</code> <code>locks (EXPERIMENTAL) [</code><code>yes</code><code>] : &lt;– 回車</code>

<code>building </code><code>in</code> <code>/var/tmp/pear-build-rootVrjsuq/APC-3</code><code>.1.13</code>

然後打開 /etc/php.ini 并設定 cgi.fix_pathinfo=0:

<code>vi</code> <code>/etc/php</code><code>.ini</code>

然後再在PHP.INI添加如下:

<code>[APC]</code>

<code>extension=apc.so</code>

然後編輯/etc/nginx/conf.d/default.conf

把廈門的注釋去掉 并改為如下:

<code>   </code><code>location ~ .php$ {</code>

<code>        </code><code>root           </code><code>/usr/share/nginx/html</code><code>;</code>

<code>        </code><code>try_files $uri =404;</code>

<code>        </code><code>fastcgi_pass   127.0.0.1:9000;</code>

<code>        </code><code>fastcgi_index  index.php;</code>

<code>        </code><code>fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;</code>

<code>        </code><code>include        fastcgi_params;</code>

<code>    </code><code>}</code>

預設情況下監聽端口 9000 。 另外,也可以使PHP-FPM使用Unix套接字,這避免了TCP的開銷。要做到這一點,打開 /etc/php-fpm.d/www.conf

<code>vi</code> <code>/etc/php-fpm</code><code>.d</code><code>/www</code><code>.conf</code>

… 修改後如下:

<code>[...]</code>

<code>;listen = 127.0.0.1:9000</code>

<code>listen = </code><code>/var/run/php-fpm/php5-fpm</code><code>.sock</code>

然後重新加載 PHP-FPM:

<code>systemctl restart php-fpm.service</code>

接下來通過你的nginx的配置和所有的虛拟主機和改線 fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/tmp/php5-fpm.sock;,像這樣:

<code>vi</code> <code>/etc/nginx/conf</code><code>.d</code><code>/default</code><code>.conf</code>

<code>    </code><code>location ~ .php$ {</code>

<code>        </code><code>fastcgi_pass   unix:</code><code>/var/run/php-fpm/php5-fpm</code><code>.sock;</code>

最後重新加載 nginx:

<code>systemctl restart nginx.service</code>

<code></code>

      本文轉自flyingzf  51CTO部落格,原文連結:http://blog.51cto.com/flyingzf/1638244,如需轉載請自行聯系原作者