I am learning PHP recently and want to build a small website on SAE, so I downloaded a Ubuntu version 14.04 and built a LAMP PHP development environment. I also encountered many problems during the construction process. Now I will record the process in the hope that it will be helpful to newbies.
1. Install mysql.
1. Update the source list
Open the "terminal window", enter "
sudo apt-get update"-->Enter-->"Enter the password of the root user"-->Enter, and that's it. If you install mysql directly without running this command, an error message "There are several software packages that cannot be downloaded. You can run apt-get update------" will appear, making the installation impossible.
2. Install mysql
Open the "Terminal Window", enter
sudo apt-get install mysql-server mysql-client-->Enter-->Enter "y"-->Enter-->Enter mysql in the "Package Settings Dialog Box" Password of the "root" user-->Enter-->Enter the password again-->Enter, the installation is completed. (Be sure to remember the password of the root user set when installing mysql. The root user in the Ubuntu 14.04 system and the root user in mysql are not the same user.)
3. Determine whether mysql is installed successfully
Open the "terminal window" and enter
sudo service mysql restart-->Press Enter-->If mysql starts successfully and is in running state, it means that mysql is installed successfully. Then you can enter "mysql -uroot -p"-->Enter-->Enter the password to log in to mysql.
2. Install Apache
1. Install Appche2 from the command line
Open the "terminal window", enter
sudo apt-get install apache2-->Enter-->Enter "root user's password"-->Enter-->Enter" y"-->Press Enter and the installation is completed.
2. The path to the default website root directory
After Apache is installed, the default website root directory is "/var/www/html". In the terminal window, enter
ls /var/www/html-->Enter-->In the website root There is an "index.html" file in the directory. Enter "127.0.0.1"--> press Enter in the browser to open the page.
3.1 The path of Apache’s first configuration file apache2.conf
Enter "ls /etc/apache2" in the terminal window-->Enter-->There is a configuration file of "apache2.conf".
3.2 The path of Apache’s second configuration file 000-default.conf
Enter
ls /etc/apache2/sites-availablein the terminal window-->Enter-->There is a configuration file "000-default.conf".
4. Modify the root directory of the website
4.1 Enter
sudo gedit /etc/apache2/apache2.confin the terminal window-->Enter-->Find the location of "
4.2 Enter
sudo gedit /etc/apache2/sites-available/000-default.confin the terminal window-->Enter-->Find the location of "DocumentRoot /var/www/html"-->Change "/var/www/html" to the new root directory , here I changed it to "/var/www/".
5. Restart Apache
In the terminal window, enter "sudo /etc/init.d/apache2 restart"-->Enter-->"Enter the root user password"-->Enter-->Restart success.
6. Create index.html
Create a new index.html file under the "/var/www/" folder"-->Save, then open the browser and enter "127.0.0.1"-->You can access it "index.html" file-->Change successful.
3. Install PHP
1. Install php
Open the "terminal window" and enter
sudo apt-get install php5-->Enter-->Enter "y"--> ; Enter --> Installation completed.
2. Let Apache support php
Open the "terminal window", enter
sudo apt-get install libapache2-mod-php5--> Enter --> Installation completed.
3. Install the php5-gd module
Open " Terminal window", enter
sudo apt-get install php5-gd-->Enter-->The installation is complete.
4. Use gedit to create the info.php file under "/var/www"
Open the "terminal window", enter
sudo gedit /var/www/info.php--> ; Enter--> Enter ""-->Save, the file is created successfully
5. Test whether Apache can parse the php web page
In Firefox browser. Enter "127.0.0.1info.php"-->The PHP version information page appears, indicating that the PHP installation and configuration is successful (but mysql cannot be found in the version information, indicating that PHP does not support mysql at this time)
4. Let apache support mysql
Open the "terminal window", enter
sudo apt-get install libapache2-mod-auth-mysql-->Enter-->The installation is successful. After installing this module, apache can support mysql.
5. Let php support mysql
Open the "terminal window" ", enter
sudo apt-get install php5-mysql-->Enter-->The installation is successful. After installing this module, php can support mysql.
6. Install phpmyadmin (the graphical management interface of mysql)
Open the "terminal window" and enter
sudo apt-get install phpmyadmin-->Enter.(中间需要输入一次mysql的密码)
然后在"终端窗口",输入
sudo ln -s /usr/share/phpmyadmin/ /var/www(相当与在www下创建了一个phpmyadmin的快捷方式,如果没有" -s "就是直接在www下创建一个与phpmyadmin相同目录,且不是复制),然后打开浏览器输入"/localhost/phpmyadmin"-->登录就可以了。
附:
可能会用到的一些Linux命令:
1. 给php文件夹授权:
sduo chmod a+w /var/www/html/php -R(表示给当前文件夹授予"a(所有,u用户,g组,o其他)"用户赋予"w(写入,"r"表读取,"x"表执行)的权限")或
sudo chmod 777 /var/www然后就可以写入html或php文件了。777是linux中的最高权限,表示可读,可写,可执行。
2. "su ifconfig"查看当前ip;
3. 启动Apache服务:
service httpd start;4. 停止Apache服务:
service httpd stop;5. 关闭开机自启动:
chkconfig httpd off;
配置svn同步到sae的svn仓库上:
1. 安装svn:
sudo apt-get install subversion2. 将svn中文件同步到sea服务器(先要cd到../svn/appname)
svn ci -m "submit code"# 注意,这里填写的submit code为更新的理由,必填项
3. 查看当前版本号:
svn ls path我的path: https://svn.sinaapp.com/longpeng/ (sae上的)
/home/long/svn/longpeng(本地的)
4. mysql设置主键'id'自增长:
ALTER TABLE `test` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT;
5. 备份/恢复数据库:
mysqldump -uyylg -p12345 yylgDB >/home/long/yylgDB.txt;
mysql -uyylg yylgDB /long/yylgDB.txt;
以上就介绍了在ubantu下配置LAMP,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools
