Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator

  • 2020-05-06 12:00:42
  • OfStack

I wrote out the process of erecting lnmp website. I hope it will be helpful to those who want to erecting lnmp website. If there is a better way, please put it forward.
The reason nginx doesn't work with apache is because nginx is more efficient, especially for low-configuration servers like the one I set up on an old machine with 256M of memory.
1. Install ubuntu server 10.04 or 10.10, en in the installation language, shanghai in the time zone, ssh in the service, and the rest by default.
Tip: after the above installation process is completed, it is recommended to use other computers to log in the server, windows system can use putty, linux system directly in the terminal with the command:

Code:
ssh login @server ip

Since the following process involves a lot of commands and code, you can paste directly from the client (right click on putty under windows to paste the contents of the clipboard to the terminal).
2. Add source:

Code:
 
sudo vi /etc/apt/sources.list 

The source for lucid(10.04) is added as follows:
Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 

Source of maverick(10.10) :

Code:
 
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main 

The last behavior of nginx's ppa source requires the addition of key, which runs on the terminal:

Code:
 
sudo apt-key adv --keyserver keyserver.Ubuntu.com --recv-keys C300EE8C 

3. Update

Code:
 
sudo apt-get update 

4. Install the website system

Code:
 
sudo apt-get install nginx php5-common php5-dev php5-cgi php5-fpm php-apc php5-mysql php5-curl php5-gd php5-idn php-pear php5-mcrypt php5-memcache php5-ming php5-recode php5-tidy php5-xmlrpc php5-xsl mysql-server 

The above is required installation, the following php component is optional installation, the general website program may not be necessary:

Code:
 
sudo apt-get install php5-imagick php5-imap php5-recode php5-snmp php5-sqlite php5-xmlrpc php5-suhosin php5-odbc php5-ladp 

5. Modify the nginx configuration file

Code:
 
sudo vi /etc/nginx/sites-enabled/default 

Put one of them:

Code:
 
location / { 
root /var/www; 
index index.html index.htm; 
} 

To:

Code:
 
location / { 
root /var/www/nginx-default; 
index index.php index.html index.htm; 
} 

Of which:

Code:
#location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# include fastcgi_params;
#}

To:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
0
6. Change the ownership of website directory:

Code:
sudo chown -R ubuntu nginx-default/

Note: ubuntu is the system login username.
7. Install ZendGuardLoader and eaccelerator:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
1
Add
at the end of the configuration file
Code:
 
zend_extension=/usr/zend/ZendGuardLoader.so 
zend_loader.enable=1 
zend_loader.disable_licensing=0 
zend_loader.obfuscation_level_support=3 
zend_loader.license_path= 
zend_extension="/usr/lib/php5/20090626+lfs/eaccelerator.so" 
eaccelerator.shm_size="16" 
eaccelerator.cache_dir="/tmp/eaccelerator" 
eaccelerator.enable="1" 
eaccelerator.optimizer="1" 
eaccelerator.check_mtime="1" 
eaccelerator.debug="0" 
eaccelerator.filter="" 
eaccelerator.shm_max="0" 
eaccelerator.shm_ttl="0" 
eaccelerator.shm_prune_period="0" 
eaccelerator.shm_only="0" 
eaccelerator.compress="1" 
eaccelerator.compress_level="9" 
eaccelerator.allowed_admin_path="/var/www/nginx-default/control.php" 

8. (optional) install phpmyadmin:

Code:
 
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.9/phpMyAdmin-3.3.9-all-languages.tar.bz2 
tar xvjf phpMyAdmin-3.3.9-all-languages.tar.bz2 
mv phpMyAdmin-3.3.9-all-languages /var/www/nginx-default/phpmyadmin 
cd /var/www/nginx-default/phpmyadmin 
cp config.sample.inc.php config.inc.php 
vi config.inc.php 

Among them:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
4
To:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
5
Below:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
6
Delete // all, and then:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
7
Change pma and pmapass to your mysql username and password, and finally log in phpmyadmin and import the creat_tables.sql file in the phpmyadmin/scripts directory into mysql.
9, restart the system, upload files, the website was successfully established! Try it!
filezilla (http:// filezilla-project.org /), free open source ftp software, windows and linux are available, support ssh port 22.

Attachment: system and part of software management operation
1. Operating system:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
8
2. Configuration modification and effectiveness of nginx:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main 
deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main 
9
3. Configuration modification and effectiveness of php:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main 
0
3. Website directory:

Code:
 
/var/www/nginx-default 

4. eaccelerator management:

Code:
 
http:// Your web site /control.php 

5. Fix a major vulnerability in nginx+php, and change the size of the uploaded file (depending on your situation)
Code:
 
sudo vi /etc/php5/fpm/php.ini 
cgi.fix_pathinfo = 0 // Repair the holes  
upload_max_filesize = 2M Instead of 5M // Modify the upload file size  

6. Set firewall

Code:
 
sudo ufw enable 
sudo ufw default deny 
sudo ufw allow 80 
sudo ufw allow 22 

7. When starting php5-fpm,
appears
Code:
 
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/fpm/conf.d/ming.ini on line 1 in Unknown on line 0 
[WARNING] [pool www] pm.start_servers is not set. It's been set to 20. 

The first line of the prompt is the reason that has been used in the configuration file; Comment instead of #. Modify the following file:

Code:
 
vi /etc/php5/fpm/conf.d/ming.ini 

Change # to; Can.
The second reason is that/etc php5 / fpm/pool d/www conf
in the configuration file
Code:
;pm.start_servers = 20

Get rid of the front; Can.
8, Discuz background starts URL static, will prompt 404 Not Found solution:
Open Rewrite in niginx, write the following in the server configuration file nignx.conf, and then restart nginx.


Code:
 
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main 
7
From the following content: http: / / www vpsee. com / 2011/04 / some - nginx - rewrite - examples - for - subdirectories /, not testing.
Discuz! 7.2 install under subdirectory /bbs:

Code:
 
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse 
deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse 
deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main 
8
Discuz! Es369en1.5 is installed under subdirectory /bbs:

Code:
 
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; 
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; 
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; 
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; 
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; 
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; 
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last; 
if (!-e $request_filename) { 
return 404; 
} 

Related articles: