-
Notifications
You must be signed in to change notification settings - Fork 58
/
run_php_mysql_website_aws
191 lines (106 loc) · 6.12 KB
/
run_php_mysql_website_aws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
INSTALL LAMP STACK ON AWS - UBUNTU 18
Step 1 — Installing Apache and Updating the Firewall
sudo apt update
sudo apt upgrade
sudo apt install apache2
sudo ufw app list
sudo ufw app info "Apache Full"
sudo ufw allow in "Apache Full"
APACHE INSTALLED SUCCESFULLY TILL HERE, YOU CAN CHECK BY ENTERING YOUR PUBLIC IP OR PUBLICK DNS ADDRESS - http://your_server_ip
==================================================
Step 2 — Installing MySQL
sudo apt install mysql-server
sudo mysql_secure_installation
sudo mysql
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; // please note here replace the "password" with yours.
FLUSH PRIVILEGES;
SELECT user,authentication_string,plugin,host FROM mysql.user;
exit
At this point, your database system is now set up and you can move on to installing PHP, the final component of the LAMP stack.
=========================================================
Step 3 — Installing PHP
sudo apt install php libapache2-mod-php php-mysql
In most cases, you will want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell the web server to prefer PHP files over others, so make Apache look for an index.php file first.
sudo nano /etc/apache2/mods-enabled/dir.conf
Move the PHP index file (highlighted above) to the first position after the DirectoryIndex specification, like this:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
-----------------------------------
sudo systemctl restart apache2
sudo systemctl status apache2
Press Q to exit this status output.
Check PHP Version by entering
php -v
Install the commonly required php modules by using the below commands - do remeber replace the php version number with your by checking the php -v command
For Example if the php -v command shows 7.4 version installed then you have to replace the 7.2 with 7.4 in the below command
sudo apt install php7.2-common php7.2-mysql php7.2-xml php7.2-xmlrpc php7.2-curl php7.2-gd php7.2-imagick php7.2-cli php7.2-dev php7.2-imap php7.2-mbstring php7.2-opcache php7.2-soap php7.2-zip php7.2-intl -y
sudo systemctl restart apache2
==================================================
Step 4 — Testing PHP Processing on your Web Server
sudo nano /var/www/html/info.php
This will open a blank file. Add the following text, which is valid PHP code, inside the file:
<?php
phpinfo();
?>
The address you will want to visit is:
http://your_ip/info.php
You will get the php info page
===========================
PHPMYADMIN INSTALL STEPS BELOW
Step 1 — Installing phpMyAdmin
sudo apt update
sudo apt install phpmyadmin php-mbstring php-gettext
Warning: When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE to select Apache, the installer will not move the necessary files during installation. Hit SPACE, TAB, and then ENTER to select Apache.
sudo phpenmod mbstring
sudo systemctl restart apache2
===================================================
http://your_domain_or_IP/phpmyadmin
====================================PERMISSIONS ADJUSTMENT================================
Step 2: Locate the PHP configuration file
Determining the right PHP configuration file can be very confusing especially because the ‘php.ini’ file can be located on a different folder depending on the PHP version.
The correct php.ini file should be in the Apache directory (e.g. ‘/etc/php/7.1/apache2/php.ini’). This will depend on the version of PHP. For instance, in Php7.2, the configuration file is located on ‘/etc/php/7.2/apache2/php.ini’
==============================================================
Step 3: Edit the Php Configuration file
sudo nano /etc/php/7.1/apache2/php.ini
Standard ‘php.ini’ settings file - Change the INI settings according to the below values:
memory_limit = 128M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 120
sudo service apache2 restart
Step 4: Verify the php.ini settings
Refreshing the info.php page should now show your updated settings. Remember to remove the info.php when you are done changing your PHP configuration.
=========================================================================
Important Notes - Common Issues during/after PHP Install
MOST IMPORTANT
PERMISSION - YOU SHOULD OWN THE FILE BEFORE YOU CAN EDIT - YOU SHOULD KNOW THE USERNAME OF THE OPERATING SYSTEM.
=====================
Issues: Website pages not visible, not able to edit the files/folder , permsission denied issue, .htaccess not able to rewrite links.
Execute the Comands below to set proper file permissions on Directories and files.
sudo chown -R ubuntu:root /var/www/html
sudo find html -type d -exec chmod 775 {} \;
sudo find html -type f -exec chmod 664 {} \;
======================================================
Enabling mod_rewrite on apache2
By default, Apache does not allow the use of ‘.htaccess’ file so you will need to edit the configuration of each website’s virtual host file by adding the following code:
OWN THE APACHE2 FOLDER FIRST IF YOU WANT TO EDIT VIA FILEZILLA OR FTP - sudo chown -R ubuntu:root /etc/apache2/ - Revert back to root:root chown when done.
OR VIA SSH TERMINAL
sudo nano /etc/apache2/apache2.conf
Change the setting as below : AllowOverride All
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
------------
sudo a2enmod rewrite
sudo service apache2 restart
=================
TO VERIFY ANY CONFIG ERRORS OR MISTAKE OR SYSNTAX ERRORS IN APACHE CONFIG FILE, RUN THE BELOW COMMAND - Its should show Syntax OK , if it not then there is some error in config due to which apache will not start.
sudo service apache2 status (Press Q to exit)
# apachectl configtest
Syntax OK
# apachectl -t
Syntax OK